Skip to content

Commit 09103e8

Browse files
authored
Merge pull request #10360 from pradyunsg/blacken-everything
Blacken the rest of the codebase, in one go
2 parents 08b62b6 + 585037a commit 09103e8

File tree

170 files changed

+9517
-8026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+9517
-8026
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ repos:
2020
rev: 21.7b0
2121
hooks:
2222
- id: black
23-
exclude: |
24-
(?x)
25-
^src/pip/_internal/models|
26-
^src/pip/_internal/operations|
27-
^src/pip/_internal/\w+\.py$|
28-
# Tests
29-
^tests/data|
30-
^tests/unit|
31-
^tests/functional/(?!test_install)|
32-
^tests/functional/test_install|
33-
# A blank ignore, to avoid merge conflicts later.
34-
^$
3523

3624
- repo: https://gitlab.com/pycqa/flake8
3725
rev: 3.8.4
@@ -40,6 +28,7 @@ repos:
4028
additional_dependencies: [
4129
'flake8-bugbear==20.1.4',
4230
'flake8-logging-format==0.6.0',
31+
'flake8-implicit-str-concat==0.2.0',
4332
]
4433
exclude: tests/data
4534

src/pip/_internal/build_env.py

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@
3131

3232

3333
class _Prefix:
34-
3534
def __init__(self, path: str) -> None:
3635
self.path = path
3736
self.setup = False
3837
self.bin_dir = get_paths(
39-
'nt' if os.name == 'nt' else 'posix_prefix',
40-
vars={'base': path, 'platbase': path}
41-
)['scripts']
38+
"nt" if os.name == "nt" else "posix_prefix",
39+
vars={"base": path, "platbase": path},
40+
)["scripts"]
4241
self.lib_dirs = get_prefixed_libs(path)
4342

4443

@@ -69,17 +68,14 @@ def _create_standalone_pip() -> Iterator[str]:
6968

7069

7170
class BuildEnvironment:
72-
"""Creates and manages an isolated environment to install build deps
73-
"""
71+
"""Creates and manages an isolated environment to install build deps"""
7472

7573
def __init__(self) -> None:
76-
temp_dir = TempDirectory(
77-
kind=tempdir_kinds.BUILD_ENV, globally_managed=True
78-
)
74+
temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
7975

8076
self._prefixes = OrderedDict(
8177
(name, _Prefix(os.path.join(temp_dir.path, name)))
82-
for name in ('normal', 'overlay')
78+
for name in ("normal", "overlay")
8379
)
8480

