Imported Upstream version 67.6.0 sandbox/jinwang.an/python-setuptools_67.6.0_20230327 upstream upstream/67.6.0
authorJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:03:02 +0000 (17:03 +0900)
committerJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:03:02 +0000 (17:03 +0900)
.bumpversion.cfg
CHANGES.rst
docs/pkg_resources.rst
setup.cfg
setuptools/discovery.py
setuptools/tests/test_wheel.py
setuptools/wheel.py

index 89976bca50d34265c9afae5bbcd374a319a0885e..bbd755e1e76367e69c50115b955b38ae64cfcf61 100644 (file)
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 67.5.1
+current_version = 67.6.0
 commit = True
 tag = True
 
index 7d5470a78f203c2e6027ea995c866af77bbe31ee..7b88786a648cfb68fc48d6667d744f02d0867d51 100644 (file)
@@ -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
 -------
 
index fcb91b7a05484db8ddacba1ad26bde3e515bce98..7fd77f8d062020283a781973ddadb2d844b67e54 100644 (file)
@@ -12,10 +12,8 @@ packages.
 
 .. attention::
    Use of ``pkg_resources`` is deprecated in favor of
-   `importlib.resources <https://docs.python.org/3/library/importlib.html#module-importlib.resources>`_,
-   `importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_,
-   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.
 
index cb4d928dfc44dfb63058fdc6530793caea6a92f0..a2d6d1123fb0e87ceea9ecf8d48c332ec64d1e9e 100644 (file)
--- 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
index f053dba8375975104dfb05b92ea909aa91b9620b..3110b72794f1e4fd75254bdb3dbf81a89918596e 100644 (file)
@@ -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)
index b2bbdfae7ff159425a1365849f555b6c04566701..559e16d758141d45f268bd571a56324516ddc389 100644 (file)
@@ -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()
 
index e388083ba8efaee7e433daed9bf302aeaec888e5..850e43cd01005c5d63ed08a35ad860858b74dce1 100644 (file)
@@ -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(