Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit049460d

Browse files
authored
bpo-37697: Sync with importlib_metadata 0.19 (#14993)
*bpo-37697: Sync with importlib_metadata 0.19* Run make regen-importlib* 📜🤖 Added by blurb_it.
1 parentb222955 commit049460d

File tree

7 files changed

+841
-794
lines changed

7 files changed

+841
-794
lines changed

‎Lib/importlib/_bootstrap_external.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,6 @@ def find_module(cls, fullname, path=None):
13671367
returnNone
13681368
returnspec.loader
13691369

1370-
search_template=r'(?:{pattern}(-.*)?\.(dist|egg)-info|EGG-INFO)'
1371-
13721370
@classmethod
13731371
deffind_distributions(cls,name=None,path=None):
13741372
"""
@@ -1400,24 +1398,35 @@ def _search_paths(cls, pattern, paths):
14001398
def_switch_path(path):
14011399
fromcontextlibimportsuppress
14021400
importzipfile
1403-
frompathlibimportPath
1404-
withsuppress(Exception):
1405-
returnzipfile.Path(path)
1406-
returnPath(path)
1401+
importpathlib
1402+
PYPY_OPEN_BUG=False
1403+
ifnotPYPY_OPEN_BUGoros.path.isfile(path):# pragma: no branch
1404+
withsuppress(Exception):
1405+
returnzipfile.Path(path)
1406+
returnpathlib.Path(path)
1407+
1408+
@classmethod
1409+
def_matches_info(cls,normalized,item):
1410+
importre
1411+
template=r'{pattern}(-.*)?\.(dist|egg)-info'
1412+
manifest=template.format(pattern=normalized)
1413+
returnre.match(manifest,item.name,flags=re.IGNORECASE)
14071414

14081415
@classmethod
1409-
def_predicate(cls,pattern,root,item):
1416+
def_matches_legacy(cls,normalized,item):
14101417
importre
1411-
returnre.match(pattern,str(item.name),flags=re.IGNORECASE)
1418+
template=r'{pattern}-.*\.egg[\\/]EGG-INFO'
1419+
manifest=template.format(pattern=normalized)
1420+
returnre.search(manifest,str(item),flags=re.IGNORECASE)
14121421

14131422
@classmethod
14141423
def_search_path(cls,root,pattern):
14151424
ifnotroot.is_dir():
14161425
return ()
14171426
normalized=pattern.replace('-','_')
1418-
matcher=cls.search_template.format(pattern=normalized)
14191427
return (itemforiteminroot.iterdir()
1420-
ifcls._predicate(matcher,root,item))
1428+
ifcls._matches_info(normalized,item)
1429+
orcls._matches_legacy(normalized,item))
14211430

14221431

14231432
classFileFinder:

‎Lib/importlib/metadata/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _from_config(cls, config):
8888

8989
@classmethod
9090
def_from_text(cls,text):
91-
config=ConfigParser()
91+
config=ConfigParser(delimiters='=')
9292
# case sensitive: https://stackoverflow.com/q/1611799/812183
9393
config.optionxform=str
9494
try:

‎Lib/test/test_importlib/fixtures.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class DistInfoPkg(OnSysPath, SiteDir):
8383
"entry_points.txt":"""
8484
[entries]
8585
main = mod:main
86+
ns:sub = mod:main
8687
"""
8788
},
8889
"mod.py":"""

‎Lib/test/test_importlib/test_main.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_new_style_classes(self):
3232
classImportTests(fixtures.DistInfoPkg,unittest.TestCase):
3333
deftest_import_nonexistent_module(self):
3434
# Ensure that the MetadataPathFinder does not crash an import of a
35-
#nonexistent module.
35+
#non-existant module.
3636
withself.assertRaises(ImportError):
3737
importlib.import_module('does_not_exist')
3838

@@ -41,6 +41,11 @@ def test_resolve(self):
4141
ep=entries['main']
4242
self.assertEqual(ep.load().__name__,"main")
4343

44+
deftest_entrypoint_with_colon_in_name(self):
45+
entries=dict(entry_points()['entries'])
46+
ep=entries['ns:sub']
47+
self.assertEqual(ep.value,'mod:main')
48+
4449
deftest_resolve_without_attr(self):
4550
ep=EntryPoint(
4651
name='ep',
@@ -159,8 +164,16 @@ def test_package_discovery(self):
159164

160165

161166
classDirectoryTest(fixtures.OnSysPath,fixtures.SiteDir,unittest.TestCase):
162-
deftest(self):
167+
deftest_egg_info(self):
163168
# make an `EGG-INFO` directory that's unrelated
164169
self.site_dir.joinpath('EGG-INFO').mkdir()
165170
# used to crash with `IsADirectoryError`
166-
self.assertIsNone(version('unknown-package'))
171+
withself.assertRaises(PackageNotFoundError):
172+
version('unknown-package')
173+
174+
deftest_egg(self):
175+
egg=self.site_dir.joinpath('foo-3.6.egg')
176+
egg.mkdir()
177+
withself.add_sys_path(egg):
178+
withself.assertRaises(PackageNotFoundError):
179+
version('foo')

‎Lib/test/test_importlib/test_zip.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
importunittest
33

44
fromcontextlibimportExitStack
5-
fromimportlib.metadataimportdistribution,entry_points,files,version
5+
fromimportlib.metadataimport (
6+
distribution,entry_points,files,PackageNotFoundError,version,
7+
)
68
fromimportlib.resourcesimportpath
79

810

@@ -22,6 +24,10 @@ def setUp(self):
2224
deftest_zip_version(self):
2325
self.assertEqual(version('example'),'21.12')
2426

27+
deftest_zip_version_does_not_match(self):
28+
withself.assertRaises(PackageNotFoundError):
29+
version('definitely-not-installed')
30+
2531
deftest_zip_entry_points(self):
2632
scripts=dict(entry_points()['console_scripts'])
2733
entry_point=scripts['example']
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Syncronize ``importlib.metadata`` with `importlib_metadata 0.19<https://gitlab.com/python-devs/importlib_metadata/-/milestones/20>`_, improving handling of EGG-INFO files and fixing a crash when entry point names contained colons.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp