diff options
-rw-r--r-- | CHANGELOG.rst | 2 | ||||
-rw-r--r-- | src/setuptools_scm/config.py | 3 | ||||
-rw-r--r-- | testing/test_cli.py | 23 |
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+") |