From bfb27383e429819ac2d31afe53c4379e53e29151 Mon Sep 17 00:00:00 2001 From: Julius Unverfehrt Date: Wed, 31 Jan 2024 10:24:29 +0100 Subject: [PATCH] fix(settings): change precedence to ENV ROOT_PATH > root_path arg --- pyinfra/config/loader.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pyinfra/config/loader.py b/pyinfra/config/loader.py index c7335d6..6c07641 100644 --- a/pyinfra/config/loader.py +++ b/pyinfra/config/loader.py @@ -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}.")