Skip to content

Commit 729990c

Browse files
authored
Round 1 of Cleanups (#4844)
* misc: fix typo * misc: 🎨 cleanup parenthesis * misc: 🎨 minor simplifications * tests: fix test_console_to_str_warning
1 parent 094afef commit 729990c

20 files changed

+79
-53
lines changed

src/pip/_internal/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
except ImportError:
3030
pass
3131
else:
32-
if (sys.platform == "darwin" and
33-
ssl.OPENSSL_VERSION_NUMBER < 0x1000100f): # OpenSSL 1.0.1
32+
# Checks for OpenSSL 1.0.1 on MacOS
33+
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
3434
try:
3535
from pip._vendor.urllib3.contrib import securetransport
3636
except (ImportError, OSError):
@@ -148,7 +148,8 @@ def create_main_parser():
148148

149149
pip_pkg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
150150
parser.version = 'pip %s from %s (python %s)' % (
151-
__version__, pip_pkg_dir, sys.version[:3])
151+
__version__, pip_pkg_dir, sys.version[:3],
152+
)
152153

153154
# add the general options
154155
gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)

src/pip/_internal/cmdoptions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def getname(n):
5656
fmt_ctl_no_binary(control)
5757
warnings.warn(
5858
'Disabling all use of wheels due to the use of --build-options '
59-
'/ --global-options / --install-options.', stacklevel=2)
59+
'/ --global-options / --install-options.', stacklevel=2,
60+
)
6061

6162

6263
###########
@@ -366,13 +367,15 @@ def _get_format_control(values, option):
366367
def _handle_no_binary(option, opt_str, value, parser):
367368
existing = getattr(parser.values, option.dest)
368369
fmt_ctl_handle_mutual_exclude(
369-
value, existing.no_binary, existing.only_binary)
370+
value, existing.no_binary, existing.only_binary,
371+
)
370372

371373

372374
def _handle_only_binary(option, opt_str, value, parser):
373375
existing = getattr(parser.values, option.dest)
374376
fmt_ctl_handle_mutual_exclude(
375-
value, existing.only_binary, existing.no_binary)
377+
value, existing.only_binary, existing.no_binary,
378+
)
376379

377380

378381
def no_binary():

src/pip/_internal/commands/check.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def run(self, options, args):
2222
for requirement in missing_reqs_dict.get(dist.key, []):
2323
logger.info(
2424
"%s %s requires %s, which is not installed.",
25-
dist.project_name, dist.version, requirement.project_name)
25+
dist.project_name, dist.version, requirement.project_name,
26+
)
2627

2728
for requirement, actual in incompatible_reqs_dict.get(
2829
dist.key, []):
2930
logger.info(
3031
"%s %s has requirement %s, but you have %s %s.",
3132
dist.project_name, dist.version, requirement,
32-
actual.project_name, actual.version)
33+
actual.project_name, actual.version,
34+
)
3335

3436
if missing_reqs_dict or incompatible_reqs_dict:
3537
return 1

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def run(self, options, args):
222222
req.name for req in requirement_set.successfully_downloaded
223223
])
224224
if downloaded:
225-
logger.info(
226-
'Successfully downloaded %s', downloaded
227-
)
225+
logger.info('Successfully downloaded %s', downloaded)
228226

229227
# Clean up
230228
if not options.no_clean:

src/pip/_internal/commands/freeze.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def run(self, options, args):
8686
isolated=options.isolated_mode,
8787
wheel_cache=wheel_cache,
8888
skip=skip,
89-
exclude_editable=options.exclude_editable)
89+
exclude_editable=options.exclude_editable,
90+
)
9091

9192
for line in freeze(**freeze_kwargs):
9293
sys.stdout.write(line + '\n')

src/pip/_internal/compat.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def backslashreplace_decode_fn(err):
6060
return u"".join(u"\\x%x" % c for c in raw_bytes), err.end
6161
codecs.register_error(
6262
"backslashreplace_decode",
63-
backslashreplace_decode_fn)
63+
backslashreplace_decode_fn,
64+
)
6465
backslashreplace_decode = "backslashreplace_decode"
6566

