Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path to the config.yml file #19

Closed
LKirst opened this issue Jun 14, 2023 · 2 comments
Closed

Path to the config.yml file #19

LKirst opened this issue Jun 14, 2023 · 2 comments

Comments

@LKirst
Copy link

LKirst commented Jun 14, 2023

When I install the app with pip install -e . and I call the cli from from any working directory other than the top directory oft the project, I get a file not found error:

$ name_of_the_app -w DEBUG hello

2023-06-14 14:29:37,123;DEBUG;name_of_the_app;starting execution
Traceback (most recent call last):
  File "C:\Users\MYUSER\anaconda3\envs\NAMEOFMYENV\Scripts\edupsy_admin-script.py", line 33, in <module>
    sys.exit(load_entry_point('name-of-the-app', 'console_scripts', 'name_of_the_app')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\PATHTOTHEAPP\name_of_the_app\src\name_of_the_app\cli.py", line 25, in main
    config.load(args.config)
  File "c:\PATHTOTHEAPP\name_of_the_app\src\name_of_the_app\core\config.py", line 99, in load
    with open(path, "r") as stream:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'etc/config.yml'

If I run the same command from the top level directory of the app, the config.yml file loads.

OS: Win10
Python 3.11.3

Is this expected behaviour? Should I replace the relative default path etc/config.yml with an absolute path, for example one generated with the package platformdirs?

@mdklatt
Copy link
Owner

mdklatt commented Jun 15, 2023

@LKirst

When I install the app with pip install -e . and I call the cli from from any working directory other than the top directory oft the project, I get a file not found error:
...
If I run the same command from the top level directory of the app, the config.yml file loads.
...

Is this expected behaviour? Should I replace the relative default path etc/config.yml with an absolute path, for example one generated with the package platformdirs?

Yes, this is the expected behavior. In practice, I use an application's root directory as its working directory, and the template follows this convention. For development, the root directory is the project root (subdirectories are src/, etc/ , tests/, and so one). For an installed application, the root directory is where it was installed. Best practice is to install it into a virtualenv envrionment, which then becomes the root directory (subdirectories are etc/ and bin/).

One advantage of doing things this way is that the runtime behavior is the same for an installed application as it is during development. Note that the tests also assume that the root directory is the working directory. You can replace the config path with an absolute directory if that fits your needs, but then you might have a mismatch between development and production. Also, you can always use --config CLI option to explicitly set the path to wherever you want.

@LKirst
Copy link
Author

LKirst commented Jun 15, 2023

Thank you very much for your explanation and for the template!

@LKirst LKirst closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants