fix(settings): change precedence to ENV ROOT_PATH > root_path arg

This commit is contained in:
Julius Unverfehrt 2024-01-31 10:24:29 +01:00
parent af914ab3ae
commit bfb27383e4

View File

@ -21,6 +21,7 @@ def load_settings(
"""Load settings from .toml files, .env and environment variables. Also ensures a ROOT_PATH environment variable is
set. If ROOT_PATH is not set and no root_path argument is passed, the current working directory is used as root.
Settings paths can be a single .toml file, a folder containing .toml files or a list of .toml files and folders.
If a ROOT_PATH environment variable is set, it is not overwritten by the root_path argument.
If a folder is passed, all .toml files in the folder are loaded. If settings path is None, only .env and
environment variables are loaded. If settings_path are relative paths, they are joined with the root_path argument.
"""
@ -82,15 +83,7 @@ def _normalize_and_verify(settings_path: Path, root_path: Path):
def get_or_set_root_path(root_path: Union[str, Path] = None):
env_root_path = os.environ.get("ROOT_PATH")
if env_root_path and root_path:
if Path(env_root_path) != Path(root_path):
logger.warning(
f"'ROOT_PATH' environment variable is set to {env_root_path}, but a different root_path argument was passed. "
f"Setting new value {root_path}."
)
os.environ["ROOT_PATH"] = str(root_path)
elif env_root_path:
if env_root_path:
root_path = env_root_path
logger.debug(f"'ROOT_PATH' environment variable is set to {root_path}.")