.
This commit is contained in:
parent
6cc7288126
commit
2e112d7398
2 changed files with 26 additions and 0 deletions
25
pipeline/local_temp.py
Normal file
25
pipeline/local_temp.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue