Reading a Specific File within (or Below) the CWD
Hi Steve,
You requested I open an issue for your (or the developers') review. In the section
https://pypi.org/project/environs/#reading-env-files
it appears that I'm looking for something other than the standard functionality. In most of the (non-Django, for example) enterprise applications with which I work, there is commonly a sub-directory like conf or some other name where we store configuration files. I'd like to store the env file there, rather in the CWD, or further up the file system. Is there a way to do this with the current functionality? I'm trying to use recurse=False, but when I use something like the following:
env.read_env("./conf/.env.test", recurse=False)
or any variation using the os standard library, for example, I am not having any success. It seems like there is no way to provide an exact location below the CWD. I'd like to define something like a
BASE_DIR=
which would be the CWD, and then
CONFIR_DIR=<BASE_DIR/conf>
then use something like the following
env.read_env("CONFIG_DIR/.env.test", recurse=False)
or an exact path in the read_env() method.
Thanks.
You should be able to pass an arbitrary path to read_env. A common pattern is to use pathlib to resolve directories relative to the env.read_env call site.
from pathlib import Path
from environs import env
HERE = Path(__file__).parent
env.read_env(HERE / "conf" / "env.test", recurse=False)
The path will resolve to an absolute path, which is probably what you want