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

Create temp_dir if not exists #2781

Merged
merged 25 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 21 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 docs/changelog/2770.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create temp_dir if not exists - by :user:`q0w`.
2 changes: 1 addition & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Core

.. conf::
:keys: temp_dir
:default: {tox_root}/.temp
:default: {tox_root}/.tmp

Directory where to put tox temporary files. For example: we create a hard link (if possible, otherwise new copy) in
this directory for the project package. This ensures tox works correctly when having parallel runs (as each session
Expand Down
4 changes: 4 additions & 0 deletions src/tox/tox_env/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def _setup_env(self) -> None:
if eq is False and old is not None: # pragma: no branch # recreate if already created and not equals
raise Recreate(f"env type changed from {old} to {conf}")
self._handle_env_tmp_dir()
self._handle_core_tmp_dir()

def _setup_with_env(self) -> None: # noqa: B027 # empty abstract base class
pass
Expand All @@ -303,6 +304,9 @@ def _handle_env_tmp_dir(self) -> None:
ensure_empty_dir(env_tmp_dir)
env_tmp_dir.mkdir(parents=True, exist_ok=True)

def _handle_core_tmp_dir(self) -> None:
self.core["temp_dir"].mkdir(parents=True, exist_ok=True)

def _clean(self, transitive: bool = False) -> None: # noqa: U100
if self._run_state["clean"]: # pragma: no branch
return # pragma: no cover
Expand Down
21 changes: 21 additions & 0 deletions tests/tox_env/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from pathlib import Path

from tox.pytest import ToxProjectCreator


def test_ensure_temp_dir_exists(tox_project: ToxProjectCreator) -> None:
ini = "[testenv]\ncommands=python -c 'print(1)'"
project = tox_project({"tox.ini": ini})
result = project.run()
result.assert_success()
assert result.state.conf.core["temp_dir"].exists()


def test_dont_cleanup_temp_dir(tox_project: ToxProjectCreator, tmp_path: Path) -> None:
ini = "[tox]\ntemp_dir={work_dir}/foo\n[testenv]\ncommands=python -c 'print(1)'"
(tmp_path / "foo" / "bar").mkdir(parents=True)
project = tox_project({"tox.ini": ini})
result = project.run("--workdir", os.fspath(tmp_path))
result.assert_success()
assert (result.state.conf.core["temp_dir"] / "bar").exists()
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fixup
fromdocname
fromhex
fs
fspath
fullmatch
getattribute
getbasetemp
Expand Down