diff options
author | chrisjbillington <chrisjbillington@gmail.com> | 2020-05-11 16:57:40 -0400 |
---|---|---|
committer | chrisjbillington <chrisjbillington@gmail.com> | 2020-05-11 17:25:47 -0400 |
commit | 26f8ff952675bc0be3dba59830d04e36bf1d172d (patch) | |
tree | 61f210720e74851c69f0584b0a8f3bc049b1dd1d | |
parent | e62d4aac4b2e9fa7c5c120f2f3b5108db21d52a2 (diff) | |
download | setuptools-scm-26f8ff952675bc0be3dba59830d04e36bf1d172d.tar.gz |
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.
-rw-r--r-- | src/setuptools_scm/version.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index cc4d838..1454a7a 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -2,7 +2,6 @@ from __future__ import print_function import datetime import warnings import re -from itertools import chain, repeat, islice from .config import Configuration from .utils import trace, string_types, utc @@ -16,11 +15,6 @@ SEMVER_PATCH = 3 SEMVER_LEN = 3 -def _pad(iterable, size, padding=None): - padded = chain(iterable, repeat(padding)) - return list(islice(padded, size)) - - def _parse_version_tag(tag, config): tagstring = tag if not isinstance(tag, string_types) else str(tag) match = config.tag_regex.match(tagstring) @@ -249,12 +243,14 @@ def guess_next_dev_version(version): def guess_next_simple_semver(version, retain, increment=True): - parts = map(int, str(version).split(".")) - parts = _pad(parts, retain, 0) + parts = [int(i) for i in str(version).split(".")[:retain]] + while len(parts) < retain: + parts.append(0) if increment: parts[-1] += 1 - parts = _pad(parts, SEMVER_LEN, 0) - return ".".join(map(str, parts)) + while len(parts) < SEMVER_LEN: + parts.append(0) + return ".".join(str(i) for i in parts) def simplified_semver_version(version): |