Skip to content

Emit warning for invalid [tools.setuptools] table #4151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4150.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Emit a warning when ``[tools.setuptools]`` is present in ``pyproject.toml`` and will be ignored. -- by :user:`SnoopJ`
10 changes: 10 additions & 0 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def read_configuration(
if not asdict or not (project_table or setuptools_table):
return {} # User is not using pyproject to configure setuptools

if "setuptools" in asdict.get("tools", {}):
# let the user know they probably have a typo in their metadata
_ToolsTypoInMetadata.emit()

if "distutils" in tool_table:
_ExperimentalConfiguration.emit(subject="[tool.distutils]")

Expand Down Expand Up @@ -439,3 +443,9 @@ class _ExperimentalConfiguration(SetuptoolsWarning):
"`{subject}` in `pyproject.toml` is still *experimental* "
"and likely to change in future releases."
)


class _ToolsTypoInMetadata(SetuptoolsWarning):
_SUMMARY = (
"Ignoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?"
)
26 changes: 26 additions & 0 deletions setuptools/tests/config/test_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from path import Path

from setuptools.config.pyprojecttoml import (
_ToolsTypoInMetadata,
read_configuration,
expand_configuration,
apply_configuration,
Expand Down Expand Up @@ -369,3 +370,28 @@ def test_include_package_data_in_setuppy(tmp_path):
assert dist.get_name() == "myproj"
assert dist.get_version() == "42"
assert dist.include_package_data is False


def test_warn_tools_typo(tmp_path):
"""Test that the common ``tools.setuptools`` typo in ``pyproject.toml`` issues a warning

See https://github.com/pypa/setuptools/issues/4150
"""
config = """
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "myproj"
version = '42'

[tools.setuptools]
packages = ["package"]
"""

pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(cleandoc(config), encoding="utf-8")

with pytest.warns(_ToolsTypoInMetadata):
read_configuration(pyproject)
13 changes: 10 additions & 3 deletions setuptools/tests/test_build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class TestTypeInfoFiles:
name = "foo"
version = "1"

[tools.setuptools]
[tool.setuptools]
include-package-data = false
"""
),
Expand All @@ -359,7 +359,7 @@ class TestTypeInfoFiles:
name = "foo"
version = "1"

[tools.setuptools]
[tool.setuptools]
include-package-data = false

[tool.setuptools.exclude-package-data]
Expand Down Expand Up @@ -409,7 +409,14 @@ class TestTypeInfoFiles:
}

@pytest.mark.parametrize(
"pyproject", ["default_pyproject", "dont_include_package_data"]
"pyproject",
[
"default_pyproject",
pytest.param(
"dont_include_package_data",
marks=pytest.mark.xfail(reason="pypa/setuptools#4350"),
),
],
)
@pytest.mark.parametrize("example", EXAMPLES.keys())
def test_type_files_included_by_default(self, tmpdir_cwd, pyproject, example):
Expand Down