Skip to content

Commit

Permalink
Fix warnings for scripts/gui_scripts with pyproject.toml (#3865)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Mar 28, 2023
2 parents be6c021 + 16ee218 commit 520aa14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/3865.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed ``_WouldIgnoreField`` warnings for ``scripts`` and ``gui_scripts``,
when ``entry-points`` is not listed in dynamic.
8 changes: 7 additions & 1 deletion setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def _normalise_cmd_options(desc: List[Tuple[str, Optional[str], str]]) -> Set[st
return {_normalise_cmd_option_key(fancy_option[0]) for fancy_option in desc}


def _get_previous_entrypoints(dist: "Distribution") -> Dict[str, list]:
ignore = ("console_scripts", "gui_scripts")
value = getattr(dist, "entry_points", None) or {}
return {k: v for k, v in value.items() if k not in ignore}


def _attrgetter(attr):
"""
Similar to ``operator.attrgetter`` but returns None if ``attr`` is not found
Expand Down Expand Up @@ -343,7 +349,7 @@ def _acessor(obj):
"keywords": _attrgetter("metadata.keywords"),
"classifiers": _attrgetter("metadata.classifiers"),
"urls": _attrgetter("metadata.project_urls"),
"entry-points": _attrgetter("entry_points"),
"entry-points": _get_previous_entrypoints,
"dependencies": _some_attrgetter("_orig_install_requires", "install_requires"),
"optional-dependencies": _some_attrgetter("_orig_extras_require", "extras_require"),
}
Expand Down
12 changes: 12 additions & 0 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):
assert "importlib-resources" in reqs
assert "bar" in reqs

@pytest.mark.parametrize(
"field,group",
[("scripts", "console_scripts"), ("gui-scripts", "gui_scripts")]
)
@pytest.mark.filterwarnings("error")
def test_scripts_dont_require_dynamic_entry_points(self, tmp_path, field, group):
# Issue 3862
pyproject = self.pyproject(tmp_path, [field])
dist = makedist(tmp_path, entry_points={group: ["foobar=foobar:main"]})
dist = pyprojecttoml.apply_configuration(dist, pyproject)
assert group in dist.entry_points


class TestMeta:
def test_example_file_in_sdist(self, setuptools_sdist):
Expand Down

0 comments on commit 520aa14

Please sign in to comment.