Skip to content

Commit 26f8ff9

Browse files
Allow guess_next_simple_semver to ignore unneeded parts
guess_next_simple_semver previously would error on trying to convert the 'rc0' part of a version such as '1.2.0rc1' to an int, even if it was told to retain only the first two parts. (It would actually only error on Python 2, where the conversion to int was non-lazy) Now if it's told to retain only the first two parts, it won't try to convert anything after the first two dots to an int, so it won't error. The outcome is the same as if the bit after the second dot was a valid int (which was going to be ignored anyway, we just now don't error on it). This is useful for the release-branch-semver scheme, which wants to be able to find the next minor version even if the most recent version is a release candidate.
1 parent e62d4aa commit 26f8ff9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/setuptools_scm/version.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import datetime
33
import warnings
44
import re
5-
from itertools import chain, repeat, islice
65

76
from .config import Configuration
87
from .utils import trace, string_types, utc
@@ -16,11 +15,6 @@
1615
SEMVER_LEN = 3
1716

1817

19-
def _pad(iterable, size, padding=None):
20-
padded = chain(iterable, repeat(padding))
21-
return list(islice(padded, size))
22-
23-
2418
def _parse_version_tag(tag, config):
2519
tagstring = tag if not isinstance(tag, string_types) else str(tag)
2620
match = config.tag_regex.match(tagstring)
@@ -249,12 +243,14 @@ def guess_next_dev_version(version):
249243

250244

251245
def guess_next_simple_semver(version, retain, increment=True):
252-
parts = map(int, str(version).split("."))
253-
parts = _pad(parts, retain, 0)
246+
parts = [int(i) for i in str(version).split(".")[:retain]]
247+
while len(parts) < retain:
248+
parts.append(0)
254249
if increment:
255250
parts[-1] += 1
256-
parts = _pad(parts, SEMVER_LEN, 0)
257-
return ".".join(map(str, parts))
251+
while len(parts) < SEMVER_LEN:
252+
parts.append(0)
253+
return ".".join(str(i) for i in parts)
258254

259255

260256
def simplified_semver_version(version):

0 commit comments

Comments
 (0)