perfect-postcode/pipeline/local_temp.py
Andras Schmelczer 2e112d7398
All checks were successful
CI / Check (push) Successful in 7m22s
Build and publish Docker image / build-and-push (push) Successful in 15m38s
.
2026-05-18 21:20:31 +01:00

25 lines
752 B
Python

"""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