Skip to content

Commit

Permalink
Merge pull request #168 from RonnyPfannschmidt/fix-167
Browse files Browse the repository at this point in the history
try to fix #167 by introducing a preformated flag
  • Loading branch information
RonnyPfannschmidt authored Apr 8, 2017
2 parents 00f3fbe + a9a1bd5 commit 75897ba
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.15.5
=======

* fix #167 by correctly respecting preformatted version metadata
from PKG-INFO/EGG-INFO

v1.15.4
=======

Expand Down
2 changes: 1 addition & 1 deletion setuptools_scm/hacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 15 additions & 3 deletions setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def tags_to_versions(tags):
class ScmVersion(object):
def __init__(self, tag_version,
distance=None, node=None, dirty=False,
preformatted=False,
**kw):
if kw:
trace("unknown args", kw)
self.tag = tag_version
if dirty and distance is None:
distance = 0
Expand All @@ -64,6 +67,7 @@ def __init__(self, tag_version,
self.time = datetime.datetime.now()
self.extra = kw
self.dirty = dirty
self.preformatted = preformatted

@property
def exact(self):
Expand All @@ -84,13 +88,19 @@ 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, preformatted):
if preformatted:
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, 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):
Expand Down Expand Up @@ -147,6 +157,8 @@ def postrelease_version(version):
def format_version(version, **config):
trace('scm version', version)
trace('config', config)
if version.preformatted:
return version.tag
version_scheme = callable_or_entrypoint(
'setuptools_scm.version_scheme', config['version_scheme'])
local_scheme = callable_or_entrypoint(
Expand Down
10 changes: 7 additions & 3 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions testing/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 75897ba

Please sign in to comment.