Skip to content

Commit f0f2024

Browse files
committed
⚫ Fade to black.
1 parent 50c72b2 commit f0f2024

File tree

8 files changed

+126
-126
lines changed

8 files changed

+126
-126
lines changed

importlib_metadata/__init__.py

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
NullFinder,
1818
PyPy_repr,
1919
install,
20-
)
20+
)
2121

2222
from configparser import ConfigParser
2323
from contextlib import suppress
@@ -37,7 +37,7 @@
3737
'metadata',
3838
'requires',
3939
'version',
40-
]
40+
]
4141

4242

4343
class PackageNotFoundError(ModuleNotFoundError):
@@ -49,13 +49,13 @@ def __str__(self):
4949

5050
@property
5151
def name(self):
52-
name, = self.args
52+
(name,) = self.args
5353
return name
5454

5555

5656
class EntryPoint(
57-
PyPy_repr,
58-
collections.namedtuple('EntryPointBase', 'name value group')):
57+
PyPy_repr, collections.namedtuple('EntryPointBase', 'name value group')
58+
):
5959
"""An entry point as defined by Python packaging conventions.
6060
6161
See `the packaging docs on entry points
@@ -67,7 +67,7 @@ class EntryPoint(
6767
r'(?P<module>[\w.]+)\s*'
6868
r'(:\s*(?P<attr>[\w.]+))?\s*'
6969
r'(?P<extras>\[.*\])?\s*$'
70-
)
70+
)
7171
"""
7272
A regular expression describing the syntax for an entry point,
7373
which might look like:
@@ -115,7 +115,7 @@ def _from_config(cls, config):
115115
cls(name, value, group)
116116
for group in config.sections()
117117
for name, value in config.items(group)
118-
]
118+
]
119119

120120
@classmethod
121121
def _from_text(cls, text):
@@ -139,7 +139,7 @@ def __reduce__(self):
139139
return (
140140
self.__class__,
141141
(self.name, self.value, self.group),
142-
)
142+
)
143143

144144

145145
class PackagePath(pathlib.PurePosixPath):
@@ -217,9 +217,8 @@ def discover(cls, **kwargs):
217217
raise ValueError("cannot accept context and kwargs")
218218
context = context or DistributionFinder.Context(**kwargs)
219219
return itertools.chain.from_iterable(
220-
resolver(context)
221-
for resolver in cls._discover_resolvers()
222-
)
220+
resolver(context) for resolver in cls._discover_resolvers()
221+
)
223222

224223
@staticmethod
225224
def at(path):
@@ -234,20 +233,20 @@ def at(path):
234233
def _discover_resolvers():
235234
"""Search the meta_path for resolvers."""
236235
declared = (
237-
getattr(finder, 'find_distributions', None)
238-
for finder in sys.meta_path
239-
)
236+
getattr(finder, 'find_distributions', None) for finder in sys.meta_path
237+
)
240238
return filter(None, declared)
241239

242240
@classmethod
243241
def _local(cls, root='.'):
244242
from pep517 import build, meta
243+
245244
system = build.compat_system(root)
246245
builder = functools.partial(
247246
meta.build,
248247
source_dir=root,
249248
system=system,
250-
)
249+
)
251250
return PathDistribution(zipp.Path(meta.build_as_zip(builder)))
252251

253252
@property
@@ -264,7 +263,7 @@ def metadata(self):
264263
# effect is to just end up using the PathDistribution's self._path
265264
# (which points to the egg-info file) attribute unchanged.
266265
or self.read_text('')
267-
)
266+
)
268267
return email.message_from_string(text)
269268

270269
@property
@@ -331,9 +330,10 @@ def _deps_from_requires_text(cls, source):
331330
section_pairs = cls._read_sections(source.splitlines())
332331
sections = {
333332
section: list(map(operator.itemgetter('line'), results))
334-
for section, results in
335-
itertools.groupby(section_pairs, operator.itemgetter('section'))
336-
}
333+
for section, results in itertools.groupby(
334+
section_pairs, operator.itemgetter('section')
335+
)
336+
}
337337
return cls._convert_egg_info_reqs_to_simple_reqs(sections)
338338

