Skip to content

Commit 52ce982

Browse files
authored
Merge branch 'main' into fix-relative-to
2 parents 1584b96 + e8998d9 commit 52ce982

File tree

19 files changed

+181
-119
lines changed

19 files changed

+181
-119
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ on:
44
merge_group:
55
push:
66
branches-ignore:
7-
# disabled for jaraco/skeleton#103
8-
# - gh-readonly-queue/** # Temporary merge queue-related GH-made branches
7+
# temporary GH branches relating to merge queues (jaraco/skeleton#93)
8+
- gh-readonly-queue/**
9+
tags:
10+
# required if branches-ignore is supplied (jaraco/skeleton#103)
11+
- '**'
912
pull_request:
1013

1114
permissions:
@@ -28,10 +31,10 @@ env:
2831
jobs:
2932
test:
3033
strategy:
34+
# https://blog.jaraco.com/efficient-use-of-ci-resources/
3135
matrix:
3236
python:
3337
- "3.8"
34-
- "3.11"
3538
- "3.12"
3639
platform:
3740
- ubuntu-latest
@@ -42,6 +45,8 @@ jobs:
4245
platform: ubuntu-latest
4346
- python: "3.10"
4447
platform: ubuntu-latest
48+
- python: "3.11"
49+
platform: ubuntu-latest
4550
- python: pypy3.10
4651
platform: ubuntu-latest
4752
runs-on: ${{ matrix.platform }}

.readthedocs.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ python:
33
install:
44
- path: .
55
extra_requirements:
6-
- docs
6+
- doc
77

88
# required boilerplate readthedocs/readthedocs.org#10401
99
build:
1010
os: ubuntu-lts-latest
1111
tools:
1212
python: latest
13+
# post-checkout job to ensure the clone isn't shallow jaraco/skeleton#114
14+
jobs:
15+
post_checkout:
16+
- git fetch --unshallow || true

NEWS.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
v7.2.0
2+
======
3+
4+
Features
5+
--------
6+
7+
- Deferred select imports in for speedup (python/cpython#109829).
8+
- Updated fixtures for python/cpython#120801.
9+
10+
11+
v7.1.0
12+
======
13+
14+
Features
15+
--------
16+
17+
- Improve import time (python/cpython#114664).
18+
19+
20+
Bugfixes
21+
--------
22+
23+
- Make MetadataPathFinder.find_distributions a classmethod for consistency with CPython. Closes #484. (#484)
24+
- Allow ``MetadataPathFinder.invalidate_caches`` to be called as a classmethod.
25+
26+
27+
v7.0.2
28+
======
29+
30+
No significant changes.
31+
32+
133
v7.0.1
234
======
335

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
url='https://peps.python.org/pep-{pep_number:0>4}/',
2626
),
2727
dict(
28-
pattern=r'(Python #|py-)(?P<python>\d+)',
28+
pattern=r'(python/cpython#|Python #|py-)(?P<python>\d+)',
2929
url='https://github.com/python/cpython/issues/{python}',
3030
),
3131
],

importlib_metadata/__init__.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import re
55
import abc
6-
import csv
76
import sys
87
import json
98
import zipp
@@ -19,8 +18,8 @@
1918
import posixpath
2019
import collections
2120

22-
from .compat.py311 import relative_fix
23-
from . import _adapters, _meta, _py39compat
21+
from . import _meta
22+
from .compat import py39, py311
2423
from ._collections import FreezableDefaultDict, Pair
2524
from ._compat import (
2625
NullFinder,
@@ -34,7 +33,7 @@
3433
from importlib import import_module
3534
from importlib.abc import MetaPathFinder
3635
from itertools import starmap
37-
from typing import Iterable, List, Mapping, Optional, Set, cast
36+
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast
3837

3938
__all__ = [
4039
'Distribution',
@@ -176,12 +175,12 @@ class EntryPoint:
176175
def __init__(self, name: str, value: str, group: str) -> None:
177176
vars(self).update(name=name, value=value, group=group)
178177

179-
def load(self):
178+
def load(self) -> Any:
180179
"""Load the entry point from its definition. If only a module
181180
is indicated by the value, return that module. Otherwise,
182181
return the named object.
183182
"""
184-
match = self.pattern.match(self.value)
183+
match = cast(Match, self.pattern.match(self.value))
185184
module = import_module(match.group('module'))
186185
attrs = filter(None, (match.group('attr') or '').split('.'))
187186
return functools.reduce(getattr, attrs, module)
@@ -276,12 +275,12 @@ def __repr__(self):
276275
"""
277276
return '%s(%r)' % (self.__class__.__name__, tuple(self))
278277

279-
def select(self, **params):
278+
def select(self, **params) -> EntryPoints:
280279
"""
281280
Select entry points from self that match the
282281
given parameters (typically group and/or name).
283282
"""
284-
return EntryPoints(ep for ep in self if _py39compat.ep_matches(ep, **params))
283+
return EntryPoints(ep for ep in self if py39.ep_matches(ep, **params))
285284

286285
@property
287286
def names(self) -> Set[str]:
@@ -462,6 +461,9 @@ def metadata(self) -> _meta.PackageMetadata:
462461
Custom providers may provide the METADATA file or override this
463462
property.
464463
"""
464+
# deferred for performance (python/cpython#109829)
465+
from . import _adapters
466+
465467
opt_text = (
466468
self.read_text('METADATA')
467469
or self.read_text('PKG-INFO')
@@ -523,6 +525,10 @@ def make_file(name, hash=None, size_str=None):
523525

524526
@pass_none
525527
def make_files(lines):
528+
# Delay csv import, since Distribution.files is not as widely used
529+
# as other parts of importlib.metadata
530+
import csv
531+
526532
return starmap(make_file, csv.reader(lines))
527533

528534
@pass_none
@@ -564,7 +570,7 @@ def _read_files_egginfo_installed(self):
564570
return
565571

566572
paths = (
567-
relative_fix((subdir / name).resolve())
573+
py311.relative_fix((subdir / name).resolve())
568574
.relative_to(self.locate_file('').resolve(), walk_up=True)
569575
.as_posix()
570576
for name in text.splitlines()
@@ -873,8 +879,9 @@ class MetadataPathFinder(NullFinder, DistributionFinder):
873879
of Python that do not have a PathFinder find_distributions().
874880
"""
875881

882+
@classmethod
876883
def find_distributions(
877-
self, context=DistributionFinder.Context()
884+
cls, context=DistributionFinder.Context()
878885
) -> Iterable[PathDistribution]:
879886
"""
880887
Find distributions.
@@ -884,7 +891,7 @@ def find_distributions(
884891
(or all names if ``None`` indicated) along the paths in the list
885892
of directories ``context.path``.
886893
"""
887-
found = self._search_paths(context.name, context.path)
894+
found = cls._search_paths(context.name, context.path)
888895
return map(PathDistribution, found)
889896

890897
@classmethod
@@ -895,6 +902,7 @@ def _search_paths(cls, name, paths):
895902
path.search(prepared) for path in map(FastPath, paths)
896903
)
897904

905+
@classmethod
898906
def invalidate_caches(cls) -> None:
899907
FastPath.__new__.cache_clear()
900908

@@ -992,7 +1000,7 @@ def version(distribution_name: str) -> str:
9921000

9931001
_unique = functools.partial(
9941002
unique_everseen,
995-
key=_py39compat.normalized_name,
1003+
key=py39.normalized_name,
9961004
)
9971005
"""
9981006
Wrapper for ``distributions`` to return unique distributions by name.

importlib_metadata/compat/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if TYPE_CHECKING: # pragma: no cover
88
# Prevent circular imports on runtime.
9-
from . import Distribution, EntryPoint
9+
from .. import Distribution, EntryPoint
1010
else:
1111
Distribution = EntryPoint = Any
1212

@@ -18,7 +18,7 @@ def normalized_name(dist: Distribution) -> Optional[str]:
1818
try:
1919
return dist._normalized_name
2020
except AttributeError:
21-
from . import Prepared # -> delay to prevent circular imports.
21+
from .. import Prepared # -> delay to prevent circular imports.
2222

2323
return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name'])
2424

@@ -30,7 +30,7 @@ def ep_matches(ep: EntryPoint, **params) -> bool:
3030
try:
3131
return ep.matches(**params)
3232
except AttributeError:
33-
from . import EntryPoint # -> delay to prevent circular imports.
33+
from .. import EntryPoint # -> delay to prevent circular imports.
3434

3535
# Reconstruct the EntryPoint object to make sure it is compatible.
3636
return EntryPoint(ep.name, ep.value, ep.group).matches(**params)

pyproject.toml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
[build-system]
2-
requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"]
2+
requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.1"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "importlib_metadata"
7+
authors = [
8+
{ name = "Jason R. Coombs", email = "[email protected]" },
9+
]
10+
description = "Read metadata from Python packages"
11+
readme = "README.rst"
12+
classifiers = [
13+
"Development Status :: 5 - Production/Stable",
14+
"Intended Audience :: Developers",
15+
"License :: OSI Approved :: Apache Software License",
16+
"Programming Language :: Python :: 3",
17+
"Programming Language :: Python :: 3 :: Only",
18+
]
19+
requires-python = ">=3.8"
20+
dependencies = [
21+
"zipp>=0.5",
22+
'typing-extensions>=3.6.4; python_version < "3.8"',
23+
]
24+
dynamic = ["version"]
25+
26+
[project.urls]
27+
Source = "https://github.com/python/importlib_metadata"
28+
29+
[project.optional-dependencies]
30+
test = [
31+
# upstream
32+
"pytest >= 6, != 8.1.*",
33+
"pytest-checkdocs >= 2.4",
34+
"pytest-cov",
35+
"pytest-mypy",
36+
"pytest-enabler >= 2.2",
37+
"pytest-ruff >= 0.2.1",
38+
39+
# local
40+
'importlib_resources>=1.3; python_version < "3.9"',
41+
"packaging",
42+
"pyfakefs",
43+
"flufl.flake8",
44+
"pytest-perf >= 0.9.2",
45+
"jaraco.test >= 5.4",
46+
]
47+
doc = [
48+
# upstream
49+
"sphinx >= 3.5",
50+
"jaraco.packaging >= 9.3",
51+
"rst.linker >= 1.9",
52+
"furo",
53+
"sphinx-lint",
54+
55+
# tidelift
56+
"jaraco.tidelift >= 1.4",
57+
58+
# local
59+
]
60+
perf = ["ipython"]
61+
562
[tool.setuptools_scm]

pytest.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[pytest]
22
norecursedirs=dist build .tox .eggs
3-
addopts=--doctest-modules
3+
addopts=
4+
--doctest-modules
5+
--import-mode importlib
6+
consider_namespace_packages=true
47
filterwarnings=
58
## upstream
69

setup.cfg

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)