mdklatt / cookiecutter-python-app

Cookiecutter template for a Python application project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Path to the config.yml file

LKirst opened this issue · comments

commented

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?

@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.

commented

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