Skip to content

Commit d6fea05

Browse files
refactor: migrate integration code to vcs-versioning and remove private shims
Move core functionality to vcs-versioning: - Move dump_version logic to vcs_versioning/_dump_version.py - Move infer_version_string to vcs_versioning/_version_inference.py - Update vcs_versioning to use local _dump_version instead of setuptools_scm Remove unnecessary private shim modules: - Delete _types.py, _run_cmd.py, _entrypoints.py (private, not in __all__) - Delete _integration/toml.py (just a re-export) - Delete _integration/dump_version.py (now in vcs-versioning) - Keep public modules (git.py, hg.py, discover.py, fallbacks.py) for backward compat - Keep _version_cls.py (used by public API) Update imports throughout codebase: - Update all internal imports to use vcs_versioning directly - Update test imports in both testing/ and nextgen/vcs-versioning/testingB/ - Fix _own_version_helper.py to import from vcs_versioning Fix pytest configuration: - Move pytest_plugins from conftest.py to pyproject.toml addopts - Prevents 'non-top-level conftest' errors when running all tests from root - Both test suites now run successfully together (408 passed, 10 skipped, 1 xfailed)
1 parent 0afc5b9 commit d6fea05

26 files changed

+179
-149
lines changed

_own_version_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from collections.abc import Callable
1515

1616
from setuptools import build_meta as build_meta
17+
from vcs_versioning import _types as _t
1718

1819
from setuptools_scm import Configuration
19-
from setuptools_scm import _types as _t
2020
from setuptools_scm import get_version
2121
from setuptools_scm import git
2222
from setuptools_scm import hg

