Skip to content

Commit 5c9ed9e

Browse files
fix #266 and add a unittest for the tag_to_version
1 parent c50979a commit 5c9ed9e

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ v3.0.0
66
* switch to src layout (breaking change)
77
* no longer alias tag and parsed_version in order to support understanding a version parse failure
88
* require parse results to be ScmVersion or None (breaking change)
9+
* fix #266 by requirin the prefix word to be a word again
10+
(breaking change as the bug allowed arbitrary prefixes while the original feature only allowed words")
911

1012
v2.1.0
1113
======

src/setuptools_scm/version.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SEMVER_MINOR = 2
1414
SEMVER_PATCH = 3
1515
SEMVER_LEN = 3
16+
TAG_PREFIX = re.compile(r"^\w+-(.*)")
1617

1718

1819
def _pad(iterable, size, padding=None):
@@ -56,14 +57,21 @@ def callable_or_entrypoint(group, callable_or_name):
5657

5758

5859
def tag_to_version(tag):
60+
"""
61+
take a tag that might be prefixed with a keyword and return only the version part
62+
"""
5963
trace("tag", tag)
6064
if "+" in tag:
6165
warnings.warn("tag %r will be stripped of the local component" % tag)
6266
tag = tag.split("+")[0]
6367
# lstrip the v because of py2/py3 differences in setuptools
6468
# also required for old versions of setuptools
65-
66-
version = tag.rsplit("-", 1)[-1].lstrip("v")
69+
prefix_match = TAG_PREFIX.match(tag)
70+
if prefix_match is not None:
71+
version = prefix_match.group(1)
72+
else:
73+
version = tag
74+
trace("version pre parse", version)
6775
if VERSION_CLASS is None:
6876
return version
6977
version = pkg_parse_version(version)

testing/test_functions.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
import sys
33
import pkg_resources
44
from setuptools_scm import dump_version, get_version, PRETEND_KEY
5-
from setuptools_scm.version import guess_next_version, meta, format_version
5+
from setuptools_scm.version import (
6+
guess_next_version,
7+
meta,
8+
format_version,
9+
tag_to_version,
10+
)
611
from setuptools_scm.utils import has_command
712

813
PY3 = sys.version_info > (2,)
@@ -77,3 +82,16 @@ def test_has_command(recwarn):
7782
assert not has_command("yadayada_setuptools_aint_ne")
7883
msg = recwarn.pop()
7984
assert "yadayada" in str(msg.message)
85+
86+
87+
@pytest.mark.parametrize(
88+
"tag, expected_version",
89+
[
90+
("1.1", "1.1"),
91+
("release-1.1", "1.1"),
92+
pytest.param("3.3.1-rc26", "3.3.1rc26", marks=pytest.mark.issue(266)),
93+
],
94+
)
95+
def test_tag_to_version(tag, expected_version):
96+
version = str(tag_to_version(tag))
97+
assert version == expected_version

0 commit comments

Comments
 (0)