Skip to content

Commit a8a7168

Browse files
fix #286 - return a list from tags_to_versions
1 parent 6f27033 commit a8a7168

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v3.0.3
2+
======
3+
4+
* fix #286 - duo an oversight a helper functio nwas returning a generator instead of a list
5+
6+
17
v3.0.2
28
======
39

src/setuptools_scm/version.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def _parse_version_tag(tag, config):
3030
if len(match.groups()) == 1:
3131
key = 1
3232
else:
33-
key = 'version'
34-
33+
key = "version"
34+
3535
result = {
36-
'version': match.group(key),
37-
'prefix': match.group(0)[:match.start(key)],
38-
'suffix': match.group(0)[match.end(key):],
36+
"version": match.group(key),
37+
"prefix": match.group(0)[:match.start(key)],
38+
"suffix": match.group(0)[match.end(key):],
3939
}
4040

4141
trace("tag '%s' parsed to %s" % (tag, result))
@@ -88,20 +88,21 @@ def tag_to_version(tag, config=None):
8888
config = Configuration()
8989

9090
tagdict = _parse_version_tag(tag, config)
91-
if not isinstance(tagdict, dict) or not tagdict.get('version', None):
91+
if not isinstance(tagdict, dict) or not tagdict.get("version", None):
9292
warnings.warn("tag %r no version found" % (tag,))
9393
return None
9494

95-
version = tagdict['version']
95+
version = tagdict["version"]
9696
trace("version pre parse", version)
9797

98-
if tagdict.get('suffix', ''):
99-
warnings.warn("tag %r will be stripped of its suffix '%s'" % (tag, tagdict['suffix']))
98+
if tagdict.get("suffix", ""):
99+
warnings.warn(
100+
"tag %r will be stripped of its suffix '%s'" % (tag, tagdict["suffix"])
101+
)
100102

101103
if VERSION_CLASS is not None:
102104
version = pkg_parse_version(version)
103105
trace("version", repr(version))
104-
105106
return version
106107

107108

@@ -111,7 +112,12 @@ def tags_to_versions(tags, config=None):
111112
:param tags: an iterable of tags
112113
:param config: optional configuration object
113114
"""
114-
return filter(None, map(lambda tag: tag_to_version(tag, config=config), tags))
115+
result = []
116+
for tag in tags:
117+
tag = tag_to_version(tag, config=config)
118+
if tag:
119+
result.append(tag)
120+
return result
115121

116122

117123
class ScmVersion(object):
@@ -176,9 +182,14 @@ def _parse_tag(tag, preformatted, config):
176182
return tag
177183

178184

179-
def meta(tag, distance=None, dirty=False, node=None, preformatted=False, config=None, **kw):
185+
def meta(
186+
tag, distance=None, dirty=False, node=None, preformatted=False, config=None, **kw
187+
):
180188
if not config:
181-
warnings.warn("meta invoked without explicit configuration, will use defaults where required.")
189+
warnings.warn(
190+
"meta invoked without explicit configuration,"
191+
" will use defaults where required."
192+
)
182193
parsed_version = _parse_tag(tag, preformatted, config)
183194
trace("version", tag, "->", parsed_version)
184195
assert parsed_version is not None, "cant parse version %s" % tag

testing/test_version.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from setuptools_scm.config import Configuration
3-
from setuptools_scm.version import meta, simplified_semver_version
3+
from setuptools_scm.version import meta, simplified_semver_version, tags_to_versions
44

55

66
@pytest.mark.parametrize(
@@ -49,6 +49,13 @@ def test_next_semver(version, expected_next):
4949
],
5050
)
5151
def test_tag_regex1(tag, expected):
52-
Configuration().tag_regex = r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$'
52+
Configuration().tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$"
5353
result = meta(tag)
5454
assert result.tag.public == expected
55+
56+
57+
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/286")
58+
def test_tags_to_versions():
59+
config = Configuration()
60+
versions = tags_to_versions(["1", "2", "3"], config=config)
61+
assert isinstance(versions, list) # enable subscription

0 commit comments

Comments
 (0)