Skip to content

Commit abe6580

Browse files
authored
Emit warning for invalid [tools.setuptools] table (#4151)
2 parents 75d21fe + 1cbafac commit abe6580

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

newsfragments/4150.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Emit a warning when ``[tools.setuptools]`` is present in ``pyproject.toml`` and will be ignored. -- by :user:`SnoopJ`

setuptools/config/pyprojecttoml.py

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def read_configuration(
108108
if not asdict or not (project_table or setuptools_table):
109109
return {} # User is not using pyproject to configure setuptools
110110

111+
if "setuptools" in asdict.get("tools", {}):
112+
# let the user know they probably have a typo in their metadata
113+
_ToolsTypoInMetadata.emit()
114+
111115
if "distutils" in tool_table:
112116
_ExperimentalConfiguration.emit(subject="[tool.distutils]")
113117

@@ -439,3 +443,9 @@ class _ExperimentalConfiguration(SetuptoolsWarning):
439443
"`{subject}` in `pyproject.toml` is still *experimental* "
440444
"and likely to change in future releases."
441445
)
446+
447+
448+
class _ToolsTypoInMetadata(SetuptoolsWarning):
449+
_SUMMARY = (
450+
"Ignoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?"
451+
)

setuptools/tests/config/test_pyprojecttoml.py

+26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from path import Path
99

1010
from setuptools.config.pyprojecttoml import (
11+
_ToolsTypoInMetadata,
1112
read_configuration,
1213
expand_configuration,
1314
apply_configuration,
@@ -369,3 +370,28 @@ def test_include_package_data_in_setuppy(tmp_path):
369370
assert dist.get_name() == "myproj"
370371
assert dist.get_version() == "42"
371372
assert dist.include_package_data is False
373+
374+
375+
def test_warn_tools_typo(tmp_path):
376+
"""Test that the common ``tools.setuptools`` typo in ``pyproject.toml`` issues a warning
377+
378+
See https://github.com/pypa/setuptools/issues/4150
379+
"""
380+
config = """
381+
[build-system]
382+
requires = ["setuptools"]
383+
build-backend = "setuptools.build_meta"
384+
385+
[project]
386+
name = "myproj"
387+
version = '42'
388+
389+
[tools.setuptools]
390+
packages = ["package"]
391+
"""
392+
393+
pyproject = tmp_path / "pyproject.toml"
394+
pyproject.write_text(cleandoc(config), encoding="utf-8")
395+
396+
with pytest.warns(_ToolsTypoInMetadata):
397+
read_configuration(pyproject)

setuptools/tests/test_build_py.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class TestTypeInfoFiles:
349349
name = "foo"
350350
version = "1"
351351
352-
[tools.setuptools]
352+
[tool.setuptools]
353353
include-package-data = false
354354
"""
355355
),
@@ -359,7 +359,7 @@ class TestTypeInfoFiles:
359359
name = "foo"
360360
version = "1"
361361
362-
[tools.setuptools]
362+
[tool.setuptools]
363363
include-package-data = false
364364
365365
[tool.setuptools.exclude-package-data]
@@ -409,7 +409,14 @@ class TestTypeInfoFiles:
409409
}
410410

411411
@pytest.mark.parametrize(
412-
"pyproject", ["default_pyproject", "dont_include_package_data"]
412+
"pyproject",
413+
[
414+
"default_pyproject",
415+
pytest.param(
416+
"dont_include_package_data",
417+
marks=pytest.mark.xfail(reason="pypa/setuptools#4350"),
418+
),
419+
],
413420
)
414421
@pytest.mark.parametrize("example", EXAMPLES.keys())
415422
def test_type_files_included_by_default(self, tmpdir_cwd, pyproject, example):

0 commit comments

Comments
 (0)