339339
@staticmethod
@@ -357,6 +357,7 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
357357
requirement. This method converts the former to the
358358
latter. See _test_deps_from_requires_text for an example.
359359
"""
360+
360361
def make_condition(name):
361362
return name and 'extra == "{name}"'.format(name=name)
362363

@@ -445,33 +446,35 @@ def zip_children(self):
445446
names = zip_path.root.namelist()
446447
self.joinpath = zip_path.joinpath
447448

448-
return dict.fromkeys(
449-
child.split(posixpath.sep, 1)[0]
450-
for child in names
451-
)
449+
return dict.fromkeys(child.split(posixpath.sep, 1)[0] for child in names)
452450

453451
def is_egg(self, search):
454452
base = self.base
455453
return (
456454
base == search.versionless_egg_name
457455
or base.startswith(search.prefix)
458-
and base.endswith('.egg'))
456+
and base.endswith('.egg')
457+
)
459458

460459
def search(self, name):
461460
for child in self.children():
462461
n_low = child.lower()
463-
if (n_low in name.exact_matches
464-
or n_low.startswith(name.prefix)
465-
and n_low.endswith(name.suffixes)
466-
# legacy case:
467-
or self.is_egg(name) and n_low == 'egg-info'):
462+
if (
463+
n_low in name.exact_matches
464+
or n_low.startswith(name.prefix)
465+
and n_low.endswith(name.suffixes)
466+
# legacy case:
467+
or self.is_egg(name)
468+
and n_low == 'egg-info'
469+
):
468470
yield self.joinpath(child)
469471

470472

471473
class Prepared:
472474
"""
473475
A prepared search for metadata on a possibly-named package.
474476
"""
477+
475478
normalized = ''
476479
prefix = ''
477480
suffixes = '.dist-info', '.egg-info'
@@ -484,8 +487,7 @@ def __init__(self, name):
484487
return
485488
self.normalized = name.lower().replace('-', '_')
486489
self.prefix = self.normalized + '-'
487-
self.exact_matches = [
488-
self.normalized + suffix for suffix in self.suffixes]
490+
self.exact_matches = [self.normalized + suffix for suffix in self.suffixes]
489491
self.versionless_egg_name = self.normalized + '.egg'
490492

491493

@@ -513,9 +515,8 @@ def find_distributions(self, context=DistributionFinder.Context()):
513515
def _search_paths(cls, name, paths):
514516
"""Find metadata directories in paths heuristically."""
515517
return itertools.chain.from_iterable(
516-
path.search(Prepared(name))
517-
for path in map(FastPath, paths)
518-
)
518+
path.search(Prepared(name)) for path in map(FastPath, paths)
519+
)
519520

520521

521522
class PathDistribution(Distribution):
@@ -528,9 +529,15 @@ def __init__(self, path):
528529
self._path = path
529530

530531
def read_text(self, filename):
531-
with suppress(FileNotFoundError, IsADirectoryError, KeyError,
532-
NotADirectoryError, PermissionError):
532+
with suppress(
533+
FileNotFoundError,
534+
IsADirectoryError,
535+
KeyError,
536+
NotADirectoryError,
537+
PermissionError,
538+
):
533539
return self._path.joinpath(filename).read_text(encoding='utf-8')
540+
534541
read_text.__doc__ = Distribution.read_text.__doc__
535542

536543
def locate_file(self, path):
@@ -578,15 +585,11 @@ def entry_points():
578585
579586
:return: EntryPoint objects for all installed packages.
580587
"""
581-
eps = itertools.chain.from_iterable(
582-
dist.entry_points for dist in distributions())
588+
eps = itertools.chain.from_iterable(dist.entry_points for dist in distributions())
583589
by_group = operator.attrgetter('group')
584590
ordered = sorted(eps, key=by_group)
585591
grouped = itertools.groupby(ordered, by_group)
586-
return {
587-
group: tuple(eps)
588-
for group, eps in grouped
589-
}
592+
return {group: tuple(eps) for group, eps in grouped}
590593

