From 68af09493b1d7ef829eb3c0813542c5e21e63ec4 Mon Sep 17 00:00:00 2001 From: Danyal-Faheem Date: Wed, 17 Jan 2024 20:02:21 +0500 Subject: [PATCH 01/37] refactor: add return type for select method --- importlib_metadata/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 09a02a4e..a3aae725 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -275,7 +275,7 @@ def __repr__(self): """ return '%s(%r)' % (self.__class__.__name__, tuple(self)) - def select(self, **params): + def select(self, **params) -> EntryPoints: """ Select entry points from self that match the given parameters (typically group and/or name). From 72b30eca10d73b0f793aac5239e11710077c26cf Mon Sep 17 00:00:00 2001 From: Danyal-Faheem Date: Tue, 30 Jan 2024 15:30:36 +0500 Subject: [PATCH 02/37] refactor: add return type for load method --- importlib_metadata/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index a3aae725..d196ab79 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -33,7 +33,7 @@ from importlib import import_module from importlib.abc import MetaPathFinder from itertools import starmap -from typing import Iterable, List, Mapping, Optional, Set, cast +from typing import Iterable, List, Mapping, Optional, Set, cast, Any __all__ = [ 'Distribution', @@ -175,7 +175,7 @@ class EntryPoint: def __init__(self, name: str, value: str, group: str) -> None: vars(self).update(name=name, value=value, group=group) - def load(self): + def load(self) -> Any: """Load the entry point from its definition. If only a module is indicated by the value, return that module. Otherwise, return the named object. From fd3a0abc127bbd8986958e5baa54f9304daf2fa4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 6 Mar 2024 21:50:33 -0500 Subject: [PATCH 03/37] Re-order imports for consistency. --- importlib_metadata/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index d196ab79..3f14faa2 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -33,7 +33,7 @@ from importlib import import_module from importlib.abc import MetaPathFinder from itertools import starmap -from typing import Iterable, List, Mapping, Optional, Set, cast, Any +from typing import Any, Iterable, List, Mapping, Optional, Set, cast __all__ = [ 'Distribution', From 9d4908e77692d915872b24c040d3a1c89ebba1be Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 6 Mar 2024 21:56:41 -0500 Subject: [PATCH 04/37] =?UTF-8?q?=F0=9F=A7=8E=E2=80=8D=E2=99=80=EF=B8=8F?= =?UTF-8?q?=20Genuflect=20to=20the=20types.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- importlib_metadata/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 3f14faa2..5593f74e 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -33,7 +33,7 @@ from importlib import import_module from importlib.abc import MetaPathFinder from itertools import starmap -from typing import Any, Iterable, List, Mapping, Optional, Set, cast +from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast __all__ = [ 'Distribution', @@ -180,7 +180,7 @@ def load(self) -> Any: is indicated by the value, return that module. Otherwise, return the named object. """ - match = self.pattern.match(self.value) + match = cast(Match, self.pattern.match(self.value)) module = import_module(match.group('module')) attrs = filter(None, (match.group('attr') or '').split('.')) return functools.reduce(getattr, attrs, module) @@ -769,6 +769,7 @@ class Lookup: """ A micro-optimized class for searching a (fast) path for metadata. """ + def __init__(self, path: FastPath): """ Calculate all of the children representing metadata. From 913352a8765662f1569123b27ecb9ca7bc4d649e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 7 Mar 2024 08:09:53 -0500 Subject: [PATCH 05/37] Finalize --- NEWS.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 5f9b2765..085a5305 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,9 @@ +v7.0.2 +====== + +No significant changes. + + v7.0.1 ====== From b4ce0ff90ec730866885a08134ece217b69949d2 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:30:22 -0800 Subject: [PATCH 06/37] gh-109653: Improve import time of importlib.metadata / email.utils (python/cpython#114664) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My criterion for delayed imports is that they're only worth it if the majority of users of the module would benefit from it, otherwise you're just moving latency around unpredictably. mktime_tz is not used anywhere in the standard library and grep.app indicates it's not got much use in the ecosystem either. Distribution.files is not nearly as widely used as other importlib.metadata APIs, so we defer the csv import. Before: ``` λ hyperfine -w 8 './python -c "import importlib.metadata"' Benchmark 1: ./python -c "import importlib.metadata" Time (mean ± σ): 65.1 ms ± 0.5 ms [User: 55.3 ms, System: 9.8 ms] Range (min … max): 64.4 ms … 66.4 ms 44 runs ``` After: ``` λ hyperfine -w 8 './python -c "import importlib.metadata"' Benchmark 1: ./python -c "import importlib.metadata" Time (mean ± σ): 62.0 ms ± 0.3 ms [User: 52.5 ms, System: 9.6 ms] Range (min … max): 61.3 ms … 62.8 ms 46 runs ``` for about a 3ms saving with warm disk cache, maybe 7-11ms with cold disk cache. --- importlib_metadata/__init__.py | 5 ++++- newsfragments/+.feature.rst | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 newsfragments/+.feature.rst diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index c68d8ad8..5cd15ab5 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -3,7 +3,6 @@ import os import re import abc -import csv import sys import json import zipp @@ -522,6 +521,10 @@ def make_file(name, hash=None, size_str=None): @pass_none def make_files(lines): + # Delay csv import, since Distribution.files is not as widely used + # as other parts of importlib.metadata + import csv + return starmap(make_file, csv.reader(lines)) @pass_none diff --git a/newsfragments/+.feature.rst b/newsfragments/+.feature.rst new file mode 100644 index 00000000..865acfc1 --- /dev/null +++ b/newsfragments/+.feature.rst @@ -0,0 +1 @@ +Improve import time (python/cpython#114664). From fb7465c6f81847574b736e6dfa1bb93187e025cc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 14 Mar 2024 17:59:00 -0400 Subject: [PATCH 07/37] gh-116811: Ensure MetadataPathFinder.invalidate_caches is reachable when delegated through PathFinder. (python/cpython#116812) * Make MetadataPathFinder a proper classmethod. --- importlib_metadata/__init__.py | 1 + newsfragments/+.bugfix.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 newsfragments/+.bugfix.rst diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 5cd15ab5..86e68a23 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -898,6 +898,7 @@ def _search_paths(cls, name, paths): path.search(prepared) for path in map(FastPath, paths) ) + @classmethod def invalidate_caches(cls) -> None: FastPath.__new__.cache_clear() diff --git a/newsfragments/+.bugfix.rst b/newsfragments/+.bugfix.rst new file mode 100644 index 00000000..a8dd3dde --- /dev/null +++ b/newsfragments/+.bugfix.rst @@ -0,0 +1 @@ +Allow ``MetadataPathFinder.invalidate_caches`` to be called as a classmethod. From 9a878d6b263b7e9dedc10fc0df1a7323e9ee7b99 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 16 Jan 2024 16:10:03 +0100 Subject: [PATCH 08/37] gh-114107: Fix symlink test if symlinks aren't supported (python/cpython#114108) --- tests/test_main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 6e0b1da7..45d74534 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,6 +5,8 @@ import importlib import importlib_metadata import contextlib +from test.support import os_helper + import pyfakefs.fake_filesystem_unittest as ffs from . import fixtures @@ -396,6 +398,7 @@ def test_packages_distributions_all_module_types(self): assert not any(name.endswith('.dist-info') for name in distributions) + @os_helper.skip_unless_symlink def test_packages_distributions_symlinked_top_level(self) -> None: """ Distribution is resolvable from a simple top-level symlink in RECORD. From f16e114956ea2970d4b391ca031dfe7f2d65d46e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 04:53:22 -0400 Subject: [PATCH 09/37] Add support for python/cpython references --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 134d7534..90a1da2a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ url='https://peps.python.org/pep-{pep_number:0>4}/', ), dict( - pattern=r'(Python #|py-)(?P\d+)', + pattern=r'(python/cpython#|Python #|py-)(?P\d+)', url='https://github.com/python/cpython/issues/{python}', ), ], From 3531507c7a275cfcbdefe02e0aed4f92ff589b09 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:11:25 -0400 Subject: [PATCH 10/37] Fix test failures on older Pythons with os_helper shim. Copied 'from_test_support' from importlib_resources. --- setup.cfg | 1 + tests/fixtures.py | 6 ++++-- tests/py39compat.py | 18 ++++++++++++++++-- tests/test_main.py | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 71b66b39..f67df574 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,6 +37,7 @@ testing = pyfakefs flufl.flake8 pytest-perf >= 0.9.2 + jaraco.collections docs = # upstream diff --git a/tests/fixtures.py b/tests/fixtures.py index 7daae16a..88478050 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -9,7 +9,7 @@ import functools import contextlib -from .py39compat import FS_NONASCII +from .py39compat import os_helper from . import _path from ._path import FilesSpec @@ -335,7 +335,9 @@ def record_names(file_defs): class FileBuilder: def unicode_filename(self): - return FS_NONASCII or self.skip("File system does not support non-ascii.") + return os_helper.FS_NONASCII or self.skip( + "File system does not support non-ascii." + ) def DALS(str): diff --git a/tests/py39compat.py b/tests/py39compat.py index 926dcad9..b01ecad8 100644 --- a/tests/py39compat.py +++ b/tests/py39compat.py @@ -1,4 +1,18 @@ +import types + +from jaraco.collections import Projection + + +def from_test_support(*names): + """ + Return a SimpleNamespace of names from test.support. + """ + import test.support + + return types.SimpleNamespace(**Projection(names, vars(test.support))) + + try: - from test.support.os_helper import FS_NONASCII + from test.support import os_helper # type: ignore except ImportError: - from test.support import FS_NONASCII # noqa + os_helper = from_test_support('FS_NONASCII', 'skip_unless_symlink') diff --git a/tests/test_main.py b/tests/test_main.py index 45d74534..c94ab0f4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,7 +5,7 @@ import importlib import importlib_metadata import contextlib -from test.support import os_helper +from .py39compat import os_helper import pyfakefs.fake_filesystem_unittest as ffs From 856541b5f26c099ef7629b95533ca285fe6c102c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:12:18 -0400 Subject: [PATCH 11/37] Moved compatibility module to compat package. --- importlib_metadata/__init__.py | 7 ++++--- importlib_metadata/compat/__init__.py | 0 importlib_metadata/{_py39compat.py => compat/py39.py} | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 importlib_metadata/compat/__init__.py rename importlib_metadata/{_py39compat.py => compat/py39.py} (82%) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 86e68a23..c85ffa76 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -18,7 +18,8 @@ import posixpath import collections -from . import _adapters, _meta, _py39compat +from . import _adapters, _meta +from .compat import py39 from ._collections import FreezableDefaultDict, Pair from ._compat import ( NullFinder, @@ -279,7 +280,7 @@ def select(self, **params) -> EntryPoints: Select entry points from self that match the given parameters (typically group and/or name). """ - return EntryPoints(ep for ep in self if _py39compat.ep_matches(ep, **params)) + return EntryPoints(ep for ep in self if py39.ep_matches(ep, **params)) @property def names(self) -> Set[str]: @@ -996,7 +997,7 @@ def version(distribution_name: str) -> str: _unique = functools.partial( unique_everseen, - key=_py39compat.normalized_name, + key=py39.normalized_name, ) """ Wrapper for ``distributions`` to return unique distributions by name. diff --git a/importlib_metadata/compat/__init__.py b/importlib_metadata/compat/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/importlib_metadata/_py39compat.py b/importlib_metadata/compat/py39.py similarity index 82% rename from importlib_metadata/_py39compat.py rename to importlib_metadata/compat/py39.py index fc6b8221..1f15bd97 100644 --- a/importlib_metadata/_py39compat.py +++ b/importlib_metadata/compat/py39.py @@ -6,7 +6,7 @@ if TYPE_CHECKING: # pragma: no cover # Prevent circular imports on runtime. - from . import Distribution, EntryPoint + from .. import Distribution, EntryPoint else: Distribution = EntryPoint = Any @@ -18,7 +18,7 @@ def normalized_name(dist: Distribution) -> Optional[str]: try: return dist._normalized_name except AttributeError: - from . import Prepared # -> delay to prevent circular imports. + from .. import Prepared # -> delay to prevent circular imports. return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name']) @@ -30,7 +30,7 @@ def ep_matches(ep: EntryPoint, **params) -> bool: try: return ep.matches(**params) except AttributeError: - from . import EntryPoint # -> delay to prevent circular imports. + from .. import EntryPoint # -> delay to prevent circular imports. # Reconstruct the EntryPoint object to make sure it is compatible. return EntryPoint(ep.name, ep.value, ep.group).matches(**params) From ffa719bbd8876b43964b704af34b6bce50ac7271 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:14:31 -0400 Subject: [PATCH 12/37] Moved compatibility module to compat package. --- tests/compat/__init__.py | 0 tests/{py39compat.py => compat/py39.py} | 0 tests/fixtures.py | 2 +- tests/test_main.py | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 tests/compat/__init__.py rename tests/{py39compat.py => compat/py39.py} (100%) diff --git a/tests/compat/__init__.py b/tests/compat/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/py39compat.py b/tests/compat/py39.py similarity index 100% rename from tests/py39compat.py rename to tests/compat/py39.py diff --git a/tests/fixtures.py b/tests/fixtures.py index 88478050..07f10963 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -9,7 +9,7 @@ import functools import contextlib -from .py39compat import os_helper +from .compat.py39 import os_helper from . import _path from ._path import FilesSpec diff --git a/tests/test_main.py b/tests/test_main.py index c94ab0f4..af79e698 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,7 +5,7 @@ import importlib import importlib_metadata import contextlib -from .py39compat import os_helper +from .compat.py39 import os_helper import pyfakefs.fake_filesystem_unittest as ffs From 5950f43b8f44a1b700342ffd4633c147309b1c7c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:17:34 -0400 Subject: [PATCH 13/37] Remove legacy logic for Python 3.7. --- tests/test_py39compat.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_py39compat.py b/tests/test_py39compat.py index 7e6235e4..34745a4b 100644 --- a/tests/test_py39compat.py +++ b/tests/test_py39compat.py @@ -14,8 +14,7 @@ class OldStdlibFinderTests(fixtures.DistInfoPkgOffPath, unittest.TestCase): def setUp(self): - python_version = sys.version_info[:2] - if python_version < (3, 8) or python_version > (3, 9): + if sys.version_info >= (3, 10): self.skipTest("Tests specific for Python 3.8/3.9") super().setUp() From 41ca0390dbb52543104f12c0629f0bbb882e48ea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:22:24 -0400 Subject: [PATCH 14/37] Moved compatibility tests to the compat package, as they're not included in CPython. --- tests/{test_py39compat.py => compat/test_py39_compat.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{test_py39compat.py => compat/test_py39_compat.py} (99%) diff --git a/tests/test_py39compat.py b/tests/compat/test_py39_compat.py similarity index 99% rename from tests/test_py39compat.py rename to tests/compat/test_py39_compat.py index 34745a4b..549e518a 100644 --- a/tests/test_py39compat.py +++ b/tests/compat/test_py39_compat.py @@ -2,7 +2,7 @@ import pathlib import unittest -from . import fixtures +from .. import fixtures from importlib_metadata import ( distribution, distributions, From e30a16d471f62555db5605d5652bede9a1234b1a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 06:20:46 -0400 Subject: [PATCH 15/37] Consolidated test support logic in jaraco.test.cpython. --- setup.cfg | 2 +- tests/compat/py39.py | 20 ++++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/setup.cfg b/setup.cfg index f67df574..02d3c7e8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,7 @@ testing = pyfakefs flufl.flake8 pytest-perf >= 0.9.2 - jaraco.collections + jaraco.test >= 5.4 docs = # upstream diff --git a/tests/compat/py39.py b/tests/compat/py39.py index b01ecad8..0f6f9c3a 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -1,18 +1,6 @@ -import types +from jaraco.test.cpython import from_test_support, try_import -from jaraco.collections import Projection - -def from_test_support(*names): - """ - Return a SimpleNamespace of names from test.support. - """ - import test.support - - return types.SimpleNamespace(**Projection(names, vars(test.support))) - - -try: - from test.support import os_helper # type: ignore -except ImportError: - os_helper = from_test_support('FS_NONASCII', 'skip_unless_symlink') +os_helper = try_import('os_helper') or from_test_support( + 'FS_NONASCII', 'skip_unless_symlink' +) From 07d894d96777e77f9dac3ec671f2dce4c584a26d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 13:49:52 -0400 Subject: [PATCH 16/37] Copy backport of isolated_modules from importlib_resources. --- tests/compat/py312.py | 18 ++++++++++++++++++ tests/compat/py39.py | 1 + 2 files changed, 19 insertions(+) create mode 100644 tests/compat/py312.py diff --git a/tests/compat/py312.py b/tests/compat/py312.py new file mode 100644 index 00000000..ea9a58ba --- /dev/null +++ b/tests/compat/py312.py @@ -0,0 +1,18 @@ +import contextlib + +from .py39 import import_helper + + +@contextlib.contextmanager +def isolated_modules(): + """ + Save modules on entry and cleanup on exit. + """ + (saved,) = import_helper.modules_setup() + try: + yield + finally: + import_helper.modules_cleanup(saved) + + +vars(import_helper).setdefault('isolated_modules', isolated_modules) diff --git a/tests/compat/py39.py b/tests/compat/py39.py index 0f6f9c3a..5fe61c39 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -4,3 +4,4 @@ os_helper = try_import('os_helper') or from_test_support( 'FS_NONASCII', 'skip_unless_symlink' ) +import_helper = try_import('import_helper') or from_test_support() From adc4b124fc57cc3864bf68c61f7fa046757ffa02 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 13:55:54 -0400 Subject: [PATCH 17/37] Ensure tests do not leak references in sys.modules. --- tests/fixtures.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index 07f10963..f8082df0 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -9,6 +9,7 @@ import functools import contextlib +from .compat.py312 import import_helper from .compat.py39 import os_helper from . import _path @@ -84,6 +85,7 @@ def add_sys_path(dir): def setUp(self): super().setUp() self.fixtures.enter_context(self.add_sys_path(self.site_dir)) + self.fixtures.enter_context(import_helper.isolated_modules()) class SiteBuilder(SiteDir): From 47b14acde7b15472b02a14c7abdd7e5545af37f5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 15:17:03 -0400 Subject: [PATCH 18/37] Make MetadataPathFinder.find_distributions a classmethod for consistency with CPython. Closes #484. --- importlib_metadata/__init__.py | 5 +++-- newsfragments/484.bugfix.rst | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 newsfragments/484.bugfix.rst diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index c85ffa76..32ee3b4d 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -877,8 +877,9 @@ class MetadataPathFinder(NullFinder, DistributionFinder): of Python that do not have a PathFinder find_distributions(). """ + @classmethod def find_distributions( - self, context=DistributionFinder.Context() + cls, context=DistributionFinder.Context() ) -> Iterable[PathDistribution]: """ Find distributions. @@ -888,7 +889,7 @@ def find_distributions( (or all names if ``None`` indicated) along the paths in the list of directories ``context.path``. """ - found = self._search_paths(context.name, context.path) + found = cls._search_paths(context.name, context.path) return map(PathDistribution, found) @classmethod diff --git a/newsfragments/484.bugfix.rst b/newsfragments/484.bugfix.rst new file mode 100644 index 00000000..4274419b --- /dev/null +++ b/newsfragments/484.bugfix.rst @@ -0,0 +1 @@ +Make MetadataPathFinder.find_distributions a classmethod for consistency with CPython. Closes #484. \ No newline at end of file From 1711b2c1984b2f871fe12c9c14fd7a0b42d32987 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 15:26:59 -0400 Subject: [PATCH 19/37] Need to include names from test.support for py312 compat. --- tests/compat/py39.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/compat/py39.py b/tests/compat/py39.py index 5fe61c39..16c8b574 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -4,4 +4,6 @@ os_helper = try_import('os_helper') or from_test_support( 'FS_NONASCII', 'skip_unless_symlink' ) -import_helper = try_import('import_helper') or from_test_support() +import_helper = try_import('import_helper') or from_test_support( + 'modules_setup', 'modules_cleanup' +) From f5d6b5f3f3f6fffe01b340c5a19562433db148a9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 15:38:57 -0400 Subject: [PATCH 20/37] Finalize --- NEWS.rst | 16 ++++++++++++++++ newsfragments/+.bugfix.rst | 1 - newsfragments/+.feature.rst | 1 - newsfragments/484.bugfix.rst | 1 - 4 files changed, 16 insertions(+), 3 deletions(-) delete mode 100644 newsfragments/+.bugfix.rst delete mode 100644 newsfragments/+.feature.rst delete mode 100644 newsfragments/484.bugfix.rst diff --git a/NEWS.rst b/NEWS.rst index 085a5305..850e8f00 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,19 @@ +v7.1.0 +====== + +Features +-------- + +- Improve import time (python/cpython#114664). + + +Bugfixes +-------- + +- Make MetadataPathFinder.find_distributions a classmethod for consistency with CPython. Closes #484. (#484) +- Allow ``MetadataPathFinder.invalidate_caches`` to be called as a classmethod. + + v7.0.2 ====== diff --git a/newsfragments/+.bugfix.rst b/newsfragments/+.bugfix.rst deleted file mode 100644 index a8dd3dde..00000000 --- a/newsfragments/+.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Allow ``MetadataPathFinder.invalidate_caches`` to be called as a classmethod. diff --git a/newsfragments/+.feature.rst b/newsfragments/+.feature.rst deleted file mode 100644 index 865acfc1..00000000 --- a/newsfragments/+.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Improve import time (python/cpython#114664). diff --git a/newsfragments/484.bugfix.rst b/newsfragments/484.bugfix.rst deleted file mode 100644 index 4274419b..00000000 --- a/newsfragments/484.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Make MetadataPathFinder.find_distributions a classmethod for consistency with CPython. Closes #484. \ No newline at end of file From 6673723baa487e447135815e8aaf1bb41aa963bd Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Thu, 21 Mar 2024 03:49:10 +0000 Subject: [PATCH 21/37] GH-109653: Defer import of ``importlib.metadata._adapters`` (python/cpython#109829) --------- Co-authored-by: Jason R. Coombs --- importlib_metadata/__init__.py | 5 ++++- newsfragments/+.feature.rst | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 newsfragments/+.feature.rst diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 32ee3b4d..f4c75941 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -18,7 +18,7 @@ import posixpath import collections -from . import _adapters, _meta +from . import _meta from .compat import py39 from ._collections import FreezableDefaultDict, Pair from ._compat import ( @@ -461,6 +461,9 @@ def metadata(self) -> _meta.PackageMetadata: Custom providers may provide the METADATA file or override this property. """ + # deferred for performance (python/cpython#109829) + from . import _adapters + opt_text = ( self.read_text('METADATA') or self.read_text('PKG-INFO') diff --git a/newsfragments/+.feature.rst b/newsfragments/+.feature.rst new file mode 100644 index 00000000..26618684 --- /dev/null +++ b/newsfragments/+.feature.rst @@ -0,0 +1 @@ +Deferred select imports in for speedup (python/cpython#109829). From a0d0c4b7e87fbfd04cee2546ba452858587516fd Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 21 Mar 2024 15:34:23 -0400 Subject: [PATCH 22/37] Allow mypy on PyPy (jaraco/skeleton#111) https://github.com/pypa/setuptools/pull/4257 shows that mypy now works with PyPy --- setup.cfg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 400a72a5..6fa73b6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,9 +23,7 @@ testing = pytest >= 6 pytest-checkdocs >= 2.4 pytest-cov - pytest-mypy; \ - # workaround for jaraco/skeleton#22 - python_implementation != "PyPy" + pytest-mypy pytest-enabler >= 2.2 pytest-ruff >= 0.2.1 From c9a7f97ba83be124e173713f5c24564c2b6dd49e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 21 Mar 2024 15:49:52 -0400 Subject: [PATCH 23/37] Re-enable ignoring of temporary merge queue branches. Closes jaraco/skeleton#103. --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf94f7d8..143b0984 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,8 +4,11 @@ on: merge_group: push: branches-ignore: - # disabled for jaraco/skeleton#103 - # - gh-readonly-queue/** # Temporary merge queue-related GH-made branches + # temporary GH branches relating to merge queues (jaraco/skeleton#93) + - gh-readonly-queue/** + tags: + # required if branches-ignore is supplied (jaraco/skeleton#103) + - '**' pull_request: permissions: From d72c6a081b67ce18eae654bf3c8d2d627af6939e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 23 Mar 2024 13:46:21 -0400 Subject: [PATCH 24/37] Fetch unshallow clones in readthedocs. Closes jaraco/skeleton#114. --- .readthedocs.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 68489063..85dfea9d 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -10,3 +10,7 @@ build: os: ubuntu-lts-latest tools: python: latest + # post-checkout job to ensure the clone isn't shallow jaraco/skeleton#114 + jobs: + post_checkout: + - git fetch --unshallow || true From 3fc7a935dfc0e5c8e330a29efc5518c464795cf8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 29 Mar 2024 21:11:46 -0400 Subject: [PATCH 25/37] Move Python 3.11 out of the test matrix. Probably should have done this when moving continue-on-error to Python 3.13. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 143b0984..a15c74a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,6 @@ jobs: matrix: python: - "3.8" - - "3.11" - "3.12" platform: - ubuntu-latest @@ -45,6 +44,8 @@ jobs: platform: ubuntu-latest - python: "3.10" platform: ubuntu-latest + - python: "3.11" + platform: ubuntu-latest - python: pypy3.10 platform: ubuntu-latest runs-on: ${{ matrix.platform }} From 6ff02e0eefcd90e271cefd326b460ecfa0e3eb9e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 31 Mar 2024 04:27:11 -0400 Subject: [PATCH 26/37] Configure pytest to support namespace packages. Ref pytest-dev/pytest#12112. --- pytest.ini | 5 ++++- setup.cfg | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 022a723e..9a0f3bce 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,9 @@ [pytest] norecursedirs=dist build .tox .eggs -addopts=--doctest-modules +addopts= + --doctest-modules + --import-mode importlib +consider_namespace_packages=true filterwarnings= ## upstream diff --git a/setup.cfg b/setup.cfg index 6fa73b6a..f46b6cbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ install_requires = [options.extras_require] testing = # upstream - pytest >= 6 + pytest >= 6, != 8.1.1 pytest-checkdocs >= 2.4 pytest-cov pytest-mypy From 34ba6b2ec0650c8c70d9285a0c7ee1a126406807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Mon, 1 Apr 2024 17:47:04 +0200 Subject: [PATCH 27/37] Add link to blog entry from jaraco/skeleton#115 above CI build matrix. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a15c74a6..ac0ff69e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,6 +31,7 @@ env: jobs: test: strategy: + # https://blog.jaraco.com/efficient-use-of-ci-resources/ matrix: python: - "3.8" From 7ad4f2fa9fb2b030d3ecc231fc24de181705622d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 16 Apr 2024 10:31:45 -0400 Subject: [PATCH 28/37] Pin against pytest 8.1.x due to pytest-dev/pytest#12194. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index f46b6cbf..05ac4c76 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ install_requires = [options.extras_require] testing = # upstream - pytest >= 6, != 8.1.1 + pytest >= 6, != 8.1.* pytest-checkdocs >= 2.4 pytest-cov pytest-mypy From f4529af6a66e34d423860566be7882d665e10569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Tue, 16 Apr 2024 22:37:50 +0200 Subject: [PATCH 29/37] Move project metadata to `pyproject.toml` (jaraco/skeleton#122) Intentionally omitted specifying `tool.setuptools.include-package-data`: it's true by default in `pyproject.toml` according to https://setuptools.pypa.io/en/latest/userguide/datafiles.html#include-package-data. Closes jaraco/skeleton#121 --- pyproject.toml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- setup.cfg | 42 ------------------------------------------ 2 files changed, 48 insertions(+), 43 deletions(-) delete mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index a853c578..869fe7e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,52 @@ [build-system] -requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"] +requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.1"] build-backend = "setuptools.build_meta" +[project] +name = "PROJECT" +authors = [ + { name = "Jason R. Coombs", email = "jaraco@jaraco.com" }, +] +description = "PROJECT_DESCRIPTION" +readme = "README.rst" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", +] +requires-python = ">=3.8" +dependencies = [ +] +dynamic = ["version"] + +[project.optional-dependencies] +testing = [ + # upstream + "pytest >= 6, != 8.1.*", + "pytest-checkdocs >= 2.4", + "pytest-cov", + "pytest-mypy", + "pytest-enabler >= 2.2", + "pytest-ruff >= 0.2.1", + + # local +] +docs = [ + # upstream + "sphinx >= 3.5", + "jaraco.packaging >= 9.3", + "rst.linker >= 1.9", + "furo", + "sphinx-lint", + + # local +] + +[project.urls] +Homepage = "https://github.com/PROJECT_PATH" + +[project.scripts] + [tool.setuptools_scm] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 05ac4c76..00000000 --- a/setup.cfg +++ /dev/null @@ -1,42 +0,0 @@ -[metadata] -name = PROJECT -author = Jason R. Coombs -author_email = jaraco@jaraco.com -description = PROJECT_DESCRIPTION -long_description = file:README.rst -url = https://github.com/PROJECT_PATH -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: MIT License - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - -[options] -include_package_data = true -python_requires = >=3.8 -install_requires = - -[options.extras_require] -testing = - # upstream - pytest >= 6, != 8.1.* - pytest-checkdocs >= 2.4 - pytest-cov - pytest-mypy - pytest-enabler >= 2.2 - pytest-ruff >= 0.2.1 - - # local - -docs = - # upstream - sphinx >= 3.5 - jaraco.packaging >= 9.3 - rst.linker >= 1.9 - furo - sphinx-lint - - # local - -[options.entry_points] From d34801bd169637d95d262fca9e0dbd658ae1feef Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 18 Apr 2024 16:38:18 -0400 Subject: [PATCH 30/37] Migrated config to pyproject.toml using jaraco.develop.migrate-config and ini2toml. --- pyproject.toml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++- setup.cfg | 58 ------------------------------------------------- 2 files changed, 58 insertions(+), 59 deletions(-) delete mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index a853c578..4931fcbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,62 @@ [build-system] -requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"] +requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.1"] build-backend = "setuptools.build_meta" +[project] +name = "importlib_metadata" +authors = [ + { name = "Jason R. Coombs", email = "jaraco@jaraco.com" }, +] +description = "Read metadata from Python packages" +readme = "README.rst" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", +] +requires-python = ">=3.8" +dependencies = [ + "zipp>=0.5", + 'typing-extensions>=3.6.4; python_version < "3.8"', +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/python/importlib_metadata" + +[project.optional-dependencies] +testing = [ + # upstream + "pytest >= 6", + "pytest-checkdocs >= 2.4", + "pytest-cov", + 'pytest-mypy; python_implementation != "PyPy"', # workaround for jaraco/skeleton#22 + "pytest-enabler >= 2.2", + "pytest-ruff >= 0.2.1", + + # local + 'importlib_resources>=1.3; python_version < "3.9"', + "packaging", + "pyfakefs", + "flufl.flake8", + "pytest-perf >= 0.9.2", + "jaraco.test >= 5.4", +] +docs = [ + # upstream + "sphinx >= 3.5", + "jaraco.packaging >= 9.3", + "rst.linker >= 1.9", + "furo", + "sphinx-lint", + + # tidelift + "jaraco.tidelift >= 1.4", + + # local +] +perf = ["ipython"] + [tool.setuptools_scm] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 02d3c7e8..00000000 --- a/setup.cfg +++ /dev/null @@ -1,58 +0,0 @@ -[metadata] -name = importlib_metadata -author = Jason R. Coombs -author_email = jaraco@jaraco.com -description = Read metadata from Python packages -long_description = file:README.rst -url = https://github.com/python/importlib_metadata -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: Apache Software License - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - -[options] -include_package_data = true -python_requires = >=3.8 -install_requires = - zipp>=0.5 - typing-extensions>=3.6.4; python_version < "3.8" - -[options.extras_require] -testing = - # upstream - pytest >= 6 - pytest-checkdocs >= 2.4 - pytest-cov - pytest-mypy; \ - # workaround for jaraco/skeleton#22 - python_implementation != "PyPy" - pytest-enabler >= 2.2 - pytest-ruff >= 0.2.1 - - # local - importlib_resources>=1.3; python_version < "3.9" - packaging - pyfakefs - flufl.flake8 - pytest-perf >= 0.9.2 - jaraco.test >= 5.4 - -docs = - # upstream - sphinx >= 3.5 - jaraco.packaging >= 9.3 - rst.linker >= 1.9 - furo - sphinx-lint - - # tidelift - jaraco.tidelift >= 1.4 - - # local - -perf = - ipython - -[options.entry_points] From 744cf2a2befb6a616657c105e5c9be9f3f921224 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Apr 2024 10:48:06 -0400 Subject: [PATCH 31/37] Allow macos on Python 3.8 to fail as GitHub CI has dropped support. Closes jaraco/skeleton#124. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac0ff69e..5ace4c50 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: - python: pypy3.10 platform: ubuntu-latest runs-on: ${{ matrix.platform }} - continue-on-error: ${{ matrix.python == '3.13' }} + continue-on-error: ${{ matrix.python == '3.13' || (matrix.python == '3.8' || matrix.python == '3.9') && matrix.platform == 'macos-latest' }} steps: - uses: actions/checkout@v4 - name: Setup Python From bcf8f079eb729e7bcd50c10cf4da522620b00635 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Apr 2024 11:06:12 -0400 Subject: [PATCH 32/37] Move project.urls to appear in the order that ini2toml generates it. Remove project.scripts. --- pyproject.toml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 869fe7e5..04b14cbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,9 @@ dependencies = [ ] dynamic = ["version"] +[project.urls] +Homepage = "https://github.com/PROJECT_PATH" + [project.optional-dependencies] testing = [ # upstream @@ -44,9 +47,4 @@ docs = [ # local ] -[project.urls] -Homepage = "https://github.com/PROJECT_PATH" - -[project.scripts] - [tool.setuptools_scm] From 67aab1554c7c9cbb19bb546a5b6476267030c5b5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 2 May 2024 15:36:22 -0400 Subject: [PATCH 33/37] Revert "Allow macos on Python 3.8 to fail as GitHub CI has dropped support." This reverts commit 744cf2a2befb6a616657c105e5c9be9f3f921224. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ace4c50..ac0ff69e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: - python: pypy3.10 platform: ubuntu-latest runs-on: ${{ matrix.platform }} - continue-on-error: ${{ matrix.python == '3.13' || (matrix.python == '3.8' || matrix.python == '3.9') && matrix.platform == 'macos-latest' }} + continue-on-error: ${{ matrix.python == '3.13' }} steps: - uses: actions/checkout@v4 - name: Setup Python From a595a0fad054cd20b69d3e954c99174e3a548938 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 31 May 2024 03:53:48 -0400 Subject: [PATCH 34/37] Rename extras to align with core metadata spec. Closes jaraco/skeleton#125. --- .readthedocs.yaml | 2 +- pyproject.toml | 4 ++-- tox.ini | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 85dfea9d..dc8516ac 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -3,7 +3,7 @@ python: install: - path: . extra_requirements: - - docs + - doc # required boilerplate readthedocs/readthedocs.org#10401 build: diff --git a/pyproject.toml b/pyproject.toml index 04b14cbc..50845ee3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dynamic = ["version"] Homepage = "https://github.com/PROJECT_PATH" [project.optional-dependencies] -testing = [ +test = [ # upstream "pytest >= 6, != 8.1.*", "pytest-checkdocs >= 2.4", @@ -36,7 +36,7 @@ testing = [ # local ] -docs = [ +doc = [ # upstream "sphinx >= 3.5", "jaraco.packaging >= 9.3", diff --git a/tox.ini b/tox.ini index 4c39a5b1..cc4db36e 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ commands = pytest {posargs} usedevelop = True extras = - testing + test [testenv:diffcov] description = run tests and check that diff from main is covered @@ -22,8 +22,8 @@ commands = [testenv:docs] description = build the documentation extras = - docs - testing + doc + test changedir = docs commands = python -m sphinx -W --keep-going . {toxinidir}/build/html From 963f643b1f05effc980bb6df0196c64f6576dfc6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 20 Jun 2024 12:39:10 -0400 Subject: [PATCH 35/37] gh-120801: Update fixtures. Removed unused fixtures relating to cwd. Rely on os_helper.temp_dir where relevant. Renamed to tmp_path to reflect pathlib behavior. --- newsfragments/+76d2542b.feature.rst | 1 + tests/compat/py39.py | 2 +- tests/fixtures.py | 33 ++++++----------------------- tests/test_api.py | 2 +- tests/test_main.py | 2 +- 5 files changed, 11 insertions(+), 29 deletions(-) create mode 100644 newsfragments/+76d2542b.feature.rst diff --git a/newsfragments/+76d2542b.feature.rst b/newsfragments/+76d2542b.feature.rst new file mode 100644 index 00000000..43b0e391 --- /dev/null +++ b/newsfragments/+76d2542b.feature.rst @@ -0,0 +1 @@ +Updated fixtures for python/cpython#120801. diff --git a/tests/compat/py39.py b/tests/compat/py39.py index 16c8b574..9476eb35 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -2,7 +2,7 @@ os_helper = try_import('os_helper') or from_test_support( - 'FS_NONASCII', 'skip_unless_symlink' + 'FS_NONASCII', 'skip_unless_symlink', 'temp_dir' ) import_helper = try_import('import_helper') or from_test_support( 'modules_setup', 'modules_cleanup' diff --git a/tests/fixtures.py b/tests/fixtures.py index f8082df0..1bf9a803 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,10 +1,8 @@ -import os import sys import copy import json import shutil import pathlib -import tempfile import textwrap import functools import contextlib @@ -26,29 +24,12 @@ @contextlib.contextmanager -def tempdir(): - tmpdir = tempfile.mkdtemp() - try: - yield pathlib.Path(tmpdir) - finally: - shutil.rmtree(tmpdir) - - -@contextlib.contextmanager -def save_cwd(): - orig = os.getcwd() - try: - yield - finally: - os.chdir(orig) - - -@contextlib.contextmanager -def tempdir_as_cwd(): - with tempdir() as tmp: - with save_cwd(): - os.chdir(str(tmp)) - yield tmp +def tmp_path(): + """ + Like os_helper.temp_dir, but yields a pathlib.Path. + """ + with os_helper.temp_dir() as path: + yield pathlib.Path(path) @contextlib.contextmanager @@ -69,7 +50,7 @@ def setUp(self): class SiteDir(Fixtures): def setUp(self): super().setUp() - self.site_dir = self.fixtures.enter_context(tempdir()) + self.site_dir = self.fixtures.enter_context(tmp_path()) class OnSysPath(Fixtures): diff --git a/tests/test_api.py b/tests/test_api.py index a85c62ad..a93065cb 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -109,7 +109,7 @@ def test_entry_points_unique_packages_normalized(self): Entry points should only be exposed for the first package on sys.path with a given name (even when normalized). """ - alt_site_dir = self.fixtures.enter_context(fixtures.tempdir()) + alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path()) self.fixtures.enter_context(self.add_sys_path(alt_site_dir)) alt_pkg = { "DistInfo_pkg-1.1.0.dist-info": { diff --git a/tests/test_main.py b/tests/test_main.py index af79e698..32241c00 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -135,7 +135,7 @@ def test_unique_distributions(self): fixtures.build_files(self.make_pkg('abc'), self.site_dir) before = list(_unique(distributions())) - alt_site_dir = self.fixtures.enter_context(fixtures.tempdir()) + alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path()) self.fixtures.enter_context(self.add_sys_path(alt_site_dir)) fixtures.build_files(self.make_pkg('ABC'), alt_site_dir) after = list(_unique(distributions())) From 311cef4ab03cfd122bc4895094ab85b67f565406 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 20 Jun 2024 12:40:33 -0400 Subject: [PATCH 36/37] Finalize --- NEWS.rst | 10 ++++++++++ newsfragments/+.feature.rst | 1 - newsfragments/+76d2542b.feature.rst | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) delete mode 100644 newsfragments/+.feature.rst delete mode 100644 newsfragments/+76d2542b.feature.rst diff --git a/NEWS.rst b/NEWS.rst index 850e8f00..70f1eb38 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,13 @@ +v7.2.0 +====== + +Features +-------- + +- Deferred select imports in for speedup (python/cpython#109829). +- Updated fixtures for python/cpython#120801. + + v7.1.0 ====== diff --git a/newsfragments/+.feature.rst b/newsfragments/+.feature.rst deleted file mode 100644 index 26618684..00000000 --- a/newsfragments/+.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Deferred select imports in for speedup (python/cpython#109829). diff --git a/newsfragments/+76d2542b.feature.rst b/newsfragments/+76d2542b.feature.rst deleted file mode 100644 index 43b0e391..00000000 --- a/newsfragments/+76d2542b.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Updated fixtures for python/cpython#120801. From c9729e1a0f66b7adad70c629518b7dab82ccd8c6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 21 Jun 2024 13:09:07 -0400 Subject: [PATCH 37/37] Prefer "Source" to "Homepage" for the repository label. Closes jaraco/skeleton#129 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 50845ee3..ad67d3b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ dynamic = ["version"] [project.urls] -Homepage = "https://github.com/PROJECT_PATH" +Source = "https://github.com/PROJECT_PATH" [project.optional-dependencies] test = [