Skip to content

Commit

Permalink
Configurable data export paths
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 10, 2024
1 parent 46882c0 commit c83332d
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions pathways/filesystem_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,48 @@
from pathlib import Path

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 Pathways
DATA_DIR = Path(__file__).resolve().parent / "data"
if "DATA_DIR" in VARIABLES:
DATA_DIR = Path(VARIABLES["DATA_DIR"])
else:
DATA_DIR = Path(__file__).resolve().parent / "data"
DATA_DIR.mkdir(parents=True, exist_ok=True)

# Directories for user-created data
USER_DATA_BASE_DIR = platformdirs.user_data_path(appname="pathways", appauthor="pylca")
if "USER_DATA_BASE_DIR" in VARIABLES:
USER_DATA_BASE_DIR = Path(VARIABLES.get("USER_DATA_BASE_DIR"))
else:
USER_DATA_BASE_DIR = platformdirs.user_data_path(appname="pathways", appauthor="pylca")
USER_DATA_BASE_DIR.mkdir(parents=True, exist_ok=True)

DIR_CACHED_DB = USER_DATA_BASE_DIR / "cache"
if "DIR_CACHED_DB" in VARIABLES:
DIR_CACHED_DB = Path(VARIABLES.get("DIR_CACHED_DB"))
else:
DIR_CACHED_DB = USER_DATA_BASE_DIR / "cache"
DIR_CACHED_DB.mkdir(parents=True, exist_ok=True)

USER_LOGS_DIR = platformdirs.user_log_path(appname="pathways", appauthor="pylca")
if "USER_LOGS_DIR" in VARIABLES:
USER_LOGS_DIR = Path(VARIABLES["USER_LOGS_DIR"])
else:
USER_LOGS_DIR = platformdirs.user_log_path(appname="pathways", appauthor="pylca")
USER_LOGS_DIR.mkdir(parents=True, exist_ok=True)

# STATS_DIR = USER_DATA_BASE_DIR / "stats"
STATS_DIR = Path.cwd() / "stats"
STATS_DIR.mkdir(parents=True, exist_ok=True)
if "STATS_DIR" in VARIABLES:
STATS_DIR = Path(VARIABLES["STATS_DIR"])
else:
STATS_DIR = Path.cwd() / "stats"
STATS_DIR.mkdir(parents=True, exist_ok=True)

0 comments on commit c83332d

Please sign in to comment.