Repository: pypa/setuptools_scm
Pull request #267 (2018-05-21 18:15:40)

assorted fixes


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 55810d0..adc33c1 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -3,7 +3,9 @@ v3.0.0
 
 * introduce pre-commit and use black
 * print the origin module to help testing
-* switch to src layout
+* switch to src layout (breaking change)
+* no longer alias tag and parsed_version in order to support understanding a version parse failure
+* require parse results to be ScmVersion or None (breaking change)
 
 v2.1.0
 ======
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
index 4beef3a..b256289 100644
--- a/src/setuptools_scm/__init__.py
+++ b/src/setuptools_scm/__init__.py
@@ -4,10 +4,9 @@
 """
 import os
 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 +45,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):
@@ -67,13 +65,9 @@ def _do_parse(root, parse):
     if 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",
-                category=DeprecationWarning,
+            raise TypeError(
+                "version parse result was a string\nplease return a parsed version"
             )
-            # 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"
         )
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index e49a688..aba231d 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:
@@ -36,7 +36,7 @@ class SetuptoolsOutdatedWarning(Warning):
 
 
 # append so integrators can disable the warning
-warnings.simplefilter("error", SetuptoolsOutdatedWarning, append=1)
+warnings.simplefilter("error", SetuptoolsOutdatedWarning, append=True)
 
 
 def _warn_if_setuptools_outdated():
@@ -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


Test patch:
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index fbe8cf2..b26688b 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -4,7 +4,6 @@ import pytest
 
 import setuptools_scm
 from setuptools_scm import dump_version
-
 from setuptools_scm.utils import data_from_mime, do
 
 
@@ -77,13 +76,10 @@ def test_dump_version(tmpdir):
     ast.parse(content)
 
 
-def test_parse_plain(recwarn):
+def test_parse_plain_fails(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"
-    )
+    with pytest.raises(TypeError):
+        setuptools_scm.get_version(parse=parse)
diff --git a/testing/test_setuptools_support.py b/testing/test_setuptools_support.py
index 16bcdb5..ce3444e 100644
--- a/testing/test_setuptools_support.py
+++ b/testing/test_setuptools_support.py
@@ -54,9 +54,9 @@ main()
 
 def check(packagedir, expected_version, **env):
 
-    old_pythonpath = os.environ.get('PYTHONPATH')
+    old_pythonpath = os.environ.get("PYTHONPATH")
     if old_pythonpath:
-        pythonpath = '{}:{}'.format(old_pythonpath, packagedir)
+        pythonpath = "{}:{}".format(old_pythonpath, packagedir)
     else:
         pythonpath = str(packagedir)
     subprocess.check_call(