Skip to content

Commit 629f4f4

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

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/setuptools_scm/_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ def from_data(
310310
# Handle nested SCM configuration
311311

312312
scm_config = ScmConfiguration.from_data(scm_data)
313-
314313
return cls(
315314
relative_to=relative_to,
316315
version_cls=version_cls,

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ 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+
231243
return pyproject_data
232244

233245

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)