591594

592595
def files(distribution_name):

importlib_metadata/_compat.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ def disable_stdlib_finder():
2525
See #91 for more background for rationale on this sketchy
2626
behavior.
2727
"""
28+
2829
def matches(finder):
29-
return (
30-
getattr(finder, '__module__', None) == '_frozen_importlib_external'
31-
and hasattr(finder, 'find_distributions')
32-
)
30+
return getattr(
31+
finder, '__module__', None
32+
) == '_frozen_importlib_external' and hasattr(finder, 'find_distributions')
33+
3334
for finder in filter(matches, sys.meta_path): # pragma: nocover
3435
del finder.find_distributions
3536

@@ -39,6 +40,7 @@ class NullFinder:
3940
A "Finder" (aka "MetaClassFinder") that never finds any modules,
4041
but may find distributions.
4142
"""
43+
4244
@staticmethod
4345
def find_spec(*args, **kwargs):
4446
return None
@@ -57,12 +59,14 @@ class PyPy_repr:
5759
Override repr for EntryPoint objects on PyPy to avoid __iter__ access.
5860
Ref #97, #102.
5961
"""
62+
6063
affected = hasattr(sys, 'pypy_version_info')
6164

6265
def __compat_repr__(self): # pragma: nocover
6366
def make_param(name):
6467
value = getattr(self, name)
6568
return '{name}={value!r}'.format(**locals())
69+
6670
params = ', '.join(map(make_param, self._fields))
6771
return 'EntryPoint({params})'.format(**locals())
6872

prepare/example/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from setuptools import setup
2+
23
setup(
34
name='example',
45
version='21.12',
56
license='Apache Software License',
67
packages=['example'],
78
entry_points={
89
'console_scripts': ['example = example:main', 'Example=example:main'],
9-
},
10-
)
10+
},
11+
)

tests/fixtures.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ class DistInfoPkg(OnSysPath, SiteDir):
8686
[entries]
8787
main = mod:main
8888
ns:sub = mod:main
89-
"""
90-
},
89+
""",
90+
},
9191
"mod.py": """
9292
def main():
9393
print("hello world")
9494
""",
95-
}
95+
}
9696

9797
def setUp(self):
9898
super(DistInfoPkg, self).setUp()
@@ -129,13 +129,13 @@ class EggInfoPkg(OnSysPath, SiteDir):
129129
[test]
130130
pytest
131131
""",
132-
"top_level.txt": "mod\n"
133-
},
132+
"top_level.txt": "mod\n",
133+
},
134134
"mod.py": """
135135
def main():
136136
print("hello world")
137137
""",
138-
}
138+
}
139139

140140
def setUp(self):
141141
super(EggInfoPkg, self).setUp()
@@ -156,7 +156,7 @@ class EggInfoFile(OnSysPath, SiteDir):
156156
Description: UNKNOWN
157157
Platform: UNKNOWN
158158
""",
159-
}
159+
}
160160

161161
def setUp(self):
162162
super(EggInfoFile, self).setUp()
@@ -169,7 +169,7 @@ class LocalPackage:
169169
import setuptools
170170
setuptools.setup(name="local-pkg", version="2.0.1")
171171
""",
172-
}
172+
}
173173

174174
def setUp(self):
175175
self.fixtures = contextlib.ExitStack()
@@ -214,8 +214,7 @@ def build_files(file_defs, prefix=pathlib.Path()):
214214

215215
class FileBuilder:
216216
def unicode_filename(self):
217-
return FS_NONASCII or \
218-
self.skip("File system does not support non-ascii.")
217+
return FS_NONASCII or self.skip("File system does not support non-ascii.")
219218

220219

221220
def DALS(str):

0 commit comments

Comments
 (0)