@@ -25,22 +25,13 @@ class VersionInferenceConfig:
25
25
26
26
def apply (self , dist : Distribution ) -> None :
27
27
"""Apply version inference to the distribution."""
28
- from .. import _config as _config_module
29
- from .._get_version_impl import _get_version
30
- from .._get_version_impl import _version_missing
31
-
32
- config = _config_module .Configuration .from_file (
33
- dist_name = self .dist_name ,
34
- pyproject_data = self .pyproject_data ,
35
- ** (self .overrides or {}),
28
+ version_string = infer_version_string (
29
+ self .dist_name ,
30
+ self .pyproject_data , # type: ignore[arg-type]
31
+ self .overrides ,
32
+ force_write_version_files = True ,
36
33
)
37
-
38
- # Get and assign version
39
- maybe_version = _get_version (config , force_write_version_files = True )
40
- if maybe_version is None :
41
- _version_missing (config )
42
- else :
43
- dist .metadata .version = maybe_version
34
+ dist .metadata .version = version_string
44
35
45
36
# Mark that this version was set by infer_version if overrides is None (infer_version context)
46
37
if self .overrides is None :
@@ -75,6 +66,43 @@ def apply(self, dist: Distribution) -> None:
75
66
]
76
67
77
68
69
+ def infer_version_string (
70
+ dist_name : str | None ,
71
+ pyproject_data : PyProjectData ,
72
+ overrides : dict [str , Any ] | None = None ,
73
+ * ,
74
+ force_write_version_files : bool = False ,
75
+ ) -> str :
76
+ """
77
+ Compute the inferred version string from the given inputs without requiring a
78
+ setuptools Distribution instance. This is a pure helper that simplifies
79
+ integration tests by avoiding file I/O and side effects on a Distribution.
80
+
81
+ Parameters:
82
+ dist_name: Optional distribution name (used for overrides and env scoping)
83
+ pyproject_data: Parsed PyProjectData (may be constructed via for_testing())
84
+ overrides: Optional override configuration (same keys as [tool.setuptools_scm])
85
+ force_write_version_files: When True, apply write_to/version_file effects
86
+
87
+ Returns:
88
+ The computed version string.
89
+ """
90
+ from .. import _config as _config_module
91
+ from .._get_version_impl import _get_version
92
+ from .._get_version_impl import _version_missing
93
+
94
+ config = _config_module .Configuration .from_file (
95
+ dist_name = dist_name , pyproject_data = pyproject_data , ** (overrides or {})
96
+ )
97
+
98
+ maybe_version = _get_version (
99
+ config , force_write_version_files = force_write_version_files
100
+ )
101
+ if maybe_version is None :
102
+ _version_missing (config )
103
+ return maybe_version
104
+
105
+
78
106
def get_version_inference_config (
79
107
dist_name : str | None ,
80
108
current_version : str | None ,
0 commit comments