Packages enable you to organise your Forms and Modules into a hierarchical structure. You may have apps that were created before the existence of Packages. You can convert them to use Packages by clicking the down-arrow next to one of your Forms and selecting ‘Enable packages…’.
The ‘Forms’, ‘Modules’ and ‘Server Modules’ sections of the App Browser will now be replaced by ‘Client code’ and ‘Server code’.
After you have converted your app, you will probably want to change each Form to be stored in the new way.
Forms as Python packages
The way that Forms are represented has changed with the introduction of Packages. Since Packages were introduced, Forms
are stored as Python packages; directories containing an
__init__.py file (plus a config file defining the design layout).
Form1 ├── __init__.py └── form_template.yaml
This is not the case for the app you have just converted: apps created before Packages were introduced stored Forms as
Python modules: files ending in
.py (plus a config file defining the design layout).
Your Forms will continue to be stored this way until you explicitly convert each one. This means your app will continue to work as before, without you needing to change the import statements in your code.
Converting a Form
To convert a Form to be stored in the new way (as a Python package), click on ‘advanced’ in the dropdown menu for that Form and then click ‘Package Form’:
The Form will now have a chevron
> next to it and you can drag-and-drop things inside it, as well as creating Forms,
Modules and Packages inside it. See Structuring Your App for more information.
If the Form you have converted imports other Forms and Modules from your app, you need to add an extra dot into the
import statment. For example, in the app shown above,
Form1 originally imported
Form2 like this:
from .Form2 import Form2
it must now import
Form2 like this:
from ..Form2 import Form2
Imports can be confusing in Python, especially when you have a mixture of modules and packages. If in doubt, use the autocompleter to help you get it right!
Just type “
from .”, then see the suggestions.
See How to import things for more information.