From 82a40d9727d42376ee1d1bdf95a11b91345de0ea Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 29 Aug 2024 09:27:34 +0200 Subject: [PATCH 1/2] Configurable data directory. --- premise/filesystem_constants.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/premise/filesystem_constants.py b/premise/filesystem_constants.py index ea865457..48f02108 100644 --- a/premise/filesystem_constants.py +++ b/premise/filesystem_constants.py @@ -6,14 +6,33 @@ import platformdirs +import yaml + + +def load_var_file(): + """Check if the variable file exists and load it.""" + var_file = Path.cwd() / "variables.yaml" + if var_file.exists(): + with open(var_file, "r") as f: + return yaml.safe_load(f) + else: + return None + +VARIABLES = load_var_file() or {} + # Directories for data which comes with Premise DATA_DIR = Path(__file__).resolve().parent / "data" INVENTORY_DIR = DATA_DIR / "additional_inventories" VARIABLES_DIR = Path(__file__).resolve().parent / "iam_variables_mapping" IAM_OUTPUT_DIR = DATA_DIR / "iam_output_files" -# Directories for user-created data -USER_DATA_BASE_DIR = platformdirs.user_data_path(appname="premise", appauthor="pylca") +if "USER_DATA_BASE_DIR" in VARIABLES: + USER_DATA_BASE_DIR = Path(VARIABLES.get("USER_DATA_BASE_DIR")) + print(f"USER_DATA_BASE_DIR: {USER_DATA_BASE_DIR}") +else: + USER_DATA_BASE_DIR = platformdirs.user_data_path( + appname="premise", appauthor="pylca" + ) USER_DATA_BASE_DIR.mkdir(parents=True, exist_ok=True) DIR_CACHED_DB = USER_DATA_BASE_DIR / "cache" From 1eb34ee4e75b24256fdd40e70e36409a217ee7a5 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 29 Aug 2024 07:28:08 +0000 Subject: [PATCH 2/2] Black reformating --- premise/filesystem_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/premise/filesystem_constants.py b/premise/filesystem_constants.py index 48f02108..7f6c95e7 100644 --- a/premise/filesystem_constants.py +++ b/premise/filesystem_constants.py @@ -5,7 +5,6 @@ from pathlib import Path import platformdirs - import yaml @@ -18,6 +17,7 @@ def load_var_file(): else: return None + VARIABLES = load_var_file() or {} # Directories for data which comes with Premise