From f8bf8bf50d174882208be5e8ec090316481612c3 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 4 May 2022 10:14:38 +0100 Subject: [PATCH 1/3] Capture expectations about overwritten dependencies in test This is discussed in issue 3300. --- setuptools/tests/config/test_apply_pyprojecttoml.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py index 045d7f40b6..acb07f10f4 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". From 8acf300c23e0f067c18ae4e47981491d37cda92e Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 4 May 2022 10:15:52 +0100 Subject: [PATCH 2/3] Add warning about overwritten dependencies --- setuptools/config/_apply_pyprojecttoml.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setuptools/config/_apply_pyprojecttoml.py b/setuptools/config/_apply_pyprojecttoml.py index fce5c40e34..40d56513c0 100644 --- a/setuptools/config/_apply_pyprojecttoml.py +++ b/setuptools/config/_apply_pyprojecttoml.py @@ -195,8 +195,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): From 583cb93dfe38151b17e152e961da5643ca4d49d3 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 4 May 2022 10:34:24 +0100 Subject: [PATCH 3/3] Add news fragment --- changelog.d/3206.change.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/3206.change.rst 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.