Skip to content

Commit 47ec4ab

Browse files
Fix issue #1022: version_keyword should override infer_version when config differs
When infer_version sets a version first, version_keyword should be able to override it if it brings additional configuration (like a different version_scheme). This commit implements a marker system: - infer_version sets _setuptools_scm_version_set_by_infer=True when it sets a version - version_keyword checks this marker and: - If no overrides: uses infer_version result (no warning) - If overrides present: clears version and recalculates with new config - If version set by other means: warns as before This allows proper integration behavior where version_keyword can override infer_version when the user provides specific configuration like calver schemes.
1 parent 63be5d4 commit 47ec4ab

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- add `scm` parameter support to `get_version()` function for nested SCM configuration
1212
- fix #987: expand documentation on git archival files and add cli tools for good defaults
1313
- fix #311: document github/gitlab ci pipelines that enable auto-upload to test-pypi/pypi
14+
- fix #1022: allow `version_keyword` to override `infer_version` when configuration differs
1415

1516

1617
### Changed

src/setuptools_scm/_integration/setuptools.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,21 @@ def version_keyword(
108108
_log_hookstart("version_keyword", dist)
109109

110110
if dist.metadata.version is not None:
111-
warnings.warn(f"version of {dist_name} already set")
112-
return
111+
# Check if version was set by infer_version
112+
was_set_by_infer = getattr(dist, "_setuptools_scm_version_set_by_infer", False)
113+
114+
if was_set_by_infer:
115+
# Version was set by infer_version, check if we have overrides
116+
if not overrides:
117+
# No overrides, just use the infer_version result
118+
return
119+
# We have overrides, clear the marker and proceed to override the version
120+
dist._setuptools_scm_version_set_by_infer = False # type: ignore[attr-defined]
121+
dist.metadata.version = None
122+
else:
123+
# Version was set by something else, warn and return
124+
warnings.warn(f"version of {dist_name} already set")
125+
return
113126

114127
if dist_name is None:
115128
dist_name = read_dist_name_from_setup_cfg()
@@ -141,3 +154,5 @@ def infer_version(dist: setuptools.Distribution) -> None:
141154
log.info(e, exc_info=True)
142155
else:
143156
_assign_version(dist, config)
157+
# Mark that this version was set by infer_version
158+
dist._setuptools_scm_version_set_by_infer = True # type: ignore[attr-defined]

0 commit comments

Comments
 (0)