summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-27 07:26:39 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-27 07:27:08 +0200
commit8af496d3f58fc20bc5e005e2e99d6eb2bc3d8d43 (patch)
treee68e0b5f4cbef9baa1b32e59361cb9e9be191b08
parent9fbd394884198e00ee9b1463c8dc7171b7b5ec78 (diff)
downloadsetuptools-scm-8af496d3f58fc20bc5e005e2e99d6eb2bc3d8d43.tar.gz
fix #838: handle incorrectly passed empty tag regex as default
-rw-r--r--src/setuptools_scm/__init__.py11
-rw-r--r--src/setuptools_scm/version.py21
-rw-r--r--testing/test_basic_api.py7
3 files changed, 31 insertions, 8 deletions
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
index 96c8349..faea673 100644
--- a/src/setuptools_scm/__init__.py
+++ b/src/setuptools_scm/__init__.py
@@ -6,6 +6,7 @@ from __future__ import annotations
import os
import re
+import warnings
from typing import Any
from typing import Pattern
from typing import TYPE_CHECKING
@@ -133,7 +134,15 @@ def get_version(
version_cls = _validate_version_cls(version_cls, normalize)
del normalize
if isinstance(tag_regex, str):
- tag_regex = re.compile(tag_regex)
+ if tag_regex == "":
+ warnings.warn(
+ DeprecationWarning(
+ "empty regex for tag regex is invalid, using default"
+ )
+ )
+ tag_regex = DEFAULT_TAG_REGEX
+ else:
+ tag_regex = re.compile(tag_regex)
config = Configuration(**locals())
maybe_version = _get_version(config)
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index 128533c..8cf48e8 100644
--- a/src/setuptools_scm/version.py
+++ b/src/setuptools_scm/version.py
@@ -38,10 +38,8 @@ SEMVER_LEN = 3
def _parse_version_tag(
tag: str | object, config: _config.Configuration
) -> dict[str, str] | None:
- tagstring = tag if isinstance(tag, str) else str(tag)
- match = config.tag_regex.match(tagstring)
+ match = config.tag_regex.match(str(tag))
- result = None
if match:
key: str | int
if len(match.groups()) == 1:
@@ -49,14 +47,23 @@ def _parse_version_tag(
else:
key = "version"
+ full = match.group(0)
+ log.debug("%r %r %s", tag, config.tag_regex, match)
+ log.debug(
+ "key %s data %s, %s, %r", key, match.groupdict(), match.groups(), full
+ )
result = {
"version": match.group(key),
- "prefix": match.group(0)[: match.start(key)],
- "suffix": match.group(0)[match.end(key) :],
+ "prefix": full[: match.start(key)],
+ "suffix": full[match.end(key) :],
}
- log.debug(f"tag '{tag}' parsed to {result}")
- return result
+ log.debug("tag %r parsed to %r", tag, result)
+ return result
+ else:
+ log.debug("tag %r did not parse", tag)
+
+ return None
def callable_or_entrypoint(group: str, callable_or_name: str | Any) -> Any:
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index f1b4c4f..6fd39bd 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -121,6 +121,13 @@ setup(name="myscm", use_scm_version={"fallback_version": "12.34"})
assert res.stdout == "12.34"
+def test_get_version_blank_tag_regex() -> None:
+ with pytest.warns(
+ DeprecationWarning, match="empty regex for tag regex is invalid, using default"
+ ):
+ setuptools_scm.get_version(tag_regex="")
+
+
@pytest.mark.parametrize(
"version", ["1.0", "1.2.3.dev1+ge871260", "1.2.3.dev15+ge871260.d20180625", "2345"]
)