From 8d9c073f60a369358ec276872e8de8ba7335fc10 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:13:40 +0200 Subject: [PATCH 1/6] try to fix #167 by introducing a preformated flag --- setuptools_scm/hacks.py | 2 +- setuptools_scm/version.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/setuptools_scm/hacks.py b/setuptools_scm/hacks.py index 2d298bec..add89a8b 100644 --- a/setuptools_scm/hacks.py +++ b/setuptools_scm/hacks.py @@ -10,7 +10,7 @@ def parse_pkginfo(root): data = data_from_mime(pkginfo) version = data.get('Version') if version != 'UNKNOWN': - return meta(version) + return meta(version, preformatted=True) def parse_pip_egg_info(root): diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py index 15c4495c..83d41cc3 100644 --- a/setuptools_scm/version.py +++ b/setuptools_scm/version.py @@ -55,6 +55,7 @@ def tags_to_versions(tags): class ScmVersion(object): def __init__(self, tag_version, distance=None, node=None, dirty=False, + preformated=False, **kw): self.tag = tag_version if dirty and distance is None: @@ -84,11 +85,17 @@ def format_choice(self, clean_format, dirty_format): return self.format_with(dirty_format if self.dirty else clean_format) -def meta(tag, distance=None, dirty=False, node=None, **kw): +def _parse_tag(tag, preformated): + if preformated: + return tag if SetuptoolsVersion is None or not isinstance(tag, SetuptoolsVersion): tag = tag_to_version(tag) - trace('version', tag) + return tag + +def meta(tag, distance=None, dirty=False, node=None, preformated=False, **kw): + tag = _parse_tag(tag, preformated) + trace('version', tag) assert tag is not None, 'cant parse version %s' % tag return ScmVersion(tag, distance, node, dirty, **kw) @@ -147,6 +154,8 @@ def postrelease_version(version): def format_version(version, **config): trace('scm version', version) trace('config', config) + if version.preformated: + return version.tag version_scheme = callable_or_entrypoint( 'setuptools_scm.version_scheme', config['version_scheme']) local_scheme = callable_or_entrypoint( From 26b49422cc8c04cf5bbc480fe26278574b77e1db Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:18:24 +0200 Subject: [PATCH 2/6] add forgotten attribute that i missed thanks to local state --- setuptools_scm/version.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py index 83d41cc3..5da805ac 100644 --- a/setuptools_scm/version.py +++ b/setuptools_scm/version.py @@ -65,6 +65,7 @@ def __init__(self, tag_version, self.time = datetime.datetime.now() self.extra = kw self.dirty = dirty + self.preformated = preformated @property def exact(self): From 8d995d7714c927c6fd36a9e8986d7ad5371dafc0 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:24:07 +0200 Subject: [PATCH 3/6] fix spelling of preformatted --- setuptools_scm/version.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py index 5da805ac..9d2568d0 100644 --- a/setuptools_scm/version.py +++ b/setuptools_scm/version.py @@ -55,8 +55,9 @@ def tags_to_versions(tags): class ScmVersion(object): def __init__(self, tag_version, distance=None, node=None, dirty=False, - preformated=False, + preformatted=False, **kw): + assert not kw, kw self.tag = tag_version if dirty and distance is None: distance = 0 @@ -65,7 +66,7 @@ def __init__(self, tag_version, self.time = datetime.datetime.now() self.extra = kw self.dirty = dirty - self.preformated = preformated + self.preformatted = preformatted @property def exact(self): @@ -86,16 +87,16 @@ def format_choice(self, clean_format, dirty_format): return self.format_with(dirty_format if self.dirty else clean_format) -def _parse_tag(tag, preformated): - if preformated: +def _parse_tag(tag, preformatted): + if preformatted: return tag if SetuptoolsVersion is None or not isinstance(tag, SetuptoolsVersion): tag = tag_to_version(tag) return tag -def meta(tag, distance=None, dirty=False, node=None, preformated=False, **kw): - tag = _parse_tag(tag, preformated) +def meta(tag, distance=None, dirty=False, node=None, preformatted=False, **kw): + tag = _parse_tag(tag, preformatted) trace('version', tag) assert tag is not None, 'cant parse version %s' % tag return ScmVersion(tag, distance, node, dirty, **kw) @@ -155,7 +156,7 @@ def postrelease_version(version): def format_version(version, **config): trace('scm version', version) trace('config', config) - if version.preformated: + if version.preformatted: return version.tag version_scheme = callable_or_entrypoint( 'setuptools_scm.version_scheme', config['version_scheme']) From 072c43c40e633efa373707373b7657d4818cac3e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:25:25 +0200 Subject: [PATCH 4/6] switch an assert for a trace --- setuptools_scm/version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py index 9d2568d0..d083fb8c 100644 --- a/setuptools_scm/version.py +++ b/setuptools_scm/version.py @@ -57,7 +57,8 @@ def __init__(self, tag_version, distance=None, node=None, dirty=False, preformatted=False, **kw): - assert not kw, kw + if kw: + trace("unknown args", kw) self.tag = tag_version if dirty and distance is None: distance = 0 From f9dd60a70492f421242daa5752f1ac358c3a4226 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:29:37 +0200 Subject: [PATCH 5/6] actually pass along preformatted --- setuptools_scm/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py index d083fb8c..dce8c750 100644 --- a/setuptools_scm/version.py +++ b/setuptools_scm/version.py @@ -100,7 +100,7 @@ def meta(tag, distance=None, dirty=False, node=None, preformatted=False, **kw): tag = _parse_tag(tag, preformatted) trace('version', tag) assert tag is not None, 'cant parse version %s' % tag - return ScmVersion(tag, distance, node, dirty, **kw) + return ScmVersion(tag, distance, node, dirty, preformatted, **kw) def guess_next_version(tag_version, distance): From a9a1bd5a0aec3f52f0f09de62fcc18a62b959bdc Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Apr 2017 18:39:45 +0200 Subject: [PATCH 6/6] acceptance test and changelog for issue #167 --- CHANGELOG.rst | 6 ++++++ testing/conftest.py | 10 +++++++--- testing/test_basic_api.py | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 50f0cdef..054bfe57 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +v1.15.5 +======= + +* fix #167 by correctly respecting preformatted version metadata + from PKG-INFO/EGG-INFO + v1.15.4 ======= diff --git a/testing/conftest.py b/testing/conftest.py index 49a9d14b..29e129c5 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -52,14 +52,18 @@ def commit_testfile(self, reason=None): self(self.add_command) self.commit(reason=reason) - @property - def version(self): + def get_version(self, **kw): __tracebackhide__ = True from setuptools_scm import get_version - version = get_version(root=str(self.cwd)) + version = get_version(root=str(self.cwd), **kw) print(version) return version + @property + def version(self): + __tracebackhide__ = True + return self.get_version() + @pytest.yield_fixture(autouse=True) def debug_mode(): diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py index 5f9e1d60..4192f714 100644 --- a/testing/test_basic_api.py +++ b/testing/test_basic_api.py @@ -30,6 +30,9 @@ def test_version_from_pkginfo(wd): wd.write('PKG-INFO', 'Version: 0.1') assert wd.version == '0.1' + # replicate issue 167 + assert wd.get_version(version_scheme="1.{0.distance}.0".format) == '0.1' + def assert_root(monkeypatch, expected_root): """