diff --git a/.gitignore b/.gitignore index 013b7bc..d3f856f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ video/auth.* *.mp4 r5-java/tmp +property-data diff --git a/pipeline/local_temp.py b/pipeline/local_temp.py new file mode 100644 index 0000000..d2cfbc4 --- /dev/null +++ b/pipeline/local_temp.py @@ -0,0 +1,25 @@ +"""Repo-local temporary directory helpers for pipeline scripts.""" + +from pathlib import Path +import os +import tempfile + +REPO_ROOT = Path(__file__).resolve().parent.parent +LOCAL_TMP_DIR = REPO_ROOT / ".tmp" +_TEMP_ENV_VARS = ("TMPDIR", "TEMP", "TMP") + + +def local_tmp_dir() -> Path: + """Return the repo-local temp directory, creating it if needed.""" + LOCAL_TMP_DIR.mkdir(parents=True, exist_ok=True) + return LOCAL_TMP_DIR + + +def configure_tempfile_defaults() -> Path: + """Point stdlib and subprocess temp defaults at the repo-local temp dir.""" + temp_dir = local_tmp_dir() + temp_dir_str = str(temp_dir) + for env_var in _TEMP_ENV_VARS: + os.environ[env_var] = temp_dir_str + tempfile.tempdir = temp_dir_str + return temp_dir