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
1 change: 1 addition & 0 deletions docs/changelog/2770.bugfix.rst
@@ -0,0 +1 @@
Create default temp_dir.
2 changes: 1 addition & 1 deletion docs/config.rst
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
7 changes: 6 additions & 1 deletion src/tox/config/sets.py
Expand Up @@ -194,6 +194,11 @@ def work_dir_builder(conf: Config, env_name: str | None) -> Path: # noqa: U100
def work_dir_post_process(value: Path) -> Path:
return self._conf.work_dir if self._conf.options.work_dir else value

def temp_dir_builder(conf: Config, env_name: str | None) -> Path: # noqa: U100
temp_dir = cast(Path, self["work_dir"]) / ".tmp"
temp_dir.mkdir(parents=True, exist_ok=True)
return temp_dir
q0w marked this conversation as resolved.
Show resolved Hide resolved

self.add_config(
keys=["work_dir", "toxworkdir"],
of_type=Path,
Expand All @@ -204,7 +209,7 @@ def work_dir_post_process(value: Path) -> Path:
self.add_config(
keys=["temp_dir"],
of_type=Path,
default=lambda conf, _: cast(Path, self["work_dir"]) / ".tmp", # noqa: U100, U101
default=temp_dir_builder,
desc="a folder for temporary files (is not cleaned at start)",
)
self.add_constant("host_python", "the host python executable path", sys.executable)
Expand Down
8 changes: 8 additions & 0 deletions tests/config/test_sets.py
Expand Up @@ -179,3 +179,11 @@ def test_config_work_dir(tox_project: ToxProjectCreator, work_dir: str) -> None:
result = project.run("c", *(["--workdir", str(project.path / work_dir)] if work_dir else []))
expected = project.path / work_dir if work_dir else Path("b")
assert expected == result.state.conf.core["work_dir"]


def test_config_temp_dir(tox_project: ToxProjectCreator) -> None:
ini = "[testenv]\nallowlist_externals=touch\ncommands=touch {temp_dir}/foo"
q0w marked this conversation as resolved.
Show resolved Hide resolved
project = tox_project({"tox.ini": ini})
result = project.run()
result.assert_success()
assert (result.state.conf.core["temp_dir"] / "foo").exists()