Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v2.0.0
========

* fix regression caused by the fix of #101
* assert types for version dumping
* strictly pass all versions trough parsed version metadata

v1.12.0
=======

Expand Down
38 changes: 25 additions & 13 deletions setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""
import os
import sys
import warnings

from .utils import trace
from .version import format_version
from .version import format_version, meta, ScmVersion
from .discover import find_matching_entrypoint

PRETEND_KEY = 'SETUPTOOLS_SCM_PRETEND_VERSION'
Expand Down Expand Up @@ -37,6 +38,7 @@ def _version_from_entrypoint(root, entrypoint):


def dump_version(root, version, write_to, template=None):
assert isinstance(version, string_types)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this detect the new failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code in dump-version only works with strings, perhaps even this check is not trough enough

if not write_to:
return
target = os.path.normpath(os.path.join(root, write_to))
Expand All @@ -59,10 +61,21 @@ def dump_version(root, version, write_to, template=None):
def _do_parse(root, parse):
pretended = os.environ.get(PRETEND_KEY)
if pretended:
return pretended
# we use meta here since the pretended version
# must adhere to the pep to begin with
return meta(pretended)

if parse:
version = parse(root) or _version_from_entrypoint(
parse_result = parse(root)
if isinstance(parse_result, string_types):
warnings.warn(
"version parse result was a string\n"
"please return a parsed version",
category=DeprecationWarning)
# we use ScmVersion here in order to keep legacy code working
# for 2.0 we should use meta
parse_result = ScmVersion(parse_result)
version = parse_result or _version_from_entrypoint(
root, 'setuptools_scm.parse_scm_fallback')
else:
# include fallbacks after dropping them from the main entrypoint
Expand Down Expand Up @@ -101,18 +114,17 @@ def get_version(root='.',
root = os.path.abspath(root)
trace('root', repr(root))

version = _do_parse(root, parse)
parsed_version = _do_parse(root, parse)

if version:
if parsed_version:
version_string = format_version(
parsed_version,
version_scheme=version_scheme,
local_scheme=local_scheme)
dump_version(
root=root,
version=version,
version=version_string,
write_to=write_to,
template=write_to_template)
if isinstance(version, string_types):
return version
version = format_version(
version,
version_scheme=version_scheme,
local_scheme=local_scheme)
return version

return version_string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this: much clearer than the previous implementation - i thought of doing something like that in my own PR but refrained to keep things simple...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did a more intensive restructure ensuring i never get a string there - the shortcut was an premature optimization, and as such the root of the evil ^^

3 changes: 2 additions & 1 deletion setuptools_scm/hacks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from .utils import data_from_mime, trace
from .version import meta


def parse_pkginfo(root):
Expand All @@ -9,4 +10,4 @@ def parse_pkginfo(root):
data = data_from_mime(pkginfo)
version = data.get('Version')
if version != 'UNKNOWN':
return version
return meta(version)
4 changes: 3 additions & 1 deletion testing/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def test_dump_version(tmpdir):
ast.parse(content)


def test_parse_plain():
def test_parse_plain(recwarn):
def parse(root):
return 'tricked you'
assert setuptools_scm.get_version(parse=parse) == 'tricked you'
assert str(recwarn.pop().message) == \
'version parse result was a string\nplease return a parsed version'
2 changes: 1 addition & 1 deletion testing/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_format_version(version, monkeypatch, scheme, expected):

def test_dump_version_doesnt_bail_on_value_error(tmpdir):
write_to = "VERSION"
version = VERSIONS['exact']
version = str(VERSIONS['exact'].tag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what isthis for - would this silence possible unit test failures that could detect the fixed bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exact.tag is a setultools version not a string

with pytest.raises(ValueError) as exc_info:
dump_version(tmpdir.strpath, version, write_to)
assert str(exc_info.value).startswith("bad file format:")
Expand Down