Skip to content

Commit ff20cbb

Browse files
add a warning when setuptools dynamic version in pyproject is used in error
1 parent e67c027 commit ff20cbb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ def read_pyproject(
228228
requires,
229229
)
230230

231+
setuptools_dynamic_version = (
232+
defn.get("tool", {})
233+
.get("setuptools", {})
234+
.get("dynamic", {})
235+
.get("version", None)
236+
)
237+
if setuptools_dynamic_version is not None:
238+
warnings.warn(
239+
f"{path}: at [tool.setuptools.dynamic]\n"
240+
"version = {attr = ...} is sabotaging setuptools-scm"
241+
)
242+
section["version"] = None
243+
231244
return pyproject_data
232245

233246

testing/test_pyproject_reading.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,23 @@ def test_read_pyproject_with_given_definition(monkeypatch: pytest.MonkeyPatch) -
126126
)
127127

128128
assert res.should_infer()
129+
130+
131+
def test_read_pyproject_with_setuptools_dynamic_version_warns() -> None:
132+
with pytest.warns(
133+
UserWarning,
134+
match=r"pyproject.toml: at \[tool\.setuptools\.dynamic\]\n"
135+
r"version = {attr = \.\.\.} is sabotaging setuptools-scm",
136+
):
137+
pyproject_data = read_pyproject(
138+
_given_definition={
139+
"build-system": {"requires": ["setuptools-scm[simple]"]},
140+
"project": {"name": "test-package", "dynamic": ["version"]},
141+
"tool": {
142+
"setuptools": {
143+
"dynamic": {"version": {"attr": "test_package.__version__"}}
144+
}
145+
},
146+
}
147+
)
148+
assert pyproject_data.project_version is None

0 commit comments

Comments
 (0)