Skip to content

Commit

Permalink
Remove residual dependencies from setup.py when dependencies are set …
Browse files Browse the repository at this point in the history
…in pyproject.toml (#3306)
  • Loading branch information
abravalheri committed May 16, 2022
2 parents fd072dc + 583cb93 commit aec2215
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions 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.
6 changes: 4 additions & 2 deletions setuptools/config/_apply_pyprojecttoml.py
Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Expand Up @@ -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".
Expand Down

0 comments on commit aec2215

Please sign in to comment.