summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <ronny.pfannschmidt@redhat.com>2020-12-11 23:30:24 +0100
committerRonny Pfannschmidt <ronny.pfannschmidt@redhat.com>2020-12-11 23:30:24 +0100
commit91d7ed7e04564946394dda2e97762d6694fc49d2 (patch)
tree3805de2a7fa703a7719d867b7f1dcd7e7928f58a
parent404094fea56fdef55a1e1d2ffbf343f5e9701b8b (diff)
downloadsetuptools-scm-91d7ed7e04564946394dda2e97762d6694fc49d2.tar.gz
fix #337: if relative_to is given as folder instead of file consider it directly
-rw-r--r--CHANGELOG.rst2
-rw-r--r--src/setuptools_scm/config.py15
-rw-r--r--testing/test_basic_api.py12
3 files changed, 24 insertions, 5 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 12bf230..c022499 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -4,6 +4,8 @@ v5.0.0
Breaking changes:
* fix #339: strict errors on missing scms when parsing a scm dir to avoid false version lookups
+* fix #337: if relative_to is a directory instead of a file,
+ consider it as direct target instead of the containing folder and print a warning
Bugfixes:
diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py
index f0d9243..8b8fb8e 100644
--- a/src/setuptools_scm/config.py
+++ b/src/setuptools_scm/config.py
@@ -27,13 +27,24 @@ def _check_tag_regex(value):
def _check_absolute_root(root, relative_to):
+ trace("l", repr(locals()))
if relative_to:
if os.path.isabs(root) and not root.startswith(relative_to):
warnings.warn(
"absolute root path '%s' overrides relative_to '%s'"
% (root, relative_to)
)
- root = os.path.join(os.path.dirname(relative_to), root)
+ if os.path.isdir(relative_to):
+ warnings.warn(
+ "relative_to is expected to be a file,"
+ " its the directory %r\n"
+ "assuming the parent directory was passed" % (relative_to,)
+ )
+ trace("dir", relative_to)
+ root = os.path.join(relative_to, root)
+ else:
+ trace("file", relative_to)
+ root = os.path.join(os.path.dirname(relative_to), root)
return os.path.abspath(root)
@@ -94,6 +105,7 @@ class Configuration(object):
self._absolute_root = _check_absolute_root(self._root, value)
self._relative_to = value
trace("root", repr(self._absolute_root))
+ trace("relative_to", repr(value))
@property
def root(self):
@@ -104,6 +116,7 @@ class Configuration(object):
self._absolute_root = _check_absolute_root(value, self._relative_to)
self._root = value
trace("root", repr(self._absolute_root))
+ trace("relative_to", repr(self._relative_to))
@property
def tag_regex(self):
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index 5111542..5e35a9e 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -90,10 +90,14 @@ def test_pretended(version, monkeypatch):
assert setuptools_scm.get_version() == version
-def test_root_relative_to(monkeypatch, tmpdir):
- assert_root(monkeypatch, tmpdir.join("alt").strpath)
- __file__ = tmpdir.join("module/file.py").strpath
- setuptools_scm.get_version(root="../alt", relative_to=__file__)
+def test_root_relative_to(monkeypatch, tmp_path):
+ assert_root(monkeypatch, str(tmp_path / "alt"))
+ module = tmp_path / "module/file.py"
+ module.parent.mkdir()
+ module.touch()
+ setuptools_scm.get_version(root="../alt", relative_to=str(module))
+ with pytest.warns(UserWarning, match="relative_to is expected to be a file.*"):
+ setuptools_scm.get_version(root="../alt", relative_to=str(module.parent))
def test_dump_version(tmpdir):