summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2018-05-20 11:29:46 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2018-05-21 16:28:34 +0200
commit71d28ac8bb85637b1929faa941dd4acd44978f3b (patch)
treec3c24c926769cec66f66d6f01380737a68ffea87
parent3469893c6802a79a890c44b56c9ecb6f1aec9ede (diff)
downloadsetuptools-scm-71d28ac8bb85637b1929faa941dd4acd44978f3b.tar.gz
sort out parse_version debugging, fixes #261
-rw-r--r--CHANGELOG.rst2
-rw-r--r--src/setuptools_scm/__init__.py17
-rw-r--r--src/setuptools_scm/version.py14
-rw-r--r--tox.ini6
4 files changed, 22 insertions, 17 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 55810d0..41d16bf 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -4,6 +4,8 @@ v3.0.0
* introduce pre-commit and use black
* print the origin module to help testing
* switch to src layout
+* no longer alias tag and parsed_version in order to support understanding a version parse failure
+* require parse results to be ScmVersion or None
v2.1.0
======
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
index 4beef3a..6b61b3f 100644
--- a/src/setuptools_scm/__init__.py
+++ b/src/setuptools_scm/__init__.py
@@ -7,7 +7,7 @@ import sys
import warnings
from .utils import trace
-from .version import format_version, meta, ScmVersion
+from .version import format_version, meta
from .discover import iter_matching_entrypoints
PRETEND_KEY = "SETUPTOOLS_SCM_PRETEND_VERSION"
@@ -46,15 +46,14 @@ def dump_version(root, version, write_to, template=None):
ext = os.path.splitext(target)[1]
template = template or TEMPLATES.get(ext)
- if template is not None:
- dump = template.format(version=version)
- else:
+ if template is None:
raise ValueError(
- ("bad file format: '%s' (of %s) \n" "only *.txt and *.py are supported")
- % (os.path.splitext(target)[1], target)
+ "bad file format: '{}' (of {}) \nonly *.txt and *.py are supported".format(
+ os.path.splitext(target)[1], target
+ )
)
with open(target, "w") as fp:
- fp.write(dump)
+ fp.write(template.format(version=version))
def _do_parse(root, parse):
@@ -68,12 +67,12 @@ def _do_parse(root, parse):
parse_result = parse(root)
if isinstance(parse_result, string_types):
warnings.warn(
- "version parse result was a string\n" "please return a parsed version",
+ "version parse result was a string\nplease 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)
+ parse_result = meta(parse_result)
version = parse_result or _version_from_entrypoint(
root, "setuptools_scm.parse_scm_fallback"
)
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index e49a688..2b9037f 100644
--- a/src/setuptools_scm/version.py
+++ b/src/setuptools_scm/version.py
@@ -8,7 +8,7 @@ from .utils import trace
from pkg_resources import iter_entry_points
-from pkg_resources import parse_version
+from pkg_resources import parse_version as pkg_parse_version
SEMVER_MINOR = 2
SEMVER_PATCH = 3
@@ -21,7 +21,7 @@ def _pad(iterable, size, padding=None):
def _get_version_class():
- modern_version = parse_version("1.0")
+ modern_version = pkg_parse_version("1.0")
if isinstance(modern_version, tuple):
return None
else:
@@ -66,7 +66,7 @@ def tag_to_version(tag):
version = tag.rsplit("-", 1)[-1].lstrip("v")
if VERSION_CLASS is None:
return version
- version = parse_version(version)
+ version = pkg_parse_version(version)
trace("version", repr(version))
if isinstance(version, VERSION_CLASS):
return version
@@ -140,10 +140,10 @@ def _parse_tag(tag, preformatted):
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, preformatted, **kw)
+ parsed_version = _parse_tag(tag, preformatted)
+ trace("version", tag, "->", parsed_version)
+ assert parsed_version is not None, "cant parse version %s" % tag
+ return ScmVersion(parsed_version, distance, node, dirty, preformatted, **kw)
def guess_next_version(tag_version):
diff --git a/tox.ini b/tox.ini
index 864b7b1..1281b87 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist=py{27,34,35,36,37}-test,flake8,check_readme
+envlist=py{27,34,35,36,37}-test,flake8,check_readme,py{27,36}-selftest
[flake8]
max-complexity = 10
@@ -15,10 +15,14 @@ exclude=
[testenv]
usedevelop=True
+skip_install=
+ selfcheck: True
+ test: False
deps=
pytest
commands=
test: py.test []
+ selfcheck: python setup.py --version
[testenv:flake8]
skip_install=True