Skip to content

Commit ea4a6e5

Browse files
committed
Use a different root for fallbacks. Remove old hack that merely checked entrypoint existence (and not if results are valid). Ref #333.
1 parent d1ac9d1 commit ea4a6e5

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

src/setuptools_scm/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,27 @@ def version_from_scm(root):
3434
return _version_from_entrypoint(config, "setuptools_scm.parse_scm")
3535

3636

37-
def _call_entrypoint_fn(config, fn):
37+
def _call_entrypoint_fn(root, config, fn):
3838
if function_has_arg(fn, "config"):
39-
return fn(config.absolute_root, config=config)
39+
return fn(root, config=config)
4040
else:
4141
warnings.warn(
4242
"parse functions are required to provide a named argument"
4343
" 'config' in the future.",
4444
category=PendingDeprecationWarning,
4545
stacklevel=2,
4646
)
47-
return fn(config.absolute_root)
47+
return fn(root)
4848

4949

50-
def _version_from_entrypoint(config, entrypoint):
51-
for ep in iter_matching_entrypoints(config.absolute_root, entrypoint):
52-
version = _call_entrypoint_fn(config, ep.load())
50+
def _version_from_entrypoint(config, entrypoint, fallback=False):
51+
if fallback:
52+
entrypoint += "_fallback"
53+
root = config.fallback_root
54+
else:
55+
root = config.absolute_root
56+
for ep in iter_matching_entrypoints(root, entrypoint):
57+
version = _call_entrypoint_fn(root, config, ep.load())
5358

5459
if version:
5560
return version
@@ -81,20 +86,20 @@ def _do_parse(config):
8186
return meta(tag=pretended, preformatted=True, config=config)
8287

8388
if config.parse:
84-
parse_result = _call_entrypoint_fn(config, config.parse)
89+
parse_result = _call_entrypoint_fn(config.absolute_root, config, config.parse)
8590
if isinstance(parse_result, string_types):
8691
raise TypeError(
8792
"version parse result was a string\nplease return a parsed version"
8893
)
8994
version = parse_result or _version_from_entrypoint(
90-
config, "setuptools_scm.parse_scm_fallback"
95+
config, "setuptools_scm.parse_scm", fallback=True
9196
)
9297
else:
9398
# include fallbacks after dropping them from the main entrypoint
9499
version = _version_from_entrypoint(
95100
config, "setuptools_scm.parse_scm"
96101
) or _version_from_entrypoint(
97-
config, "setuptools_scm.parse_scm_fallback"
102+
config, "setuptools_scm.parse_scm", fallback=True
98103
)
99104

100105
if version:

src/setuptools_scm/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ 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)
6465
self.parse = None
6566
self.tag_regex = DEFAULT_TAG_REGEX
6667
self.git_describe_command = None

src/setuptools_scm/integration.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from .version import _warn_if_setuptools_outdated
44
from .utils import do
5-
from .discover import iter_matching_entrypoints
65
from . import get_version
76

87

@@ -14,12 +13,7 @@ def version_keyword(dist, keyword, value):
1413
value = {}
1514
if getattr(value, "__call__", None):
1615
value = value()
17-
# this piece of code is a hack to counter the mistake in root finding
18-
matching_fallbacks = iter_matching_entrypoints(
19-
".", "setuptools_scm.parse_scm_fallback"
20-
)
21-
if any(matching_fallbacks):
22-
value.pop("root", None)
16+
2317
dist.metadata.version = get_version(**value)
2418

2519

testing/test_git.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from setuptools_scm import integration
24
from setuptools_scm.utils import do
35
from setuptools_scm import git
@@ -29,6 +31,19 @@ def test_parse_describe_output(given, tag, number, node, dirty):
2931
assert parsed == (tag, number, node, dirty)
3032

3133

34+
def test_root_relative_to(tmpdir, wd, monkeypatch):
35+
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
36+
p = wd.cwd.ensure("sub/package", dir=1)
37+
p.join("setup.py").write(
38+
"""from setuptools import setup
39+
setup(use_scm_version={"root": "../..",
40+
"relative_to": __file__})
41+
"""
42+
)
43+
res = do((sys.executable, "setup.py", "--version"), p)
44+
assert res == "0.1.dev0"
45+
46+
3247
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/298")
3348
def test_file_finder_no_history(wd, caplog):
3449
file_list = git_find_files(str(wd.cwd))

testing/test_regressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_pkginfo_noscmroot(tmpdir, monkeypatch):
2929

3030
do("git init", p.dirpath())
3131
res = do((sys.executable, "setup.py", "--version"), p)
32-
assert res == "1.0"
32+
assert res == "0.1.dev0"
3333

3434

3535
def test_pip_egg_info(tmpdir, monkeypatch):

0 commit comments

Comments
 (0)