Skip to content

Commit 686a26d

Browse files
committed
Don't pass entrypoing name around anymore and allow passing fallback_root to get_version.
1 parent ea4a6e5 commit 686a26d

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

src/setuptools_scm/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def version_from_scm(root):
3131
config = Configuration()
3232
config.root = root
3333
# TODO: Is it API?
34-
return _version_from_entrypoint(config, "setuptools_scm.parse_scm")
34+
return _version_from_entrypoints(config)
3535

3636

3737
def _call_entrypoint_fn(root, config, fn):
@@ -47,11 +47,12 @@ def _call_entrypoint_fn(root, config, fn):
4747
return fn(root)
4848

4949

50-
def _version_from_entrypoint(config, entrypoint, fallback=False):
50+
def _version_from_entrypoints(config, fallback=False):
5151
if fallback:
52-
entrypoint += "_fallback"
52+
entrypoint = "setuptools_scm.parse_scm_fallback"
5353
root = config.fallback_root
5454
else:
55+
entrypoint = "setuptools_scm.parse_scm"
5556
root = config.absolute_root
5657
for ep in iter_matching_entrypoints(root, entrypoint):
5758
version = _call_entrypoint_fn(root, config, ep.load())
@@ -91,16 +92,10 @@ def _do_parse(config):
9192
raise TypeError(
9293
"version parse result was a string\nplease return a parsed version"
9394
)
94-
version = parse_result or _version_from_entrypoint(
95-
config, "setuptools_scm.parse_scm", fallback=True
96-
)
95+
version = parse_result or _version_from_entrypoints(config, fallback=True)
9796
else:
9897
# include fallbacks after dropping them from the main entrypoint
99-
version = _version_from_entrypoint(
100-
config, "setuptools_scm.parse_scm"
101-
) or _version_from_entrypoint(
102-
config, "setuptools_scm.parse_scm", fallback=True
103-
)
98+
version = _version_from_entrypoints(config) or _version_from_entrypoints(config, fallback=True)
10499

105100
if version:
106101
return version
@@ -126,6 +121,7 @@ def get_version(
126121
relative_to=None,
127122
tag_regex=None,
128123
fallback_version=None,
124+
fallback_root=".",
129125
parse=None,
130126
git_describe_command=None,
131127
):
@@ -138,6 +134,7 @@ def get_version(
138134

139135
config = Configuration()
140136
config.root = root
137+
config.fallback_root = fallback_root
141138
config.version_scheme = version_scheme
142139
config.local_scheme = local_scheme
143140
config.write_to = write_to

src/setuptools_scm/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ def __init__(self, relative_to=None, root="."):
6161
self.write_to = ""
6262
self.write_to_template = None
6363
self.fallback_version = None
64-
self.fallback_root = _check_absolute_root(".", None)
64+
self.fallback_root = "."
6565
self.parse = None
6666
self.tag_regex = DEFAULT_TAG_REGEX
6767
self.git_describe_command = None
6868

69+
@property
70+
def fallback_root(self):
71+
return self._fallback_root
72+
73+
@fallback_root.setter
74+
def fallback_root(self, value):
75+
self._fallback_root = os.path.abspath(value)
76+
6977
@property
7078
def absolute_root(self):
7179
return self._absolute_root

testing/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_version(self, **kw):
6363
__tracebackhide__ = True
6464
from setuptools_scm import get_version
6565

66-
version = get_version(root=str(self.cwd), **kw)
66+
version = get_version(root=str(self.cwd), fallback_root=str(self.cwd), **kw)
6767
print(version)
6868
return version
6969

testing/test_basic_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def test_data_from_mime(tmpdir):
2323
assert res == {"name": "test", "revision": "1"}
2424

2525

26-
def test_version_from_pkginfo(wd):
26+
def test_version_from_pkginfo(wd, monkeypatch):
2727
wd.write("PKG-INFO", "Version: 0.1")
28+
2829
assert wd.version == "0.1"
2930

3031
# replicate issue 167

testing/test_regressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def test_pip_egg_info(tmpdir, monkeypatch):
4343
)
4444

4545
with pytest.raises(LookupError):
46-
get_version(root=p.strpath)
46+
get_version(root=p.strpath, fallback_root=p.strpath)
4747

4848
p.ensure("pip-egg-info/random.egg-info/PKG-INFO").write("Version: 1.0")
49-
assert get_version(root=p.strpath) == "1.0"
49+
assert get_version(root=p.strpath, fallback_root=p.strpath) == "1.0"
5050

5151

5252
@pytest.mark.issue(164)

0 commit comments

Comments
 (0)