Skip to content

Commit bb5edd7

Browse files
Fix test monkeypatching and get_version() positional argument
- Updated assert_root() to patch vcs_versioning._get_version_impl instead of setuptools_scm - Added root parameter to get_version() to support positional arguments (issue #669) - Support PathLike in get_version() root parameter for type compatibility - Updated test_basic_api.py to patch at the correct module level Test improvements: - test_root_parameter_pass_by now passes (was failing due to monkeypatch) - 3/21 tests passing in test_basic_api - test_parentdir_prefix now failing on output format (unrelated to refactoring)
1 parent 0241064 commit bb5edd7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/setuptools_scm/_get_version_impl.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
from os import PathLike
6+
57
from vcs_versioning._get_version_impl import _find_scm_in_parents
68
from vcs_versioning._get_version_impl import _get_version
79
from vcs_versioning._get_version_impl import _version_missing
@@ -12,13 +14,19 @@
1214

1315

1416
# Legacy get_version function (soft deprecated)
15-
def get_version(**kwargs: object) -> str:
17+
def get_version(root: str | PathLike[str] | None = None, **kwargs: object) -> str:
1618
"""Legacy API - get version string
1719
1820
This function is soft deprecated. Use Configuration.from_file() and _get_version() instead.
21+
22+
Args:
23+
root: Optional root directory (can be passed as positional arg for backward compat)
24+
**kwargs: Additional configuration parameters
1925
"""
2026
from vcs_versioning.config import Configuration
2127

28+
if root is not None:
29+
kwargs["root"] = root
2230
config = Configuration(**kwargs) # type: ignore[arg-type]
2331
version = _get_version(config, force_write_version_files=False)
2432
if version is None:

testing/test_basic_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def assertion(config: Configuration) -> ScmVersion:
6161

6262
return ScmVersion(Version("1.0"), config=config)
6363

64-
monkeypatch.setattr(setuptools_scm._get_version_impl, "parse_version", assertion)
64+
# Patch at vcs_versioning level since that's where the implementation lives
65+
import vcs_versioning._get_version_impl
66+
67+
monkeypatch.setattr(vcs_versioning._get_version_impl, "parse_version", assertion)
6568

6669

6770
def test_root_parameter_creation(monkeypatch: pytest.MonkeyPatch) -> None:

0 commit comments

Comments
 (0)