8581
self._bin_dirs: List[str] = []
@@ -94,12 +90,13 @@ def __init__(self) -> None:
9490
system_sites = {
9591
os.path.normcase(site) for site in (get_purelib(), get_platlib())
9692
}
97-
self._site_dir = os.path.join(temp_dir.path, 'site')
93+
self._site_dir = os.path.join(temp_dir.path, "site")
9894
if not os.path.exists(self._site_dir):
9995
os.mkdir(self._site_dir)
100-
with open(os.path.join(self._site_dir, 'sitecustomize.py'), 'w') as fp:
101-
fp.write(textwrap.dedent(
102-
'''
96+
with open(os.path.join(self._site_dir, "sitecustomize.py"), "w") as fp:
97+
fp.write(
98+
textwrap.dedent(
99+
"""
103100
import os, site, sys
104101
105102
# First, drop system-sites related paths.
@@ -122,33 +119,36 @@ def __init__(self) -> None:
122119
for path in {lib_dirs!r}:
123120
assert not path in sys.path
124121
site.addsitedir(path)
125-
'''
126-
).format(system_sites=system_sites, lib_dirs=self._lib_dirs))
122+
"""
123+
).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
124+
)
127125

128126
def __enter__(self) -> None:
129127
self._save_env = {
130128
name: os.environ.get(name, None)
131-
for name in ('PATH', 'PYTHONNOUSERSITE', 'PYTHONPATH')
129+
for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
132130
}
133131

134132
path = self._bin_dirs[:]
135-
old_path = self._save_env['PATH']
133+
old_path = self._save_env["PATH"]
136134
if old_path:
137135
path.extend(old_path.split(os.pathsep))
138136

139137
pythonpath = [self._site_dir]
140138

141-
os.environ.update({
142-
'PATH': os.pathsep.join(path),
143-
'PYTHONNOUSERSITE': '1',
144-
'PYTHONPATH': os.pathsep.join(pythonpath),
145-
})
139+
os.environ.update(
140+
{
141+
"PATH": os.pathsep.join(path),
142+
"PYTHONNOUSERSITE": "1",
143+
"PYTHONPATH": os.pathsep.join(pythonpath),
144+
}
145+
)
146146

147147
def __exit__(
148148
self,
149149
exc_type: Optional[Type[BaseException]],
150150
exc_val: Optional[BaseException],
151-
exc_tb: Optional[TracebackType]
151+
exc_tb: Optional[TracebackType],
152152
) -> None:
153153
for varname, old_value in self._save_env.items():
154154
if old_value is None:
@@ -160,8 +160,8 @@ def check_requirements(
160160
self, reqs: Iterable[str]
161161
) -> Tuple[Set[Tuple[str, str]], Set[str]]:
162162
"""Return 2 sets:
163-
- conflicting requirements: set of (installed, wanted) reqs tuples
164-
- missing requirements: set of reqs
163+
- conflicting requirements: set of (installed, wanted) reqs tuples
164+
- missing requirements: set of reqs
165165
"""
166166
missing = set()
167167
conflicting = set()
@@ -187,7 +187,7 @@ def install_requirements(
187187
finder: "PackageFinder",
188188
requirements: Iterable[str],
189189
prefix_as_string: str,
190-
message: str
190+
message: str,
191191
) -> None:
192192
prefix = self._prefixes[prefix_as_string]
193193
assert not prefix.setup
@@ -220,43 +220,51 @@ def _install_requirements(
220220
message: str,
221221
) -> None:
222222
args: List[str] = [
223-
sys.executable, pip_runnable, 'install',
224-
'--ignore-installed', '--no-user', '--prefix', prefix.path,
225-
'--no-warn-script-location',
223+
sys.executable,
224+
pip_runnable,
225+
"install",
226+
"--ignore-installed",
227+
"--no-user",
228+
"--prefix",
229+
prefix.path,
230+
"--no-warn-script-location",
226231
]
227232
if logger.getEffectiveLevel() <= logging.DEBUG:
228-
args.append('-v')
229-
for format_control in ('no_binary', 'only_binary'):
233+
args.append("-v")
234+
for format_control in ("no_binary", "only_binary"):
230235
formats = getattr(finder.format_control, format_control)
231-
args.extend(('--' + format_control.replace('_', '-'),
232-
','.join(sorted(formats or {':none:'}))))
236+
args.extend(
237+
(
238+
"--" + format_control.replace("_", "-"),
239+
",".join(sorted(formats or {":none:"})),
240+
)
241+
)
233242

234243
index_urls = finder.index_urls
235244
if index_urls:
236-
args.extend(['-i', index_urls[0]])
245+
args.extend(["-i", index_urls[0]])
237246
for extra_index in index_urls[1:]:
238-
args.extend(['--extra-index-url', extra_index])
247+
args.extend(["--extra-index-url", extra_index])
239248
else:
240-
args.append('--no-index')
249+
args.append("--no-index")
241250
for link in finder.find_links:
242-
args.extend(['--find-links', link])
251+
args.extend(["--find-links", link])
243252

244253
for host in finder.trusted_hosts:
245-
args.extend(['--trusted-host', host])
254+
args.extend(["--trusted-host", host])
246255
if finder.allow_all_prereleases:
247-
args.append('--pre')
256+
args.append("--pre")
248257
if finder.prefer_binary:
249-
args.append('--prefer-binary')
250-
args.append('--')
258+
args.append("--prefer-binary")
259+
args.append("--")
251260
args.extend(requirements)
252261
extra_environ = {"_PIP_STANDALONE_CERT": where()}
253262
with open_spinner(message) as spinner:
254263
call_subprocess(args, spinner=spinner, extra_environ=extra_environ)
255264

256265

257266
class NoOpBuildEnvironment(BuildEnvironment):
258-
"""A no-op drop-in replacement for BuildEnvironment
259-
"""
267+
"""A no-op drop-in replacement for BuildEnvironment"""
260268

261269
def __init__(self) -> None:
262270
pass
@@ -268,7 +276,7 @@ def __exit__(
268276
self,
269277
exc_type: Optional[Type[BaseException]],
270278
exc_val: Optional[BaseException],
271-
exc_tb: Optional[TracebackType]
279+
exc_tb: Optional[TracebackType],
272280
) -> None:
273281
pass
274282

@@ -280,6 +288,6 @@ def install_requirements(
280288
finder: "PackageFinder",
281289
requirements: Iterable[str],
282290
prefix_as_string: str,
283-
message: str
291+
message: str,
284292
) -> None:
285293
raise NotImplementedError()

src/pip/_internal/cache.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class Cache:
3030
"""An abstract class - provides cache directories for data from links
3131
3232
33-
:param cache_dir: The root of the cache.
34-
:param format_control: An object of FormatControl class to limit
35-
binaries being read from the cache.
36-
:param allowed_formats: which formats of files the cache should store.
37-
('binary' and 'source' are the only allowed values)
33+
:param cache_dir: The root of the cache.
34+
:param format_control: An object of FormatControl class to limit
35+
binaries being read from the cache.
36+
:param allowed_formats: which formats of files the cache should store.
37+
('binary' and 'source' are the only allowed values)
3838
"""
3939

4040
def __init__(
@@ -50,8 +50,7 @@ def __init__(
5050
assert self.allowed_formats.union(_valid_formats) == _valid_formats
5151

5252
def _get_cache_path_parts(self, link: Link) -> List[str]:
53-
"""Get parts of part that must be os.path.joined with cache_dir
54-
"""
53+
"""Get parts of part that must be os.path.joined with cache_dir"""
5554

5655
# We want to generate an url to use as our cache key, we don't want to
5756
# just re-use the URL because it might have other items in the fragment
@@ -84,17 +83,11 @@ def _get_cache_path_parts(self, link: Link) -> List[str]:
8483
return parts
8584

8685
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
87-
can_not_cache = (
88-
not self.cache_dir or
89-
not canonical_package_name or
90-
not link
91-
)
86+
can_not_cache = not self.cache_dir or not canonical_package_name or not link
9287
if can_not_cache:
9388
return []
9489

95-
formats = self.format_control.get_allowed_formats(
96-
canonical_package_name
97-
)
90+
formats = self.format_control.get_allowed_formats(canonical_package_name)
9891
if not self.allowed_formats.intersection(formats):
9992
return []
10093

@@ -106,8 +99,7 @@ def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
10699
return candidates
107100

108101
def get_path_for_link(self, link: Link) -> str:
109-
"""Return a directory to store cached items in for link.
110-
"""
102+
"""Return a directory to store cached items in for link."""
111103
raise NotImplementedError()
112104

113105
def get(
@@ -123,8 +115,7 @@ def get(
123115

124116

125117
class SimpleWheelCache(Cache):
126-
"""A cache of wheels for future installs.
127-
"""
118+
"""A cache of wheels for future installs."""
128119

129120
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
130121
super().__init__(cache_dir, format_control, {"binary"})
@@ -161,9 +152,7 @@ def get(
161152
return link
162153

163154
canonical_package_name = canonicalize_name(package_name)
164-
for wheel_name, wheel_dir in self._get_candidates(
165-
link, canonical_package_name
166-
):
155+
for wheel_name, wheel_dir in self._get_candidates(link, canonical_package_name):
167156
try:
168157
wheel = Wheel(wheel_name)
169158
except InvalidWheelFilename:
@@ -172,7 +161,9 @@ def get(
172161
logger.debug(
173162
"Ignoring cached wheel %s for %s as it "
174163
"does not match the expected distribution name %s.",
175-
wheel_name, link, package_name,
164+
wheel_name,
165+
link,
166+
package_name,
176167
)
177168
continue
178169
if not wheel.supported(supported_tags):
@@ -194,8 +185,7 @@ def get(
194185

195186

196187
class EphemWheelCache(SimpleWheelCache):
197-
"""A SimpleWheelCache that creates it's own temporary cache directory
198-
"""
188+
"""A SimpleWheelCache that creates it's own temporary cache directory"""
199189

200190
def __init__(self, format_control: FormatControl) -> None:
201191
self._temp_dir = TempDirectory(
@@ -224,7 +214,7 @@ class WheelCache(Cache):
224214
"""
225215

226216
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
227-
super().__init__(cache_dir, format_control, {'binary'})
217+
super().__init__(cache_dir, format_control, {"binary"})
228218
self._wheel_cache = SimpleWheelCache(cache_dir, format_control)
229219
self._ephem_cache = EphemWheelCache(format_control)
230220

0 commit comments

Comments
 (0)