diff --git a/changelog.d/3206.change.rst b/changelog.d/3206.change.rst new file mode 100644 index 0000000000..f4d8683942 --- /dev/null +++ b/changelog.d/3206.change.rst @@ -0,0 +1,4 @@ +Fixed behaviour when both ``install_requires`` (in ``setup.py``) and +``dependencies`` (in ``pyproject.toml``) are specified. +The configuration in ``pyproject.toml`` will take precedence over ``setup.py`` +(in accordance with PEP 621). A warning was added to inform users. diff --git a/setuptools/config/_apply_pyprojecttoml.py b/setuptools/config/_apply_pyprojecttoml.py index a580b63f6f..002cc4b809 100644 --- a/setuptools/config/_apply_pyprojecttoml.py +++ b/setuptools/config/_apply_pyprojecttoml.py @@ -181,8 +181,10 @@ def _python_requires(dist: "Distribution", val: dict, _root_dir): def _dependencies(dist: "Distribution", val: list, _root_dir): - existing = getattr(dist, "install_requires", []) - _set_config(dist, "install_requires", existing + val) + if getattr(dist, "install_requires", []): + msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)" + warnings.warn(msg) + _set_config(dist, "install_requires", val) def _optional_dependencies(dist: "Distribution", val: dict, _root_dir): diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py index 4f541697aa..28643f0caf 100644 --- a/setuptools/tests/config/test_apply_pyprojecttoml.py +++ b/setuptools/tests/config/test_apply_pyprojecttoml.py @@ -257,6 +257,15 @@ def test_listed_in_dynamic(self, tmp_path, attr, field, value): dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist) assert dist_value == value + def test_warning_overwritten_dependencies(self, tmp_path): + src = "[project]\nname='pkg'\nversion='0.1'\ndependencies=['click']\n" + pyproject = tmp_path / "pyproject.toml" + pyproject.write_text(src, encoding="utf-8") + dist = makedist(tmp_path, install_requires=["wheel"]) + with pytest.warns(match="`install_requires` overwritten"): + dist = pyprojecttoml.apply_configuration(dist, pyproject) + assert "wheel" not in dist.install_requires + def test_optional_dependencies_dont_remove_env_markers(self, tmp_path): """ Internally setuptools converts dependencies with markers to "extras".