Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect TMP, TMPDIR, TEMP #442

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frameworks/autosklearn/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else
git clone --recurse-submodules --shallow-submodules ${DEPTH} ${REPO} ${TARGET_DIR}
cd ${TARGET_DIR}
git checkout "${COMMIT}"
git submodule update --init --recursive
cd ${HERE}
PIP install -U -e ${TARGET_DIR}
fi
Expand Down
9 changes: 8 additions & 1 deletion frameworks/shared/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def run_in_venv(caller_file, script_file: str, *args,
input_data: Union[dict, ns], dataset: Dataset, config: TaskConfig,
options: Union[None, dict, ns] = None,
process_results=None,
python_exec=None):
python_exec=None,
retain_tmp_env: bool = True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, especially for TMP properties, but I'd suggest to make it more generic then in case frameworks want to propagate some other variables:

Suggested change
retain_tmp_env: bool = True):
retained_env_vars: List[str] = ['TMP', 'TEMP', 'TMPDIR']):

here = dir_of(caller_file)
if python_exec is None: # use local virtual env by default
python_exec = venv_python_exec(here)
Expand All @@ -93,6 +94,12 @@ def run_in_venv(caller_file, script_file: str, *args,
ser_config = options['serialization']
env = options['env'] or ns()

# To honour any arguments about tmpdir, we copy over
# the TMP, TEMP and TMPDIR environment variables
if retain_tmp_env:
for env_var in ["TMP", "TEMP", "TMPDIR"]:
env[env_var] = os.environ.get(env_var)
eddiebergman marked this conversation as resolved.
Show resolved Hide resolved

with TemporaryDirectory() as tmpdir:

ds = _make_input_dataset(input_data, dataset, tmpdir, serialization=ser_config)
Expand Down