Skip to content

Commit

Permalink
Remove extracted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 20, 2024
1 parent 8563d7f commit 8481ab4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 46 deletions.
1 change: 0 additions & 1 deletion newsfragments/4575.bugfix.rst

This file was deleted.

1 change: 0 additions & 1 deletion newsfragments/4575.feature.rst
Original file line number Diff line number Diff line change
@@ -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`
15 changes: 4 additions & 11 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 13 additions & 29 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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))

Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def test_provides_extras_deterministic_order():
'hello': '*.msg',
},
(
"\"values of 'package_data' dict\" must be of type <tuple[str, ...] | list[str]>"
" (got '*.msg')"
"\"values of 'package_data' dict\" "
"must be a list of strings (got '*.msg')"
),
),
# Invalid value type (generators are single use)
Expand All @@ -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 <tuple[str, ...] | list[str]>"
" (got <generator object"
"\"values of 'package_data' dict\" must be a list of strings "
"(got <generator object"
),
),
)
Expand Down

0 comments on commit 8481ab4

Please sign in to comment.