6667

@@ -88,8 +89,9 @@ def console_to_str(data):
8889
s = data.decode(encoding)
8990
except UnicodeDecodeError:
9091
logger.warning(
91-
"Subprocess output does not appear to be encoded as %s" %
92-
encoding)
92+
"Subprocess output does not appear to be encoded as %s",
93+
encoding,
94+
)
9395
s = data.decode(encoding, errors=backslashreplace_decode)
9496

9597
# Make sure we can print the output, by encoding it to the output

src/pip/_internal/download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ def __init__(self, *args, **kwargs):
348348
# connection got interrupted in some way. A 503 error in general
349349
# is typically considered a transient error so we'll go ahead and
350350
# retry it.
351-
# A 500 may indicate transient errror in Amazon S3
352-
# A 520 or 527 - may indicate transient errror in CloudFlare
351+
# A 500 may indicate transient error in Amazon S3
352+
# A 520 or 527 - may indicate transient error in CloudFlare
353353
status_forcelist=[500, 503, 520, 527],
354354

355355
# Add a small amount of back off between failed requests in

src/pip/_internal/index.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,16 @@ def sort_path(path):
253253
else:
254254
logger.warning(
255255
"Url '%s' is ignored: it is neither a file "
256-
"nor a directory.", url)
256+
"nor a directory.", url,
257+
)
257258
elif is_url(url):
258259
# Only add url with clear scheme
259260
urls.append(url)
260261
else:
261262
logger.warning(
262263
"Url '%s' is ignored. It is either a non-existing "
263-
"path or lacks a specific scheme.", url)
264+
"path or lacks a specific scheme.", url,
265+
)
264266

265267
return files, urls
266268

@@ -400,13 +402,13 @@ def find_all_candidates(self, project_name):
400402
index_locations = self._get_index_urls_locations(project_name)
401403
index_file_loc, index_url_loc = self._sort_locations(index_locations)
402404
fl_file_loc, fl_url_loc = self._sort_locations(
403-
self.find_links, expand_dir=True)
405+
self.find_links, expand_dir=True,
406+
)
404407
dep_file_loc, dep_url_loc = self._sort_locations(self.dependency_links)
405408

406-
file_locations = (
407-
Link(url) for url in itertools.chain(
408-
index_file_loc, fl_file_loc, dep_file_loc)
409-
)
409+
file_locations = (Link(url) for url in itertools.chain(
410+
index_file_loc, fl_file_loc, dep_file_loc,
411+
))
410412

411413
# We trust every url that the user has given us whether it was given
412414
# via --index-url or --find-links
@@ -632,11 +634,13 @@ def _link_package_versions(self, link, search):
632634
return
633635
if ext not in SUPPORTED_EXTENSIONS:
634636
self._log_skipped_link(
635-
link, 'unsupported archive format: %s' % ext)
637+
link, 'unsupported archive format: %s' % ext,
638+
)
636639
return
637640
if "binary" not in search.formats and ext == wheel_ext:
638641
self._log_skipped_link(
639-
link, 'No binaries permitted for %s' % search.supplied)
642+
link, 'No binaries permitted for %s' % search.supplied,
643+
)
640644
return
641645
if "macosx10" in link.path and ext == '.zip':
642646
self._log_skipped_link(link, 'macosx10 one')
@@ -662,7 +666,8 @@ def _link_package_versions(self, link, search):
662666
# This should be up by the search.ok_binary check, but see issue 2700.
663667
if "source" not in search.formats and ext != wheel_ext:
664668
self._log_skipped_link(
665-
link, 'No sources permitted for %s' % search.supplied)
669+
link, 'No sources permitted for %s' % search.supplied,
670+
)
666671
return
667672

668673
if not version:
@@ -829,8 +834,8 @@ def get_page(cls, link, skip_archives=True, session=None):
829834
except requests.HTTPError as exc:
830835
cls._handle_fail(link, exc, url)
831836
except SSLError as exc:
832-
reason = ("There was a problem confirming the ssl certificate: "
833-
"%s" % exc)
837+
reason = "There was a problem confirming the ssl certificate: "
838+
reason += str(exc)
834839
cls._handle_fail(link, reason, url, meth=logger.info)
835840
except requests.ConnectionError as exc:
836841
cls._handle_fail(link, "connection error: %s" % exc, url)
@@ -1098,7 +1103,8 @@ def fmt_ctl_formats(fmt_ctl, canonical_name):
10981103

