Skip to content

Commit 6e22672

Browse files
Fix logging configuration, empty tag regex warning, and test patches
- Fixed parse_tag_regex handling to emit deprecation warning properly - setuptools_scm.get_version now delegates to vcs_versioning.get_version - Fixed import of strip_path_suffix in file_finders/git.py to use vcs_versioning - Fixed test patches in test_git.py to patch _git module instead of re-exported git
1 parent 3f55d14 commit 6e22672

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

nextgen/vcs-versioning/src/vcs_versioning/_get_version_impl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,14 @@ def get_version(
248248

249249

250250
def parse_tag_regex(tag_regex: str | Pattern[str]) -> Pattern[str]:
251+
"""Pre-validate and convert tag_regex to Pattern before Configuration.
252+
253+
This ensures get_version() emits the deprecation warning for empty strings
254+
before Configuration.__post_init__ runs.
255+
"""
251256
if isinstance(tag_regex, str):
252257
if tag_regex == "":
253-
warnings.warn(EMPTY_TAG_REGEX_DEPRECATION)
258+
warnings.warn(EMPTY_TAG_REGEX_DEPRECATION, stacklevel=3)
254259
return _config.DEFAULT_TAG_REGEX
255260
else:
256261
return re.compile(tag_regex)

src/setuptools_scm/_file_finders/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _git_toplevel(path: str) -> str | None:
3939
# ``cwd`` is absolute path to current working directory.
4040
# the below method removes the length of ``out`` from
4141
# ``cwd``, which gives the git toplevel
42-
from .._compat import strip_path_suffix
42+
from vcs_versioning._compat import strip_path_suffix
4343

4444
out = strip_path_suffix(cwd, out, f"cwd={cwd!r}\nout={out!r}")
4545
log.debug("find files toplevel %s", out)

src/setuptools_scm/_get_version_impl.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ def get_version(root: str | PathLike[str] | None = None, **kwargs: object) -> st
2323
root: Optional root directory (can be passed as positional arg for backward compat)
2424
**kwargs: Additional configuration parameters
2525
"""
26-
from vcs_versioning.config import Configuration
26+
from vcs_versioning._get_version_impl import get_version as _vcs_get_version
2727

2828
if root is not None:
2929
kwargs["root"] = root
30-
config = Configuration(**kwargs) # type: ignore[arg-type]
31-
version = _get_version(config, force_write_version_files=False)
32-
if version is None:
33-
raise RuntimeError("Unable to determine version")
34-
return version
30+
# Delegate to vcs_versioning's get_version which handles all validation including tag_regex
31+
return _vcs_get_version(**kwargs) # type: ignore[arg-type]
3532

3633

3734
__all__ = [

testing/test_git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def test_git_getdate_badgit(
508508
git_wd = git.GitWorkdir(wd.cwd)
509509
fake_date_result = CompletedProcess(args=[], stdout="%cI", stderr="", returncode=0)
510510
with patch.object(
511-
git,
511+
_git,
512512
"run_git",
513513
Mock(return_value=fake_date_result),
514514
):
@@ -524,7 +524,7 @@ def test_git_getdate_git_2_45_0_plus(
524524
args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0
525525
)
526526
with patch.object(
527-
git,
527+
_git,
528528
"run_git",
529529
Mock(return_value=fake_date_result),
530530
):

0 commit comments

Comments
 (0)