@@ -114,62 +114,49 @@ def get_version_inference_config(
114
114
Returns:
115
115
VersionInferenceResult with the decision and configuration
116
116
"""
117
+ # Normalize name from project metadata when not provided
117
118
if dist_name is None :
118
119
dist_name = pyproject_data .project_name
119
120
120
- # Handle version already set
121
+ # If a version is already present, decide based on context (infer_version vs version_keyword)
121
122
if current_version is not None :
122
- if was_set_by_infer :
123
- if overrides is not None and overrides :
124
- # Clear version and proceed with actual overrides (non-empty dict)
125
- return VersionInferenceConfig (
126
- dist_name = dist_name ,
127
- pyproject_data = pyproject_data ,
128
- overrides = overrides ,
129
- )
130
- else :
131
- # Keep existing version from infer_version (no overrides or empty overrides)
132
- # But allow re-inferring if this is another infer_version call
133
- if overrides is None :
134
- # This is another infer_version call, allow it to proceed
135
- return VersionInferenceConfig (
136
- dist_name = dist_name ,
137
- pyproject_data = pyproject_data ,
138
- overrides = overrides ,
139
- )
140
- else :
141
- # This is version_keyword with empty overrides, keep existing version
142
- return VersionInferenceNoOp ()
143
- else :
144
- # Version set by something else
123
+ # infer_version call (overrides is None) should be a no-op if version already exists
124
+ if overrides is None :
125
+ return VersionInferenceNoOp ()
126
+
127
+ if not was_set_by_infer :
145
128
return VersionInferenceError (
146
- f"version of { dist_name } already set" , should_warn = True
129
+ f"version of { dist_name } already set" ,
130
+ should_warn = pyproject_data .should_infer (),
147
131
)
148
132
149
- # Handle setuptools-scm package
133
+ # Version was set by infer_version previously
134
+ if overrides :
135
+ # Non-empty overrides from version_keyword → re-infer with overrides
136
+ return VersionInferenceConfig (
137
+ dist_name = dist_name , pyproject_data = pyproject_data , overrides = overrides
138
+ )
139
+ # Empty overrides dict from version_keyword → keep existing version
140
+ return VersionInferenceNoOp ()
141
+
142
+ # Do not infer a version for setuptools-scm itself
150
143
if dist_name == "setuptools-scm" :
151
144
return VersionInferenceNoOp ()
152
145
153
- # version_keyword (with overrides) always tries to infer
146
+ # version_keyword path: any overrides (empty or not) mean we should infer
154
147
if overrides is not None :
155
148
return VersionInferenceConfig (
156
- dist_name = dist_name ,
157
- pyproject_data = pyproject_data ,
158
- overrides = overrides ,
149
+ dist_name = dist_name , pyproject_data = pyproject_data , overrides = overrides
159
150
)
160
151
161
- # infer_version (no overrides) uses pyproject configuration to decide
152
+ # infer_version path: decide based on pyproject configuration only
162
153
try :
163
- should_proceed = pyproject_data .should_infer ()
154
+ if pyproject_data .should_infer ():
155
+ return VersionInferenceConfig (
156
+ dist_name = dist_name , pyproject_data = pyproject_data , overrides = None
157
+ )
164
158
except ValueError :
165
- # For infer_version, silently skip on configuration issues (auto-activation shouldn't error)
159
+ # Auto-activation should not error in infer_version context → skip silently
166
160
return VersionInferenceNoOp ()
167
161
168
- if should_proceed :
169
- return VersionInferenceConfig (
170
- dist_name = dist_name ,
171
- pyproject_data = pyproject_data ,
172
- overrides = overrides ,
173
- )
174
- else :
175
- return VersionInferenceNoOp ()
162
+ return VersionInferenceNoOp ()
0 commit comments