Skip to content

Commit

Permalink
Complain about (gui-)scripts that are not listed in pyproject.toml's …
Browse files Browse the repository at this point in the history
…dynamic (#4012)
  • Loading branch information
abravalheri committed Aug 15, 2023
2 parents db4036a + cf34858 commit ab4ab87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions newsfragments/4012.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Detects (and complain about) ``scripts`` and ``gui-scripts`` set via ``setup.py``
when ``pyproject.toml`` does not include them in ``dynamic``.
12 changes: 12 additions & 0 deletions setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ def _get_previous_entrypoints(dist: "Distribution") -> Dict[str, list]:
return {k: v for k, v in value.items() if k not in ignore}


def _get_previous_scripts(dist: "Distribution") -> Optional[list]:
value = getattr(dist, "entry_points", None) or {}
return value.get("console_scripts")


def _get_previous_gui_scripts(dist: "Distribution") -> Optional[list]:
value = getattr(dist, "entry_points", None) or {}
return value.get("gui_scripts")


def _attrgetter(attr):
"""
Similar to ``operator.attrgetter`` but returns None if ``attr`` is not found
Expand Down Expand Up @@ -371,6 +381,8 @@ def _acessor(obj):
"classifiers": _attrgetter("metadata.classifiers"),
"urls": _attrgetter("metadata.project_urls"),
"entry-points": _get_previous_entrypoints,
"scripts": _get_previous_scripts,
"gui-scripts": _get_previous_gui_scripts,
"dependencies": _some_attrgetter("_orig_install_requires", "install_requires"),
"optional-dependencies": _some_attrgetter("_orig_extras_require", "extras_require"),
}
Expand Down
2 changes: 2 additions & 0 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ def pyproject(self, tmp_path, dynamic, extra_content=""):
[
("install_requires", "dependencies", ["six"]),
("classifiers", "classifiers", ["Private :: Classifier"]),
("entry_points", "scripts", {"console_scripts": ["foobar=foobar:main"]}),
("entry_points", "gui-scripts", {"gui_scripts": ["bazquux=bazquux:main"]}),
],
)
def test_not_listed_in_dynamic(self, tmp_path, attr, field, value):
Expand Down

0 comments on commit ab4ab87

Please sign in to comment.