Skip to content

Commit 1cb4c5a

Browse files
Merge pull request #496 from RonnyPfannschmidt/fix-471-better-error-on-broken-bump
fix #471: better error when a simplicistic version bump fails
2 parents 57c3590 + ef36e47 commit 1cb4c5a

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
v4.2.0
22
======
33

4-
4+
* fix #471: better error for version bump failing on complex but accepted tag
55
* fix #479: raise indicative error when tags carry non-parsable information
66
* Add `no-guess-dev` which does no next version guessing, just adds `.post1.devN` in
77
case there are new commits after the tag

src/setuptools_scm/version.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,15 @@ def _bump_dev(version):
235235

236236

237237
def _bump_regex(version):
238-
prefix, tail = re.match(r"(.*?)(\d+)$", version).groups()
239-
return "%s%d" % (prefix, int(tail) + 1)
238+
match = re.match(r"(.*?)(\d+)$", version)
239+
if match is None:
240+
raise ValueError(
241+
"{version} does not end with a number to bump, "
242+
"please correct or use a custom version scheme".format(version=version)
243+
)
244+
else:
245+
prefix, tail = match.groups()
246+
return "%s%d" % (prefix, int(tail) + 1)
240247

241248

242249
def guess_next_dev_version(version):

testing/test_version.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
release_branch_semver_version,
77
tags_to_versions,
88
no_guess_dev_version,
9+
guess_next_version,
910
)
1011

1112

@@ -128,19 +129,28 @@ def test_no_guess_version(version, expected_next):
128129
],
129130
)
130131
def test_tag_regex1(tag, expected):
131-
config = Configuration()
132132
if "+" in tag:
133133
# pytest bug wrt cardinality
134134
with pytest.warns(UserWarning):
135-
result = meta(tag, config=config)
135+
result = meta(tag, config=c)
136136
else:
137-
result = meta(tag, config=config)
137+
result = meta(tag, config=c)
138138

139139
assert result.tag.public == expected
140140

141141

142142
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/286")
143143
def test_tags_to_versions():
144-
config = Configuration()
145-
versions = tags_to_versions(["1.0", "2.0", "3.0"], config=config)
144+
versions = tags_to_versions(["1.0", "2.0", "3.0"], config=c)
146145
assert isinstance(versions, list) # enable subscription
146+
147+
148+
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/471")
149+
def test_version_bump_bad():
150+
with pytest.raises(
151+
ValueError,
152+
match=".*does not end with a number to bump, "
153+
"please correct or use a custom version scheme",
154+
):
155+
156+
guess_next_version(tag_version="2.0.0-alpha.5-PMC")

0 commit comments

Comments
 (0)