diff options
author | Bernát Gábor <gaborjbernat@gmail.com> | 2022-12-20 11:02:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 11:02:48 -0800 |
commit | 47052d41ca38ff91c3d547e851d95e85d822dc7b (patch) | |
tree | 38a4d6d82006622891ca27fc2fd24003fdee7515 /src/tox | |
parent | a26b975d95ee5e883321abe0f2d3374bd1071e63 (diff) | |
download | tox-git-47052d41ca38ff91c3d547e851d95e85d822dc7b.tar.gz |
Fix change_dir is not always relative to tox_root (#2761)
Resolves https://github.com/tox-dev/tox/issues/2619
Diffstat (limited to 'src/tox')
-rw-r--r-- | src/tox/tox_env/python/virtual_env/package/cmd_builder.py | 8 | ||||
-rw-r--r-- | src/tox/tox_env/runner.py | 11 | ||||
-rw-r--r-- | src/tox/tox_env/util.py | 26 |
3 files changed, 31 insertions, 14 deletions
diff --git a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py index 9140a936..2d6097a4 100644 --- a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py +++ b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py @@ -26,6 +26,7 @@ from tox.tox_env.python.pip.req_file import PythonDeps from tox.tox_env.python.virtual_env.api import VirtualEnv from tox.tox_env.register import ToxEnvRegister from tox.tox_env.runner import RunToxEnv +from tox.tox_env.util import add_change_dir_conf from .pyproject import Pep517VirtualEnvPackager from .util import dependencies_with_extras @@ -61,12 +62,7 @@ class VirtualEnvCmdBuilder(PythonPackageToxEnv, VirtualEnv): default=[], desc="the commands to be called for testing", ) - self.conf.add_config( - keys=["change_dir", "changedir"], - of_type=Path, - default=lambda conf, name: cast(Path, conf.core["tox_root"]), # noqa: U100 - desc="change to this working directory when executing the test command", - ) + add_change_dir_conf(self.conf, self.core) self.conf.add_config( keys=["ignore_errors"], of_type=bool, diff --git a/src/tox/tox_env/runner.py b/src/tox/tox_env/runner.py index c9c3c6ad..fb9a95e0 100644 --- a/src/tox/tox_env/runner.py +++ b/src/tox/tox_env/runner.py @@ -5,14 +5,14 @@ import os import re from abc import ABC, abstractmethod from hashlib import sha256 -from pathlib import Path -from typing import Any, Iterable, List, cast +from typing import Any, Iterable, List from tox.config.types import Command, EnvList from tox.journal import EnvJournal from .api import ToxEnv, ToxEnvCreateArgs from .package import Package, PackageToxEnv, PathPackage +from .util import add_change_dir_conf class RunToxEnv(ToxEnv, ABC): @@ -58,12 +58,7 @@ class RunToxEnv(ToxEnv, ABC): default=[], desc="the commands to be called after testing", ) - self.conf.add_config( - keys=["change_dir", "changedir"], - of_type=Path, - default=lambda conf, name: cast(Path, conf.core["tox_root"]), # noqa: U100 - desc="change to this working directory when executing the test command", - ) + add_change_dir_conf(self.conf, self.core) self.conf.add_config( keys=["args_are_paths"], of_type=bool, diff --git a/src/tox/tox_env/util.py b/src/tox/tox_env/util.py new file mode 100644 index 00000000..aa13f12b --- /dev/null +++ b/src/tox/tox_env/util.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from pathlib import Path +from typing import cast + +from tox.config.sets import CoreConfigSet, EnvConfigSet + + +def add_change_dir_conf(config: EnvConfigSet, core: CoreConfigSet) -> None: + def _post_process_change_dir(value: Path) -> Path: + if not value.is_absolute(): + value = (core["tox_root"] / value).resolve() + return value + + config.add_config( + keys=["change_dir", "changedir"], + of_type=Path, + default=lambda conf, name: cast(Path, conf.core["tox_root"]), # noqa: U100 + desc="change to this working directory when executing the test command", + post_process=_post_process_change_dir, + ) + + +__all__ = [ + "add_change_dir_conf", +] |