Skip to content

Commit 932bb3e

Browse files
authored
Ensure paths constructed by tox stay meaningful (#2587)
Resolves #2562
1 parent f4b43b5 commit 932bb3e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/changelog/2562.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure paths constructed by tox are stable by resolving relative paths to fully qualified one, this insures that running
2+
tox from a different folder than project root still generates meaningful paths - by :user:`gaborbernat`.

src/tox/config/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def __init__(
2929
pos_args: Sequence[str] | None,
3030
work_dir: Path,
3131
) -> None:
32-
3332
self._pos_args = None if pos_args is None else tuple(pos_args)
3433
self._work_dir = work_dir
3534
self._root = root
@@ -93,6 +92,9 @@ def make(cls, parsed: Parsed, pos_args: Sequence[str] | None, source: Source) ->
9392
# work dir is where we put our own files
9493
root: Path = source.path.parent if parsed.root_dir is None else parsed.root_dir
9594
work_dir: Path = source.path.parent if parsed.work_dir is None else parsed.work_dir
95+
# if these are relative we need to expand them them to ensure paths built on this can resolve independent on cwd
96+
root = root.resolve()
97+
work_dir = work_dir.resolve()
9698
return cls(
9799
config_source=source,
98100
options=parsed,

tests/config/test_main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
from pathlib import Path
45

56
from tests.conftest import ToxIniCreator
67
from tox.config.loader.api import Override
@@ -83,3 +84,19 @@ def test_args_are_paths_when_with_change_dir(tox_project: ToxProjectCreator) ->
8384
result = project.run("c", "-e", "py", "-k", "commands", "--", *args)
8485
result.assert_success()
8586
assert result.out == f"[testenv:py]\ncommands = magic.py {project.path} ..{os.sep}tox.ini a.txt . ..\n"
87+
88+
89+
def test_relative_config_paths_resolve(tox_project: ToxProjectCreator) -> None:
90+
project = tox_project({"tox.ini": "[tox]"})
91+
result = project.run(
92+
"c",
93+
"-c",
94+
str(Path(project.path.name) / "tox.ini"),
95+
"-k",
96+
"change_dir",
97+
"env_dir",
98+
from_cwd=project.path.parent,
99+
)
100+
result.assert_success()
101+
expected = f"[testenv:py]\nchange_dir = {project.path}\nenv_dir = {project.path / '.tox' / 'py'}\n\n[tox]\n"
102+
assert result.out == expected

0 commit comments

Comments
 (0)