summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2022-06-28 10:35:17 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2022-06-28 10:35:17 +0200
commit27b096e168a1e1daef8c1c6440c5d9d2d4848c07 (patch)
tree829a47e637a6035bcb718a36b0f748abe99f18f6
parent2f24235680cb1e3a999f6185812e376bd6823849 (diff)
downloadsetuptools-scm-27b096e168a1e1daef8c1c6440c5d9d2d4848c07.tar.gz
bugfix wrong condition in relative_to override and fix tests
-rw-r--r--CHANGELOG.rst2
-rw-r--r--src/setuptools_scm/config.py3
-rw-r--r--testing/test_cli.py23
3 files changed, 19 insertions, 9 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index f140523..8babcb5 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -3,6 +3,8 @@ v7.0.4
* fix #727: correctly handle incomplete archivals from setuptools_scm_git_archival
* fix #691: correctly handle specifying root in pyproject.toml
+* correct root override check condition (to ensure absolute path matching)
+* allow root by the cli to be considered relative to the cli (using abspath)
v7.0.3
=======
diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py
index f34d212..3bf250a 100644
--- a/src/setuptools_scm/config.py
+++ b/src/setuptools_scm/config.py
@@ -50,7 +50,8 @@ def _check_absolute_root(root: _t.PathT, relative_to: _t.PathT | None) -> str:
if relative_to:
if (
os.path.isabs(root)
- and not os.path.commonpath([root, relative_to]) == relative_to
+ and os.path.isabs(relative_to)
+ and not os.path.commonpath([root, relative_to]) == root
):
warnings.warn(
"absolute root path '%s' overrides relative_to '%s'"
diff --git a/testing/test_cli.py b/testing/test_cli.py
index 2cfdfb6..1eb9ead 100644
--- a/testing/test_cli.py
+++ b/testing/test_cli.py
@@ -23,6 +23,16 @@ def get_output(args: list[str]) -> str:
return out.getvalue()
+warns_cli_root_override = pytest.warns(
+ UserWarning, match="root .. is overridden by the cli arg ."
+)
+warns_absolute_root_override = pytest.warns(
+ UserWarning, match="absolute root path '.*' overrides relative_to '.*'"
+)
+
+exits_with_not_found = pytest.raises(SystemExit, match="no version found for")
+
+
def test_cli_find_pyproject(
wd: WorkDir, monkeypatch: pytest.MonkeyPatch, debug_mode: DebugMode
) -> None:
@@ -34,20 +44,17 @@ def test_cli_find_pyproject(
out = get_output([])
assert out.startswith("0.1.dev1+")
- with pytest.warns(
- UserWarning, match="absolute root path '%s' overrides relative_to '%s'"
- ):
- with pytest.raises(SystemExit, match="no version found for"):
- get_output(["--root=.."])
+ with exits_with_not_found:
+ get_output(["--root=.."])
wd.write(PYPROJECT_TOML, PYPROJECT_ROOT)
- with pytest.raises(SystemExit, match="no version found for"):
+ with exits_with_not_found:
print(get_output(["-c", PYPROJECT_TOML]))
- with pytest.raises(SystemExit, match="no version found for"):
+ with exits_with_not_found, warns_absolute_root_override:
get_output(["-c", PYPROJECT_TOML, "--root=.."])
- with pytest.warns(UserWarning, match="root .. is overridden by the cli arg ."):
+ with warns_cli_root_override:
out = get_output(["-c", PYPROJECT_TOML, "--root=."])
assert out.startswith("0.1.dev1+")