nextgen/vcs-versioning/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ exclude_lines = [
101101
[tool.pytest.ini_options]
102102
testpaths = ["testingB"]
103103
python_files = ["test_*.py"]
104-
addopts = ["-ra", "--strict-markers"]
104+
addopts = ["-ra", "--strict-markers", "-p", "vcs_versioning.test_api"]
105105
markers = [
106106
"issue: marks tests related to specific issues",
107107
]

src/setuptools_scm/_integration/dump_version.py renamed to nextgen/vcs-versioning/src/vcs_versioning/_dump_version.py

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
"""Core functionality for writing version information to files."""
2+
13
from __future__ import annotations
24

35
import logging
46
import warnings
57

68
from pathlib import Path
9+
from typing import TYPE_CHECKING
10+
11+
from ._version_cls import _version_as_tuple
712

8-
from .. import _types as _t
9-
from .._version_cls import _version_as_tuple
10-
from ..version import ScmVersion
13+
if TYPE_CHECKING:
14+
from . import _types as _t
15+
from ._version_schemes import ScmVersion
1116

1217
log = logging.getLogger(__name__)
1318

1419

15-
TEMPLATES = {
20+
DEFAULT_TEMPLATES = {
1621
".py": """\
17-
# file generated by setuptools-scm
22+
# file generated by vcs-versioning
1823
# don't change, don't track in version control
1924
2025
__all__ = [
@@ -53,38 +58,32 @@
5358
}
5459

5560

56-
def dump_version(
57-
root: _t.PathT,
58-
version: str,
59-
write_to: _t.PathT,
60-
template: str | None = None,
61-
scm_version: ScmVersion | None = None,
62-
) -> None:
63-
assert isinstance(version, str)
64-
root = Path(root)
65-
write_to = Path(write_to)
66-
if write_to.is_absolute():
67-
# trigger warning on escape
68-
write_to.relative_to(root)
69-
warnings.warn(
70-
f"{write_to=!s} is a absolute path,"
71-
" please switch to using a relative version file",
72-
DeprecationWarning,
73-
)
74-
target = write_to
75-
else:
76-
target = Path(root).joinpath(write_to)
77-
write_version_to_path(
78-
target, template=template, version=version, scm_version=scm_version
79-
)
61+
class DummyScmVersion:
62+
"""Placeholder for when no ScmVersion is available."""
63+
64+
@property
65+
def short_node(self) -> str | None:
66+
return None
8067

8168

8269
def _validate_template(target: Path, template: str | None) -> str:
70+
"""Validate and return the template to use for writing the version file.
71+
72+
Args:
73+
target: The target file path
74+
template: User-provided template or None to use default
75+
76+
Returns:
77+
The template string to use
78+
79+
Raises:
80+
ValueError: If no suitable template is found
81+
"""
8382
if template == "":
8483
warnings.warn(f"{template=} looks like a error, using default instead")
8584
template = None
8685
if template is None:
87-
template = TEMPLATES.get(target.suffix)
86+
template = DEFAULT_TEMPLATES.get(target.suffix)
8887

8988
if template is None:
9089
raise ValueError(
@@ -95,18 +94,20 @@ def _validate_template(target: Path, template: str | None) -> str:
9594
return template
9695

9796

98-
class DummyScmVersion:
99-
@property
100-
def short_node(self) -> str | None:
101-
return None
102-
103-
10497
def write_version_to_path(
10598
target: Path,
10699
template: str | None,
107100
version: str,
108101
scm_version: ScmVersion | None = None,
109102
) -> None:
103+
"""Write version information to a file using a template.
104+
105+
Args:
106+
target: The target file path to write to
107+
template: Template string or None to use default based on file extension
108+
version: The version string to write
109+
scm_version: Optional ScmVersion object for additional metadata
110+
"""
110111
final_template = _validate_template(target, template)
111112
log.debug("dump %s into %s", version, target)
112113
version_tuple = _version_as_tuple(version)
@@ -126,3 +127,38 @@ def write_version_to_path(
126127
)
127128

128129
target.write_text(content, encoding="utf-8")
130+
131+
132+
def dump_version(
133+
root: _t.PathT,
134+
version: str,
135+
write_to: _t.PathT,
136+
template: str | None = None,
137+
scm_version: ScmVersion | None = None,
138+
) -> None:
139+
"""Write version information to a file relative to root.
140+
141+
Args:
142+
root: The root directory (project root)
143+
version: The version string to write
144+
write_to: The target file path (relative to root or absolute)
145+
template: Template string or None to use default
146+
scm_version: Optional ScmVersion object for additional metadata
147+
"""
148+
assert isinstance(version, str)
149+
root = Path(root)
150+
write_to = Path(write_to)
151+
if write_to.is_absolute():
152+
# trigger warning on escape
153+
write_to.relative_to(root)
154+
warnings.warn(
155+
f"{write_to=!s} is a absolute path,"
156+
" please switch to using a relative version file",
157+
DeprecationWarning,
158+
)
159+
target = write_to
160+
else:
161+
target = Path(root).joinpath(write_to)
162+
write_version_to_path(
163+
target, template=template, version=version, scm_version=scm_version
164+
)

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,17 @@ def write_version_files(
7474
config: Configuration, version: str, scm_version: ScmVersion
7575
) -> None:
7676
if config.write_to is not None:
77-
try:
78-
# dump_version is setuptools-specific, may not be available
79-
from setuptools_scm._integration.dump_version import dump_version
80-
except ImportError:
81-
warnings.warn("write_to requires setuptools_scm package", stacklevel=2)
82-
else:
83-
dump_version(
84-
root=config.root,
85-
version=version,
86-
scm_version=scm_version,
87-
write_to=config.write_to,
88-
template=config.write_to_template,
89-
)
77+
from ._dump_version import dump_version
78+
79+
dump_version(
80+
root=config.root,
81+
version=version,
82+
scm_version=scm_version,
83+
write_to=config.write_to,
84+
template=config.write_to_template,
85+
)
9086
if config.version_file:
91-
try:
92-
from setuptools_scm._integration.dump_version import write_version_to_path
93-
except ImportError:
94-
warnings.warn("version_file requires setuptools_scm package", stacklevel=2)
95-
return
87+
from ._dump_version import write_version_to_path
9688

9789
version_file = Path(config.version_file)
9890
assert not version_file.is_absolute(), f"{version_file=}"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Core version inference functionality for build tool integrations."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
from typing import Any
7+
8+
if TYPE_CHECKING:
9+
from ._pyproject_reading import PyProjectData
10+
11+
12+
def infer_version_string(
13+
dist_name: str | None,
14+
pyproject_data: PyProjectData,
15+
overrides: dict[str, Any] | None = None,
16+
*,
17+
force_write_version_files: bool = False,
18+
) -> str:
19+
"""
20+
Compute the inferred version string from the given inputs.
21+
22+
This is a pure helper that avoids requiring build-tool specific
23+
distribution objects, making it easier to test and reuse across
24+
different build systems.
25+
26+
Parameters:
27+
dist_name: Optional distribution name (used for overrides and env scoping)
28+
pyproject_data: Parsed PyProjectData (may be constructed via for_testing())
29+
overrides: Optional override configuration (same keys as [tool.setuptools_scm])
30+
force_write_version_files: When True, apply write_to/version_file effects
31+
32+
Returns:
33+
The computed version string.
34+
35+
Raises:
36+
SystemExit: If version cannot be determined (via _version_missing)
37+
"""
38+
from ._get_version_impl import _get_version
39+
from ._get_version_impl import _version_missing
40+
from .config import Configuration
41+
42+
config = Configuration.from_file(
43+
dist_name=dist_name, pyproject_data=pyproject_data, **(overrides or {})
44+
)
45+
46+
maybe_version = _get_version(
47+
config, force_write_version_files=force_write_version_files
48+
)
49+
if maybe_version is None:
50+
_version_missing(config)
51+
return maybe_version
52+
53+
54+
__all__ = ["infer_version_string"]

nextgen/vcs-versioning/testingB/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
from __future__ import annotations
77

88
# Use our own test_api module as a pytest plugin
9-
pytest_plugins = ["vcs_versioning.test_api"]
9+
# Moved to pyproject.toml addopts to avoid non-top-level conftest issues
10+
# pytest_plugins = ["vcs_versioning.test_api"]

nextgen/vcs-versioning/testingB/test_hg_git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import pytest
44

5+
from vcs_versioning._run_cmd import CommandNotFoundError
6+
from vcs_versioning._run_cmd import has_command
7+
from vcs_versioning._run_cmd import run
58
from vcs_versioning.test_api import WorkDir
69

710
from setuptools_scm import Configuration
8-
from setuptools_scm._run_cmd import CommandNotFoundError
9-
from setuptools_scm._run_cmd import has_command
10-
from setuptools_scm._run_cmd import run
1111
from setuptools_scm.hg import parse
1212

1313

nextgen/vcs-versioning/testingB/test_mercurial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import pytest
88

9+
from vcs_versioning._run_cmd import CommandNotFoundError
910
from vcs_versioning.test_api import WorkDir
1011

1112
import setuptools_scm._file_finders
1213

1314
from setuptools_scm import Configuration
14-
from setuptools_scm._run_cmd import CommandNotFoundError
1515
from setuptools_scm.hg import archival_to_version
1616
from setuptools_scm.hg import parse
1717
from setuptools_scm.version import format_version

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ignore = ["PP305", "GH103", "GH212", "MY100", "PC111", "PC160", "PC170", "PC180"
136136
[tool.pytest.ini_options]
137137
minversion = "8"
138138
testpaths = ["testing"]
139+
addopts = ["-ra", "--strict-config", "--strict-markers", "-p", "vcs_versioning.test_api"]
139140
timeout = 300 # 5 minutes timeout per test for CI protection
140141
filterwarnings = [
141142
"error",
@@ -145,7 +146,6 @@ filterwarnings = [
145146
log_level = "debug"
146147
log_cli_level = "info"
147148
# disable unraisable until investigated
148-
addopts = ["-ra", "--strict-config", "--strict-markers"]
149149
markers = [
150150
"issue(id): reference to github issue",
151151
"skip_commit: allows to skip committing in the helpers",

src/setuptools_scm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
from __future__ import annotations
77

8+
from vcs_versioning._dump_version import dump_version # soft deprecated
9+
810
from ._config import DEFAULT_LOCAL_SCHEME
911
from ._config import DEFAULT_VERSION_SCHEME
1012
from ._config import Configuration
1113
from ._get_version_impl import _get_version
1214
from ._get_version_impl import get_version
13-
from ._integration.dump_version import dump_version # soft deprecated
1415
from ._version_cls import NonNormalizedVersion
1516
from ._version_cls import Version
1617
from .version import ScmVersion

0 commit comments

Comments
 (0)