Skip to content

Commit 27b096e

Browse files
bugfix wrong condition in relative_to override and fix tests
1 parent 2f24235 commit 27b096e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ v7.0.4
33

44
* fix #727: correctly handle incomplete archivals from setuptools_scm_git_archival
55
* fix #691: correctly handle specifying root in pyproject.toml
6+
* correct root override check condition (to ensure absolute path matching)
7+
* allow root by the cli to be considered relative to the cli (using abspath)
68

79
v7.0.3
810
=======

src/setuptools_scm/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def _check_absolute_root(root: _t.PathT, relative_to: _t.PathT | None) -> str:
5050
if relative_to:
5151
if (
5252
os.path.isabs(root)
53-
and not os.path.commonpath([root, relative_to]) == relative_to
53+
and os.path.isabs(relative_to)
54+
and not os.path.commonpath([root, relative_to]) == root
5455
):
5556
warnings.warn(
5657
"absolute root path '%s' overrides relative_to '%s'"

testing/test_cli.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ def get_output(args: list[str]) -> str:
2323
return out.getvalue()
2424

2525

26+
warns_cli_root_override = pytest.warns(
27+
UserWarning, match="root .. is overridden by the cli arg ."
28+
)
29+
warns_absolute_root_override = pytest.warns(
30+
UserWarning, match="absolute root path '.*' overrides relative_to '.*'"
31+
)
32+
33+
exits_with_not_found = pytest.raises(SystemExit, match="no version found for")
34+
35+
2636
def test_cli_find_pyproject(
2737
wd: WorkDir, monkeypatch: pytest.MonkeyPatch, debug_mode: DebugMode
2838
) -> None:
@@ -34,20 +44,17 @@ def test_cli_find_pyproject(
3444
out = get_output([])
3545
assert out.startswith("0.1.dev1+")
3646

37-
with pytest.warns(
38-
UserWarning, match="absolute root path '%s' overrides relative_to '%s'"
39-
):
40-
with pytest.raises(SystemExit, match="no version found for"):
41-
get_output(["--root=.."])
47+
with exits_with_not_found:
48+
get_output(["--root=.."])
4249

4350
wd.write(PYPROJECT_TOML, PYPROJECT_ROOT)
44-
with pytest.raises(SystemExit, match="no version found for"):
51+
with exits_with_not_found:
4552
print(get_output(["-c", PYPROJECT_TOML]))
4653

47-
with pytest.raises(SystemExit, match="no version found for"):
54+
with exits_with_not_found, warns_absolute_root_override:
4855

4956
get_output(["-c", PYPROJECT_TOML, "--root=.."])
5057

51-
with pytest.warns(UserWarning, match="root .. is overridden by the cli arg ."):
58+
with warns_cli_root_override:
5259
out = get_output(["-c", PYPROJECT_TOML, "--root=."])
5360
assert out.startswith("0.1.dev1+")

0 commit comments

Comments
 (0)