-
-
Notifications
You must be signed in to change notification settings - Fork 227
fix issue #103 - reorder version dumping #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -37,6 +38,7 @@ def _version_from_entrypoint(root, entrypoint): | |
|
||
|
||
def dump_version(root, version, write_to, template=None): | ||
assert isinstance(version, string_types) | ||
if not write_to: | ||
return | ||
target = os.path.normpath(os.path.join(root, write_to)) | ||
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ^^ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:") | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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