From: JinWang An Date: Mon, 27 Mar 2023 08:03:02 +0000 (+0900) Subject: Imported Upstream version 67.6.0 X-Git-Tag: upstream/67.6.0^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b7f6dbd544b36ca8efdb635eddf37fc730ddb38;p=platform%2Fupstream%2Fpython-setuptools.git Imported Upstream version 67.6.0 --- diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 89976bc..bbd755e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 67.5.1 +current_version = 67.6.0 commit = True tag = True diff --git a/CHANGES.rst b/CHANGES.rst index 7d5470a..7b88786 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,13 @@ +v67.6.0 +------- + + +Changes +^^^^^^^ +* #3804: Added caching for supported wheel tags. +* #3846: Added pruning heuristics to ``PackageFinder`` based on ``exclude``. + + v67.5.1 ------- diff --git a/docs/pkg_resources.rst b/docs/pkg_resources.rst index fcb91b7..7fd77f8 100644 --- a/docs/pkg_resources.rst +++ b/docs/pkg_resources.rst @@ -12,10 +12,8 @@ packages. .. attention:: Use of ``pkg_resources`` is deprecated in favor of - `importlib.resources `_, - `importlib.metadata `_, - and their backports (:pypi:`importlib_resources`, - :pypi:`importlib_metadata`). + :mod:`importlib.resources`, :mod:`importlib.metadata` + and their backports (:pypi:`importlib_resources`, :pypi:`importlib_metadata`). Users should refrain from new usage of ``pkg_resources`` and should work to port to importlib-based solutions. diff --git a/setup.cfg b/setup.cfg index cb4d928..a2d6d11 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = setuptools -version = 67.5.1 +version = 67.6.0 author = Python Packaging Authority author_email = distutils-sig@python.org description = Easily download, build, install, upgrade, and uninstall Python packages diff --git a/setuptools/discovery.py b/setuptools/discovery.py index f053dba..3110b72 100644 --- a/setuptools/discovery.py +++ b/setuptools/discovery.py @@ -44,7 +44,6 @@ from glob import glob from pathlib import Path from typing import ( TYPE_CHECKING, - Callable, Dict, Iterable, Iterator, @@ -61,7 +60,6 @@ from distutils import log from distutils.util import convert_path _Path = Union[str, os.PathLike] -_Filter = Callable[[str], bool] StrIter = Iterator[str] chain_iter = itertools.chain.from_iterable @@ -75,6 +73,22 @@ def _valid_name(path: _Path) -> bool: return os.path.basename(path).isidentifier() +class _Filter: + """ + Given a list of patterns, create a callable that will be true only if + the input matches at least one of the patterns. + """ + + def __init__(self, *patterns: str): + self._patterns = dict.fromkeys(patterns) + + def __call__(self, item: str) -> bool: + return any(fnmatchcase(item, pat) for pat in self._patterns) + + def __contains__(self, item: str) -> bool: + return item in self._patterns + + class _Finder: """Base class that exposes functionality for module/package finders""" @@ -111,8 +125,8 @@ class _Finder: return list( cls._find_iter( convert_path(str(where)), - cls._build_filter(*cls.ALWAYS_EXCLUDE, *exclude), - cls._build_filter(*include), + _Filter(*cls.ALWAYS_EXCLUDE, *exclude), + _Filter(*include), ) ) @@ -120,14 +134,6 @@ class _Finder: def _find_iter(cls, where: _Path, exclude: _Filter, include: _Filter) -> StrIter: raise NotImplementedError - @staticmethod - def _build_filter(*patterns: str) -> _Filter: - """ - Given a list of patterns, return a callable that will be true only if - the input matches at least one of the patterns. - """ - return lambda name: any(fnmatchcase(name, pat) for pat in patterns) - class PackageFinder(_Finder): """ @@ -160,6 +166,10 @@ class PackageFinder(_Finder): if include(package) and not exclude(package): yield package + # Early pruning if there is nothing else to be scanned + if f"{package}*" in exclude or f"{package}.*" in exclude: + continue + # Keep searching subdirectories, as there may be more packages # down there, even if the parent was excluded. dirs.append(dir) diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py index b2bbdfa..559e16d 100644 --- a/setuptools/tests/test_wheel.py +++ b/setuptools/tests/test_wheel.py @@ -609,9 +609,11 @@ def test_wheel_no_dist_dir(): def test_wheel_is_compatible(monkeypatch): def sys_tags(): - for t in parse_tag('cp36-cp36m-manylinux1_x86_64'): - yield t - monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags) + return { + (t.interpreter, t.abi, t.platform) + for t in parse_tag('cp36-cp36m-manylinux1_x86_64') + } + monkeypatch.setattr('setuptools.wheel._get_supported_tags', sys_tags) assert Wheel( 'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible() diff --git a/setuptools/wheel.py b/setuptools/wheel.py index e388083..850e43c 100644 --- a/setuptools/wheel.py +++ b/setuptools/wheel.py @@ -2,6 +2,7 @@ import email import itertools +import functools import os import posixpath import re @@ -28,6 +29,14 @@ NAMESPACE_PACKAGE_INIT = \ "__import__('pkg_resources').declare_namespace(__name__)\n" +@functools.lru_cache(maxsize=None) +def _get_supported_tags(): + # We calculate the supported tags only once, otherwise calling + # this method on thousands of wheels takes seconds instead of + # milliseconds. + return {(t.interpreter, t.abi, t.platform) for t in sys_tags()} + + def unpack(src_dir, dst_dir): '''Move everything under `src_dir` to `dst_dir`, and delete the former.''' for dirpath, dirnames, filenames in os.walk(src_dir): @@ -82,10 +91,8 @@ class Wheel: ) def is_compatible(self): - '''Is the wheel is compatible with the current platform?''' - supported_tags = set( - (t.interpreter, t.abi, t.platform) for t in sys_tags()) - return next((True for t in self.tags() if t in supported_tags), False) + '''Is the wheel compatible with the current platform?''' + return next((True for t in self.tags() if t in _get_supported_tags()), False) def egg_name(self): return _egg_basename(