Skip to content

Commit f51c6e3

Browse files
fix #138 - add support for the pip-egg-info folder
1 parent 8c06ee9 commit f51c6e3

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,10 @@ def scm_config():
7979
.hg = setuptools_scm.hg:parse
8080
.git = setuptools_scm.git:parse
8181
82-
# those are left here for backward compatibility in the 1.x series
83-
.hg_archival.txt = setuptools_scm.hg:parse_archival
84-
PKG-INFO = setuptools_scm.hacks:parse_pkginfo
85-
8682
[setuptools_scm.parse_scm_fallback]
8783
.hg_archival.txt = setuptools_scm.hg:parse_archival
8884
PKG-INFO = setuptools_scm.hacks:parse_pkginfo
85+
pip-egg-info = setuptools_scm.hacks:parse_pip_egg_info
8986
9087
[setuptools_scm.files_command]
9188
.hg = setuptools_scm.hg:FILES_COMMAND

setuptools_scm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def _do_parse(root, parse):
7979
root, 'setuptools_scm.parse_scm_fallback')
8080
else:
8181
# include fallbacks after dropping them from the main entrypoint
82-
version = version_from_scm(root)
82+
version = version_from_scm(root) or _version_from_entrypoint(
83+
root, 'setuptools_scm.parse_scm_fallback')
8384

8485
if version:
8586
return version

setuptools_scm/hacks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ def parse_pkginfo(root):
1111
version = data.get('Version')
1212
if version != 'UNKNOWN':
1313
return meta(version)
14+
15+
16+
def parse_pip_egg_info(root):
17+
pipdir = os.path.join(root, 'pip-egg-info')
18+
if not os.path.isdir(pipdir):
19+
return
20+
items = os.listdir(pipdir)
21+
trace('pip-egg-info', pipdir, items)
22+
if not items:
23+
return
24+
return parse_pkginfo(os.path.join(pipdir, items[0]))

setuptools_scm/integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def version_keyword(dist, keyword, value):
1414
value = {}
1515
if getattr(value, '__call__', None):
1616
value = value()
17-
if os.path.exists('PKG-INFO'):
17+
# this piece of code is a hack to counter the mistake in root finding
18+
ep = find_matching_entrypoint('.', 'setuptools_scm.parse_scm_fallback')
19+
if ep is not None:
1820
value.pop('root', None)
1921
dist.metadata.version = get_version(**value)
2022

setuptools_scm/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def callable_or_entrypoint(group, callable_or_name):
2323
trace('ep', (group, callable_or_name))
2424
if isinstance(callable_or_name, str):
2525
for ep in iter_entry_points(group, callable_or_name):
26+
trace("ep found:", ep.name)
2627
return ep.load()
2728
else:
2829
return callable_or_name

testing/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def version(self):
6161
return version
6262

6363

64+
@pytest.yield_fixture(autouse=True)
65+
def debug_mode():
66+
from setuptools_scm import utils
67+
utils.DEBUG = True
68+
yield
69+
utils.DEBUG = False
70+
71+
6472
@pytest.fixture
6573
def wd(tmpdir):
6674
return Wd(tmpdir.ensure('wd', dir=True))

testing/test_regressions.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import sys
22

3-
import pytest
3+
from setuptools_scm import get_version
44
from setuptools_scm.git import parse
55
from setuptools_scm.utils import do_ex, do
66

7+
import pytest
8+
79

810
def test_pkginfo_noscmroot(tmpdir, monkeypatch):
911
"""if we are indeed a sdist, the root does not apply"""
@@ -29,6 +31,23 @@ def test_pkginfo_noscmroot(tmpdir, monkeypatch):
2931
assert res == '1.0'
3032

3133

34+
def test_pip_egg_info(tmpdir, monkeypatch):
35+
"""if we are indeed a sdist, the root does not apply"""
36+
37+
# we should get the version from pkg-info if git is broken
38+
p = tmpdir.ensure('sub/package', dir=1)
39+
tmpdir.mkdir('.git')
40+
p.join('setup.py').write(
41+
'from setuptools import setup;'
42+
'setup(use_scm_version={"root": ".."})')
43+
44+
with pytest.raises(LookupError):
45+
get_version(root=p.strpath)
46+
47+
p.ensure('pip-egg-info/random.egg-info/PKG-INFO').write('Version: 1.0')
48+
assert get_version(root=p.strpath) == '1.0'
49+
50+
3251
def test_use_scm_version_callable(tmpdir, monkeypatch):
3352
"""use of callable as use_scm_version argument"""
3453
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")

0 commit comments

Comments
 (0)