Skip to content

Commit

Permalink
Configurable data directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Aug 29, 2024
1 parent 8ef28f0 commit 82a40d9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions premise/filesystem_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 82a40d9

Please sign in to comment.