Closed RasmusN closed 1 year ago
The problem with that is that main.py
doesn't know about the python files in the project root folder. It will have to be something like
if not FROZEN:
# for development, get the root metadata directly from local repo
sys.path.insert(0, str(MODULE_DIR.parent.parent))
from repo_settings import REPO_DIR
TRUSTED_ROOT_SRC = REPO_DIR / 'metadata' / 'root.json'
It is of course possible add the project root folder to your python path but I'm thinking it would be nice if it was working right out of the box without any customizations.
@RasmusN True, but, I believe that's not an issue if you run main.py
from the project root, using the module (-m
) switch:
python -m src.main
From the docs:
[...] As with the
-c
option, the current directory will be added to the start ofsys.path
.
Hmm... then I get this
$ python -m src.main
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Projects\tufup-example\src\main.py", line 4, in <module>
from myapp import main, settings
ModuleNotFoundError: No module named 'myapp'
@RasmusN Sorry about that: you are absolutely right. Using -m
would require imports from src.myapp
or relative imports, which, in turn, would break down when running frozen.
On second thought, I guess your sys.path
solution would do fine, as proposed above.
Another thing: In order to be able to run repo_init.py
I need to add these two lines:
import sys
sys.path.insert(0, 'src/')
I can add them to the PR if you want
It's not possible to run the example app in development mode (not frozen):
The
TRUSTED_ROOT_SRC
did not point to the path specified by repo_settings.py