9
9
10
10
import setuptools
11
11
12
+ from .. import _types as _t
12
13
from .pyproject_reading import PyProjectData
13
14
from .pyproject_reading import read_pyproject
14
15
from .setup_cfg import _dist_name_from_legacy
@@ -68,7 +69,7 @@ def version_keyword(
68
69
keyword : str ,
69
70
value : bool | dict [str , Any ] | Callable [[], dict [str , Any ]],
70
71
* ,
71
- _given_pyproject_data : PyProjectData | None = None ,
72
+ _given_pyproject_data : _t . GivenPyProjectResult = None ,
72
73
) -> None :
73
74
"""apply version infernce when setup(use_scm_version=...) is used
74
75
this takes priority over the finalize_options based version
@@ -87,20 +88,15 @@ def version_keyword(
87
88
88
89
was_set_by_infer = getattr (dist , "_setuptools_scm_version_set_by_infer" , False )
89
90
90
- # Get pyproject data
91
- if _given_pyproject_data is not None :
92
- pyproject_data = _given_pyproject_data
93
- else :
94
- try :
95
- pyproject_data = read_pyproject ()
96
- except FileNotFoundError :
97
- log .debug ("pyproject.toml not found, proceeding with empty configuration" )
98
- pyproject_data = PyProjectData .empty (
99
- Path ("pyproject.toml" ), "setuptools_scm"
100
- )
101
- except InvalidTomlError as e :
102
- log .debug ("Configuration issue in pyproject.toml: %s" , e )
103
- return
91
+ # Get pyproject data (support direct injection for tests)
92
+ try :
93
+ pyproject_data = read_pyproject (_given_result = _given_pyproject_data )
94
+ except FileNotFoundError :
95
+ log .debug ("pyproject.toml not found, proceeding with empty configuration" )
96
+ pyproject_data = PyProjectData .empty (Path ("pyproject.toml" ), "setuptools_scm" )
97
+ except InvalidTomlError as e :
98
+ log .debug ("Configuration issue in pyproject.toml: %s" , e )
99
+ return
104
100
105
101
result = get_version_inference_config (
106
102
dist_name = dist_name ,
@@ -114,7 +110,9 @@ def version_keyword(
114
110
115
111
116
112
def infer_version (
117
- dist : setuptools .Distribution , * , _given_pyproject_data : PyProjectData | None = None
113
+ dist : setuptools .Distribution ,
114
+ * ,
115
+ _given_pyproject_data : _t .GivenPyProjectResult = None ,
118
116
) -> None :
119
117
"""apply version inference from the finalize_options hook
120
118
this is the default for pyproject.toml based projects that don't use the use_scm_version keyword
@@ -127,17 +125,14 @@ def infer_version(
127
125
128
126
dist_name = _dist_name_from_legacy (dist )
129
127
130
- if _given_pyproject_data is not None :
131
- pyproject_data = _given_pyproject_data
132
- else :
133
- try :
134
- pyproject_data = read_pyproject ()
135
- except FileNotFoundError :
136
- log .debug ("pyproject.toml not found, skipping infer_version" )
137
- return
138
- except InvalidTomlError as e :
139
- log .debug ("Configuration issue in pyproject.toml: %s" , e )
140
- return
128
+ try :
129
+ pyproject_data = read_pyproject (_given_result = _given_pyproject_data )
130
+ except FileNotFoundError :
131
+ log .debug ("pyproject.toml not found, skipping infer_version" )
132
+ return
133
+ except InvalidTomlError as e :
134
+ log .debug ("Configuration issue in pyproject.toml: %s" , e )
135
+ return
141
136
142
137
result = get_version_inference_config (
143
138
dist_name = dist_name ,
0 commit comments