From 73f77c20a1fbf1b9e476950f0f0688c73fae1a09 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Fri, 12 Jul 2024 13:49:39 +0200 Subject: [PATCH] Put environment variables on second place, fixes #307 --- simpa/utils/path_manager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/simpa/utils/path_manager.py b/simpa/utils/path_manager.py index 2e7ba1ed..74f41f5d 100644 --- a/simpa/utils/path_manager.py +++ b/simpa/utils/path_manager.py @@ -20,9 +20,10 @@ class PathManager: one we provided in the `simpa_examples`) in the following places in this order: 1. The optional path you give the PathManager - 2. Your $HOME$ directory - 3. The current working directory - 4. The SIMPA home directory path + 2. Your set environment variables + 3. Your $HOME$ directory + 4. The current working directory + 5. The SIMPA home directory path """ def __init__(self, environment_path=None): @@ -32,6 +33,7 @@ def __init__(self, environment_path=None): """ self.logger = Logger() self.path_config_file_name = 'path_config.env' + override = False if environment_path is None: environment_path = os.path.join(str(Path.home()), self.path_config_file_name) self.logger.debug(f"Using $HOME$ path to search for config file: {environment_path}") @@ -44,13 +46,14 @@ def __init__(self, environment_path=None): f"for {self.path_config_file_name}") environment_path = os.path.join(environment_path, self.path_config_file_name) self.logger.debug(f"Using supplied path to search for config file: {environment_path}") + override = True if environment_path is None or not os.path.exists(environment_path) or not os.path.isfile(environment_path): error_message = f"Did not find a { self.path_config_file_name} file in any of the standard directories..." self.logger.warning(error_message) self.environment_path = environment_path - load_dotenv(environment_path, override=True) + load_dotenv(environment_path, override=override) def detect_local_path_config(self): """