10991104
def fmt_ctl_no_binary(fmt_ctl):
11001105
fmt_ctl_handle_mutual_exclude(
1101-
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary)
1106+
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary,
1107+
)
11021108

11031109

11041110
Search = namedtuple('Search', 'supplied canonical formats')

src/pip/_internal/operations/check.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def check_requirements(installed_dists):
99
if missing_reqs:
1010
missing_reqs_dict[dist.key] = missing_reqs
1111

12-
incompatible_reqs = list(get_incompatible_reqs(
13-
dist, installed_dists))
12+
incompatible_reqs = list(get_incompatible_reqs(dist, installed_dists))
1413
if incompatible_reqs:
1514
incompatible_reqs_dict[dist.key] = incompatible_reqs
1615

src/pip/_internal/operations/freeze.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def from_dist(cls, dist, dependency_links):
209209
)
210210
if not svn_location:
211211
logger.warning(
212-
'Warning: cannot find svn location for %s', req)
212+
'Warning: cannot find svn location for %s', req,
213+
)
213214
comments.append(
214215
'## FIXME: could not find svn URL in dependency_links '
215216
'for this package:'

src/pip/_internal/req/req_file.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def process_line(line, filename, line_number, finder=None, comes_from=None,
131131

132132
# preserve for the nested code path
133133
line_comes_from = '%s %s (line %s)' % (
134-
'-c' if constraint else '-r', filename, line_number)
134+
'-c' if constraint else '-r', filename, line_number,
135+
)
135136

136137
# yield a line requirement
137138
if args_str:
@@ -299,7 +300,5 @@ def skip_regex(lines_enum, options):
299300
skip_regex = options.skip_requirements_regex if options else None
300301
if skip_regex:
301302
pattern = re.compile(skip_regex)
302-
lines_enum = filterfalse(
303-
lambda e: pattern.search(e[1]),
304-
lines_enum)
303+
lines_enum = filterfalse(lambda e: pattern.search(e[1]), lines_enum)
305304
return lines_enum

src/pip/_internal/req/req_install.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ def install(self, install_options, global_options=None, root=None,
729729
global_options = global_options if global_options is not None else []
730730
if self.editable:
731731
self.install_editable(
732-
install_options, global_options, prefix=prefix)
732+
install_options, global_options, prefix=prefix,
733+
)
733734
return
734735
if self.is_wheel:
735736
version = wheel.wheel_version(self.source_dir)
@@ -756,7 +757,8 @@ def install(self, install_options, global_options=None, root=None,
756757
with TempDirectory(kind="record") as temp_dir:
757758
record_filename = os.path.join(temp_dir.path, 'install-record.txt')
758759
install_args = self.get_install_args(
759-
global_options, record_filename, root, prefix)
760+
global_options, record_filename, root, prefix,
761+
)
760762
msg = 'Running setup.py install for %s' % (self.name,)
761763
with open_spinner(msg) as spinner:
762764
with indent_log():
@@ -882,7 +884,8 @@ def install_editable(self, install_options,
882884
list(install_options),
883885

884886
cwd=self.setup_py_dir,
885-
show_stdout=False)
887+
show_stdout=False,
888+
)
886889

887890
self.install_succeeded = True
888891

@@ -953,7 +956,8 @@ def get_dist(self):
953956
return pkg_resources.Distribution(
954957
os.path.dirname(egg_info),
955958
project_name=dist_name,
956-
metadata=metadata)
959+
metadata=metadata,
960+
)
957961

958962
@property
959963
def has_hash_options(self):

src/pip/_internal/req/req_set.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def add_requirement(self, install_req, parent_req_name=None,
120120
raise InstallationError(
121121
"Could not satisfy constraints for '%s': "
122122
"installation from path or url cannot be "
123-
"constrained to a version" % name)
123+
"constrained to a version" % name,
124+
)
124125
# If we're now installing a constraint, mark the existing
125126
# object for real installation.
126127
existing_req.constraint = False

