Skip to content

Commit ed9b112

Browse files
fix #284 - allow dashes in default tag prefixes again
1 parent 3214d3e commit ed9b112

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
v3.0.2
2+
======
3+
4+
* fix a regression from tag parsing - support for multi-dashed prefixes - #284
5+
6+
17
v3.0.1
28
=======
39

4-
* fix a regression in setuptools_scm.git.parse - reorder arguments so the positional invocation from before works as expected
10+
* fix a regression in setuptools_scm.git.parse - reorder arguments so the positional invocation from before works as expected #281
511

612
v3.0.0
713
=======

src/setuptools_scm/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ def version_from_scm(root):
2929

3030

3131
def _call_entrypoint_fn(config, fn):
32-
if function_has_arg(fn, 'config'):
32+
if function_has_arg(fn, "config"):
3333
return fn(config.absolute_root, config=config)
3434
else:
35-
warnings.warn("parse functions are required to provide a named argument 'config' in the future.", PendingDeprecationWarning)
35+
warnings.warn(
36+
"parse functions are required to provide a named argument"
37+
" 'config' in the future.",
38+
PendingDeprecationWarning,
39+
)
3640
return fn(config.absolute_root)
3741

3842

@@ -75,13 +79,16 @@ def _do_parse(config):
7579
raise TypeError(
7680
"version parse result was a string\nplease return a parsed version"
7781
)
78-
version = parse_result or \
79-
_version_from_entrypoint(config, "setuptools_scm.parse_scm_fallback")
80-
82+
version = parse_result or _version_from_entrypoint(
83+
config, "setuptools_scm.parse_scm_fallback"
84+
)
8185
else:
8286
# include fallbacks after dropping them from the main entrypoint
83-
version = _version_from_entrypoint(config, "setuptools_scm.parse_scm") or \
84-
_version_from_entrypoint(config, "setuptools_scm.parse_scm_fallback")
87+
version = _version_from_entrypoint(
88+
config, "setuptools_scm.parse_scm"
89+
) or _version_from_entrypoint(
90+
config, "setuptools_scm.parse_scm_fallback"
91+
)
8592

8693
if version:
8794
return version
@@ -114,7 +121,7 @@ def get_version(
114121
in the root of the repository to direct setuptools_scm to the
115122
root of the repository by supplying ``__file__``.
116123
"""
117-
124+
118125
config = Configuration()
119126
config.root = root
120127
config.version_scheme = version_scheme

src/setuptools_scm/config.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from .utils import trace
88

9-
DEFAULT_TAG_REGEX = r'^(?:\w+-)?(?P<version>v?\d+(?:\.\d+){0,2}[^\+]+)(?:\+.*)?$'
10-
DEFAULT_VERSION_SCHEME = 'version_scheme'
9+
DEFAULT_TAG_REGEX = r"^(?:[\w-]+-)?(?P<version>v?\d+(?:\.\d+){0,2}[^\+]+)(?:\+.*)?$"
10+
DEFAULT_VERSION_SCHEME = "version_scheme"
1111

1212

1313
def _check_tag_regex(value):
@@ -16,17 +16,22 @@ def _check_tag_regex(value):
1616
regex = re.compile(value)
1717

1818
group_names = regex.groupindex.keys()
19-
if regex.groups == 0 or (regex.groups > 1 and 'version' not in group_names):
20-
warnings.warn("Expected tag_regex to contain a single match group or a group named 'version' " +
21-
"to identify the version part of any tag.")
19+
if regex.groups == 0 or (regex.groups > 1 and "version" not in group_names):
20+
warnings.warn(
21+
"Expected tag_regex to contain a single match group or a group named"
22+
" 'version' to identify the version part of any tag."
23+
)
2224

2325
return regex
2426

2527

2628
def _check_absolute_root(root, relative_to):
2729
if relative_to:
2830
if os.path.isabs(root) and not root.startswith(relative_to):
29-
warnings.warn("absolute root path '%s' overrides relative_to '%s'" % (root, relative_to))
31+
warnings.warn(
32+
"absolute root path '%s' overrides relative_to '%s'"
33+
% (root, relative_to)
34+
)
3035
root = os.path.join(os.path.dirname(relative_to), root)
3136
return os.path.abspath(root)
3237

@@ -44,17 +49,15 @@ class Configuration(object):
4449
_tag_regex = None
4550
_absolute_root = None
4651

47-
def __init__(self,
48-
relative_to=None,
49-
root='.'):
52+
def __init__(self, relative_to=None, root="."):
5053
# TODO:
5154
self._relative_to = relative_to
52-
self._root = '.'
55+
self._root = "."
5356

5457
self.root = root
5558
self.version_scheme = DEFAULT_VERSION_SCHEME
5659
self.local_scheme = "node-and-date"
57-
self.write_to = ''
60+
self.write_to = ""
5861
self.write_to_template = None
5962
self.parse = None
6063
self.tag_regex = DEFAULT_TAG_REGEX

testing/test_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from setuptools_scm.config import Configuration
2+
3+
import pytest
4+
5+
6+
@pytest.mark.parametrize(
7+
"tag, expected_version",
8+
[
9+
("apache-arrow-0.9.0", "0.9.0"),
10+
("arrow-0.9.0", "0.9.0"),
11+
("arrow-0.9.0-rc", "0.9.0-rc"),
12+
],
13+
)
14+
def test_tag_regex(tag, expected_version):
15+
config = Configuration()
16+
match = config.tag_regex.match(tag)
17+
version = match.group("version")
18+
assert version == expected_version

0 commit comments

Comments
 (0)