Skip to content

Commit 2480097

Browse files
Merge pull request #1428 from RonnyPfannschmidt/fix/compat-shim-parse-version
fix: add backward-compat shim for parse_version (#1423)
2 parents a841b68 + 2c17c0e commit 2480097

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

setuptools-scm/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
build-backend = "setuptools.build_meta"
33
requires = [
44
"setuptools>=77.0.3",
5-
"vcs-versioning>=2.0.0.dev0",
5+
"vcs-versioning>=2.0.0.dev0,<3",
66
# https://github.com/pypa/setuptools-scm/issues/1222: was <=2.0.2 for #1090 (old pip+toml);
77
# pip 21.2+ vendors tomli, so the workaround is no longer needed.
88
'tomli>=1; python_version < "3.11"',
@@ -37,7 +37,8 @@ dynamic = [
3737
]
3838
dependencies = [
3939
# Core VCS functionality - workspace dependency
40-
"vcs-versioning>=2.0.0.dev0",
40+
# Upper pin: setuptools-scm imports vcs-versioning internals; keep in sync.
41+
"vcs-versioning>=2.0.0.dev0,<3",
4142
"packaging>=20",
4243
# https://github.com/pypa/setuptools-scm/issues/1112 - re-pin in a breaking release
4344
"setuptools", # >= 61",

vcs-versioning/src/vcs_versioning/_get_version_impl.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
log = logging.getLogger(__name__)
3030

3131

32+
def parse_version(config: Configuration) -> ScmVersion | None:
33+
"""Backward-compat shim for setuptools-scm <=10.0.x.
34+
35+
Those releases import ``parse_version`` from this module. The function
36+
was inlined during the 10.1 / vcs-versioning 2.0 refactor, but we keep
37+
the name importable so that older setuptools-scm pins still work with
38+
newer vcs-versioning releases.
39+
"""
40+
scm_version = _resolve_version(config)
41+
return _apply_metadata_overrides(scm_version, config)
42+
43+
3244
def _finalize(
3345
scm_version: ScmVersion,
3446
config: Configuration,

vcs-versioning/testing_vcs/test_regressions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ def test_no_warn_when_version_file_not_tracked(tmp_path: Path, scm: str) -> None
138138
assert tracked_warnings == []
139139

140140

141+
@pytest.mark.issue(1423)
142+
def test_parse_version_importable_from_get_version_impl() -> None:
143+
"""setuptools-scm <=10.0.x imports parse_version from this module."""
144+
from vcs_versioning._get_version_impl import parse_version
145+
146+
assert callable(parse_version)
147+
148+
149+
@pytest.mark.issue(1423)
150+
def test_parse_version_shim_returns_version(tmp_path: Path) -> None:
151+
"""The compat shim should resolve and return a ScmVersion."""
152+
wd = WorkDir(tmp_path).setup_git()
153+
wd.add_and_commit("initial")
154+
wd("git tag -a v1.0.0 -m v1.0.0")
155+
156+
c = Configuration(root=tmp_path)
157+
158+
from vcs_versioning._get_version_impl import parse_version
159+
from vcs_versioning._scm_version import ScmVersion
160+
161+
result = parse_version(c)
162+
assert isinstance(result, ScmVersion)
163+
164+
141165
@pytest.mark.parametrize(
142166
("input", "expected"),
143167
[

0 commit comments

Comments
 (0)