src/pip/_internal/req/req_uninstall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ def from_dist(cls, dist):
371371
else:
372372
logger.debug(
373373
'Not sure how to uninstall: %s - Check: %s',
374-
dist, dist.location)
374+
dist, dist.location,
375+
)
375376

376377
# find distutils scripts= scripts
377378
if dist.has_metadata('scripts') and dist.metadata_isdir('scripts'):

src/pip/_internal/utils/misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ def call_subprocess(cmd, show_stdout=True, cwd=None,
679679
try:
680680
proc = subprocess.Popen(
681681
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
682-
cwd=cwd, env=env)
682+
cwd=cwd, env=env,
683+
)
683684
except Exception as exc:
684685
logger.critical(
685686
"Error %s while executing command %s", exc, command_desc,

src/pip/_internal/utils/packaging.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ def check_dist_requires_python(dist):
5656
)
5757
except specifiers.InvalidSpecifier as e:
5858
logger.warning(
59-
"Package %s has an invalid Requires-Python entry %s - %s" % (
60-
dist.project_name, requires_python, e))
59+
"Package %s has an invalid Requires-Python entry %s - %s",
60+
dist.project_name, requires_python, e,
61+
)
6162
return
6263

6364

src/pip/_internal/vcs/bazaar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def get_url(self, location):
9191

9292
def get_revision(self, location):
9393
revision = self.run_command(
94-
['revno'], show_stdout=False, cwd=location)
94+
['revno'], show_stdout=False, cwd=location,
95+
)
9596
return revision.splitlines()[-1]
9697

9798
def get_src_requirement(self, dist, location):

src/pip/_internal/vcs/git.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def get_url(self, location):
205205
"""Return URL of the first remote encountered."""
206206
remotes = self.run_command(
207207
['config', '--get-regexp', r'remote\..*\.url'],
208-
show_stdout=False, cwd=location)
208+
show_stdout=False, cwd=location,
209+
)
209210
remotes = remotes.splitlines()
210211
found_remote = remotes[0]
211212
for remote in remotes:
@@ -217,7 +218,8 @@ def get_url(self, location):
217218

218219
def get_revision(self, location):
219220
current_rev = self.run_command(
220-
['rev-parse', 'HEAD'], show_stdout=False, cwd=location)
221+
['rev-parse', 'HEAD'], show_stdout=False, cwd=location,
222+
)
221223
return current_rev.strip()
222224

223225
def _get_subdirectory(self, location):

src/pip/_internal/wheel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ def build(self, requirements, session, autobuilding=False):
811811
if req.is_wheel:
812812
if not autobuilding:
813813
logger.info(
814-
'Skipping %s, due to already being wheel.', req.name)
814+
'Skipping %s, due to already being wheel.', req.name,
815+
)
815816
elif autobuilding and req.editable:
816817
pass
817818
elif autobuilding and req.link and not req.link.is_artifact:
@@ -831,7 +832,8 @@ def build(self, requirements, session, autobuilding=False):
831832
canonicalize_name(req.name)):
832833
logger.info(
833834
"Skipping bdist_wheel for %s, due to binaries "
834-
"being disabled for it.", req.name)
835+
"being disabled for it.", req.name,
836+
)
835837
continue
836838
buildset.append(req)
837839

@@ -888,7 +890,8 @@ def build(self, requirements, session, autobuilding=False):
888890
# extract the wheel into the dir
889891
unpack_url(
890892
req.link, req.source_dir, None, False,
891-
session=session)
893+
session=session,
894+
)
892895
else:
893896
build_failure.append(req)
894897

tests/unit/test_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_console_to_str(monkeypatch):
5959
def test_console_to_str_warning(monkeypatch):
6060
some_bytes = b"a\xE9b"
6161

62-
def check_warning(msg):
62+
def check_warning(msg, *args, **kwargs):
6363
assert msg.startswith(
6464
"Subprocess output does not appear to be encoded as")
6565

0 commit comments

Comments
 (0)