You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Indicate that python scripts need not be wholly placed in __init__.py #7430
dagger's practice of using __init__.py to hold dagger scripts beyond simple imports flies in face of python convention. The documentation and templates should be revised to indicate that dagger does not in fact require or recommend this, and users are free to place their code in another file and import it in __init__.py so long as it is in a package called "main"
changed the title [-]Indicate that python scripts need not be wholly placed in __init__.py[/-][+]Indicate that python scripts need not be wholly placed in `__init__.py`[/+]on May 21, 2024
To be clear, this is documented in Module Structure but perhaps it used to be clearer when the template created src/main.py by default.
Noticing that people were confused about splitting that into multiple files (python module to package), I tried to simplify by defaulting to a package, but removed this part of the documentation because I overestimated how obvious it is:
Multiple files
You can split your Python module (main.py) into multiple files by turning it into a package:
Another alternative I'm considering is that it's planned since the beginning to allow importing "my_module" instead of "main". Then I'm perfectly fine with this structure:
.
└── src
└── my_module # name that dagger needs to know about (to import)
├── __init__.py # for imports
├── main.py # for main object
└── test.py # for Test object
Activity
[-]Indicate that python scripts need not be wholly placed in __init__.py[/-][+]Indicate that python scripts need not be wholly placed in `__init__.py`[/+]helderco commentedon May 21, 2024
To be clear, this is documented in Module Structure but perhaps it used to be clearer when the template created
src/main.pyby default.Noticing that people were confused about splitting that into multiple files (python module to package), I tried to simplify by defaulting to a package, but removed this part of the documentation because I overestimated how obvious it is:
- Docs excerpt removed in https://github.com/dagger/dagger/pull/7053/files#diff-a2b0f2ebe1418510e6e45065533f4ba5fef4d8cd819ae7c9a66e1b4961baa59bL54
The current version of the docs already explain that dagger only needs for
mainto be importable, whether it's a python module or package.I'm not very fond of yet another
main.pyin:So I'm inclined to just leave a code comment in the template recommending people to create their own file names and just import on
__init__.py.helderco commentedon May 21, 2024
Another alternative I'm considering is that it's planned since the beginning to allow importing "my_module" instead of "main". Then I'm perfectly fine with this structure: