From 8481ab4420b4b980d76382589254aa8054085b80 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 20 Aug 2024 13:08:54 -0400 Subject: [PATCH] Remove extracted changes --- newsfragments/4575.bugfix.rst | 1 - newsfragments/4575.feature.rst | 1 - setuptools/command/egg_info.py | 15 ++++-------- setuptools/dist.py | 42 +++++++++++----------------------- setuptools/tests/test_dist.py | 8 +++---- 5 files changed, 21 insertions(+), 46 deletions(-) delete mode 100644 newsfragments/4575.bugfix.rst diff --git a/newsfragments/4575.bugfix.rst b/newsfragments/4575.bugfix.rst deleted file mode 100644 index e9bde46269..0000000000 --- a/newsfragments/4575.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix a `TypeError` when a ``Distribution``'s old included attribute was a `tuple` -- by :user:`Avasam` diff --git a/newsfragments/4575.feature.rst b/newsfragments/4575.feature.rst index 45a12cf60b..0894c7dcfa 100644 --- a/newsfragments/4575.feature.rst +++ b/newsfragments/4575.feature.rst @@ -1,2 +1 @@ Allows using `dict` as an ordered type in ``setuptools.dist.check_requirements`` -- by :user:`Avasam` -Be more explicit about the expected type when parsing ``Distribution`` data -- by :user:`Avasam` diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 8991805656..f9410d8fd1 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -211,17 +211,10 @@ def save_version_info(self, filename): build tag. Install build keys in a deterministic order to avoid arbitrary reordering on subsequent builds. """ - edit_config( - filename, - dict( - egg_info=dict( - # follow the order these keys would have been added - # when PYTHONHASHSEED=0 - tag_build=self.tags(), - tag_date=0, - ) - ), - ) + # follow the order these keys would have been added + # when PYTHONHASHSEED=0 + egg_info = dict(tag_build=self.tags(), tag_date=0) + edit_config(filename, dict(egg_info=egg_info)) def finalize_options(self): # Note: we need to capture the current value returned diff --git a/setuptools/dist.py b/setuptools/dist.py index dc9b6fad37..a9626f6a98 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -8,7 +8,7 @@ import sys from glob import iglob from pathlib import Path -from typing import TYPE_CHECKING, List, MutableMapping, NoReturn, Tuple, Union, overload +from typing import TYPE_CHECKING, MutableMapping, NoReturn, overload from more_itertools import partition, unique_everseen from packaging.markers import InvalidMarker, Marker @@ -37,23 +37,9 @@ from distutils.fancy_getopt import translate_longopt from distutils.util import strtobool -if TYPE_CHECKING: - from typing_extensions import TypeAlias - __all__ = ['Distribution'] sequence = tuple, list -""" -Supported iterable types that are known to be: -- ordered (which `set` isn't) -- not match a str (which `Sequence[str]` does) -- not imply a nested type (like `dict`) - -for use with `isinstance`. -""" -_Sequence: TypeAlias = Union[Tuple[str, ...], List[str]] -# This is how stringifying _Sequence would look in Python 3.10 -_requence_type_repr = "tuple[str, ...] | list[str]" def check_importable(dist, attr, value): @@ -66,7 +52,7 @@ def check_importable(dist, attr, value): ) from e -def assert_string_list(dist, attr: str, value: _Sequence): +def assert_string_list(dist, attr, value): """Verify that value is a string list""" try: # verify that value is a list or tuple to exclude unordered @@ -76,7 +62,7 @@ def assert_string_list(dist, attr: str, value: _Sequence): assert ''.join(value) != value except (TypeError, ValueError, AttributeError, AssertionError) as e: raise DistutilsSetupError( - f"{attr!r} must be of type <{_requence_type_repr}> (got {value!r})" + "%r must be a list of strings (got %r)" % (attr, value) ) from e @@ -165,10 +151,10 @@ def check_requirements(dist, attr: str, value: _StrOrIter) -> None: raise TypeError("Unordered types are not allowed") except (TypeError, ValueError) as error: tmpl = ( - f"{attr!r} must be a string or iterable of strings " - f"containing valid project/version requirement specifiers; {error}" + "{attr!r} must be a string or list of strings " + "containing valid project/version requirement specifiers; {error}" ) - raise DistutilsSetupError(tmpl) from error + raise DistutilsSetupError(tmpl.format(attr=attr, error=error)) from error def check_specifier(dist, attr, value): @@ -784,11 +770,11 @@ def has_contents_for(self, package): return False - def _exclude_misc(self, name: str, value: _Sequence): + def _exclude_misc(self, name, value): """Handle 'exclude()' for list/tuple attrs without a special handler""" if not isinstance(value, sequence): raise DistutilsSetupError( - f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})" + "%s: setting must be a list or tuple (%r)" % (name, value) ) try: old = getattr(self, name) @@ -801,13 +787,11 @@ def _exclude_misc(self, name: str, value: _Sequence): elif old: setattr(self, name, [item for item in old if item not in value]) - def _include_misc(self, name: str, value: _Sequence): + def _include_misc(self, name, value): """Handle 'include()' for list/tuple attrs without a special handler""" if not isinstance(value, sequence): - raise DistutilsSetupError( - f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})" - ) + raise DistutilsSetupError("%s: setting must be a list (%r)" % (name, value)) try: old = getattr(self, name) except AttributeError as e: @@ -820,7 +804,7 @@ def _include_misc(self, name: str, value: _Sequence): ) else: new = [item for item in value if item not in old] - setattr(self, name, list(old) + new) + setattr(self, name, old + new) def exclude(self, **attrs): """Remove items from distribution that are named in keyword arguments @@ -845,10 +829,10 @@ def exclude(self, **attrs): else: self._exclude_misc(k, v) - def _exclude_packages(self, packages: _Sequence): + def _exclude_packages(self, packages): if not isinstance(packages, sequence): raise DistutilsSetupError( - f"packages: setting must be of type <{_requence_type_repr}> (got {packages!r})" + "packages: setting must be a list or tuple (%r)" % (packages,) ) list(map(self.exclude_package, packages)) diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 62a78c6a02..c9672a7282 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -117,8 +117,8 @@ def test_provides_extras_deterministic_order(): 'hello': '*.msg', }, ( - "\"values of 'package_data' dict\" must be of type " - " (got '*.msg')" + "\"values of 'package_data' dict\" " + "must be a list of strings (got '*.msg')" ), ), # Invalid value type (generators are single use) @@ -127,8 +127,8 @@ def test_provides_extras_deterministic_order(): 'hello': (x for x in "generator"), }, ( - "\"values of 'package_data' dict\" must be of type " - " (got