Skip to content

Commit

Permalink
Round 1 of Cleanups (#4844)
Browse files Browse the repository at this point in the history
* misc: fix typo
* misc: 🎨 cleanup parenthesis
* misc: 🎨 minor simplifications
* tests: fix test_console_to_str_warning
  • Loading branch information
pradyunsg authored Dec 25, 2017
1 parent 094afef commit 729990c
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 53 deletions.
7 changes: 4 additions & 3 deletions src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
except ImportError:
pass
else:
if (sys.platform == "darwin" and
ssl.OPENSSL_VERSION_NUMBER < 0x1000100f): # OpenSSL 1.0.1
# Checks for OpenSSL 1.0.1 on MacOS
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
try:
from pip._vendor.urllib3.contrib import securetransport
except (ImportError, OSError):
Expand Down Expand Up @@ -148,7 +148,8 @@ def create_main_parser():

pip_pkg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
parser.version = 'pip %s from %s (python %s)' % (
__version__, pip_pkg_dir, sys.version[:3])
__version__, pip_pkg_dir, sys.version[:3],
)

# add the general options
gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
Expand Down
9 changes: 6 additions & 3 deletions src/pip/_internal/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def getname(n):
fmt_ctl_no_binary(control)
warnings.warn(
'Disabling all use of wheels due to the use of --build-options '
'/ --global-options / --install-options.', stacklevel=2)
'/ --global-options / --install-options.', stacklevel=2,
)


###########
Expand Down Expand Up @@ -366,13 +367,15 @@ def _get_format_control(values, option):
def _handle_no_binary(option, opt_str, value, parser):
existing = getattr(parser.values, option.dest)
fmt_ctl_handle_mutual_exclude(
value, existing.no_binary, existing.only_binary)
value, existing.no_binary, existing.only_binary,
)


def _handle_only_binary(option, opt_str, value, parser):
existing = getattr(parser.values, option.dest)
fmt_ctl_handle_mutual_exclude(
value, existing.only_binary, existing.no_binary)
value, existing.only_binary, existing.no_binary,
)


def no_binary():
Expand Down
6 changes: 4 additions & 2 deletions src/pip/_internal/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def run(self, options, args):
for requirement in missing_reqs_dict.get(dist.key, []):
logger.info(
"%s %s requires %s, which is not installed.",
dist.project_name, dist.version, requirement.project_name)
dist.project_name, dist.version, requirement.project_name,
)

for requirement, actual in incompatible_reqs_dict.get(
dist.key, []):
logger.info(
"%s %s has requirement %s, but you have %s %s.",
dist.project_name, dist.version, requirement,
actual.project_name, actual.version)
actual.project_name, actual.version,
)

if missing_reqs_dict or incompatible_reqs_dict:
return 1
Expand Down
4 changes: 1 addition & 3 deletions src/pip/_internal/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ def run(self, options, args):
req.name for req in requirement_set.successfully_downloaded
])
if downloaded:
logger.info(
'Successfully downloaded %s', downloaded
)
logger.info('Successfully downloaded %s', downloaded)

# Clean up
if not options.no_clean:
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def run(self, options, args):
isolated=options.isolated_mode,
wheel_cache=wheel_cache,
skip=skip,
exclude_editable=options.exclude_editable)
exclude_editable=options.exclude_editable,
)

for line in freeze(**freeze_kwargs):
sys.stdout.write(line + '\n')
8 changes: 5 additions & 3 deletions src/pip/_internal/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def backslashreplace_decode_fn(err):
return u"".join(u"\\x%x" % c for c in raw_bytes), err.end
codecs.register_error(
"backslashreplace_decode",
backslashreplace_decode_fn)
backslashreplace_decode_fn,
)
backslashreplace_decode = "backslashreplace_decode"


Expand Down Expand Up @@ -88,8 +89,9 @@ def console_to_str(data):
s = data.decode(encoding)
except UnicodeDecodeError:
logger.warning(
"Subprocess output does not appear to be encoded as %s" %
encoding)
"Subprocess output does not appear to be encoded as %s",
encoding,
)
s = data.decode(encoding, errors=backslashreplace_decode)

# Make sure we can print the output, by encoding it to the output
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ def __init__(self, *args, **kwargs):
# connection got interrupted in some way. A 503 error in general
# is typically considered a transient error so we'll go ahead and
# retry it.
# A 500 may indicate transient errror in Amazon S3
# A 520 or 527 - may indicate transient errror in CloudFlare
# A 500 may indicate transient error in Amazon S3
# A 520 or 527 - may indicate transient error in CloudFlare
status_forcelist=[500, 503, 520, 527],

# Add a small amount of back off between failed requests in
Expand Down
32 changes: 19 additions & 13 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,16 @@ def sort_path(path):
else:
logger.warning(
"Url '%s' is ignored: it is neither a file "
"nor a directory.", url)
"nor a directory.", url,
)
elif is_url(url):
# Only add url with clear scheme
urls.append(url)
else:
logger.warning(
"Url '%s' is ignored. It is either a non-existing "
"path or lacks a specific scheme.", url)
"path or lacks a specific scheme.", url,
)

return files, urls

Expand Down Expand Up @@ -400,13 +402,13 @@ def find_all_candidates(self, project_name):
index_locations = self._get_index_urls_locations(project_name)
index_file_loc, index_url_loc = self._sort_locations(index_locations)
fl_file_loc, fl_url_loc = self._sort_locations(
self.find_links, expand_dir=True)
self.find_links, expand_dir=True,
)
dep_file_loc, dep_url_loc = self._sort_locations(self.dependency_links)

file_locations = (
Link(url) for url in itertools.chain(
index_file_loc, fl_file_loc, dep_file_loc)
)
file_locations = (Link(url) for url in itertools.chain(
index_file_loc, fl_file_loc, dep_file_loc,
))

# We trust every url that the user has given us whether it was given
# via --index-url or --find-links
Expand Down Expand Up @@ -632,11 +634,13 @@ def _link_package_versions(self, link, search):
return
if ext not in SUPPORTED_EXTENSIONS:
self._log_skipped_link(
link, 'unsupported archive format: %s' % ext)
link, 'unsupported archive format: %s' % ext,
)
return
if "binary" not in search.formats and ext == wheel_ext:
self._log_skipped_link(
link, 'No binaries permitted for %s' % search.supplied)
link, 'No binaries permitted for %s' % search.supplied,
)
return
if "macosx10" in link.path and ext == '.zip':
self._log_skipped_link(link, 'macosx10 one')
Expand All @@ -662,7 +666,8 @@ def _link_package_versions(self, link, search):
# This should be up by the search.ok_binary check, but see issue 2700.
if "source" not in search.formats and ext != wheel_ext:
self._log_skipped_link(
link, 'No sources permitted for %s' % search.supplied)
link, 'No sources permitted for %s' % search.supplied,
)
return

if not version:
Expand Down Expand Up @@ -829,8 +834,8 @@ def get_page(cls, link, skip_archives=True, session=None):
except requests.HTTPError as exc:
cls._handle_fail(link, exc, url)
except SSLError as exc:
reason = ("There was a problem confirming the ssl certificate: "
"%s" % exc)
reason = "There was a problem confirming the ssl certificate: "
reason += str(exc)
cls._handle_fail(link, reason, url, meth=logger.info)
except requests.ConnectionError as exc:
cls._handle_fail(link, "connection error: %s" % exc, url)
Expand Down Expand Up @@ -1098,7 +1103,8 @@ def fmt_ctl_formats(fmt_ctl, canonical_name):

def fmt_ctl_no_binary(fmt_ctl):
fmt_ctl_handle_mutual_exclude(
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary)
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary,
)


Search = namedtuple('Search', 'supplied canonical formats')
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_internal/operations/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def check_requirements(installed_dists):
if missing_reqs:
missing_reqs_dict[dist.key] = missing_reqs

incompatible_reqs = list(get_incompatible_reqs(
dist, installed_dists))
incompatible_reqs = list(get_incompatible_reqs(dist, installed_dists))
if incompatible_reqs:
incompatible_reqs_dict[dist.key] = incompatible_reqs

Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def from_dist(cls, dist, dependency_links):
)
if not svn_location:
logger.warning(
'Warning: cannot find svn location for %s', req)
'Warning: cannot find svn location for %s', req,
)
comments.append(
'## FIXME: could not find svn URL in dependency_links '
'for this package:'
Expand Down
7 changes: 3 additions & 4 deletions src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def process_line(line, filename, line_number, finder=None, comes_from=None,

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

# yield a line requirement
if args_str:
Expand Down Expand Up @@ -299,7 +300,5 @@ def skip_regex(lines_enum, options):
skip_regex = options.skip_requirements_regex if options else None
if skip_regex:
pattern = re.compile(skip_regex)
lines_enum = filterfalse(
lambda e: pattern.search(e[1]),
lines_enum)
lines_enum = filterfalse(lambda e: pattern.search(e[1]), lines_enum)
return lines_enum
12 changes: 8 additions & 4 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ def install(self, install_options, global_options=None, root=None,
global_options = global_options if global_options is not None else []
if self.editable:
self.install_editable(
install_options, global_options, prefix=prefix)
install_options, global_options, prefix=prefix,
)
return
if self.is_wheel:
version = wheel.wheel_version(self.source_dir)
Expand All @@ -756,7 +757,8 @@ def install(self, install_options, global_options=None, root=None,
with TempDirectory(kind="record") as temp_dir:
record_filename = os.path.join(temp_dir.path, 'install-record.txt')
install_args = self.get_install_args(
global_options, record_filename, root, prefix)
global_options, record_filename, root, prefix,
)
msg = 'Running setup.py install for %s' % (self.name,)
with open_spinner(msg) as spinner:
with indent_log():
Expand Down Expand Up @@ -882,7 +884,8 @@ def install_editable(self, install_options,
list(install_options),

cwd=self.setup_py_dir,
show_stdout=False)
show_stdout=False,
)

self.install_succeeded = True

Expand Down Expand Up @@ -953,7 +956,8 @@ def get_dist(self):
return pkg_resources.Distribution(
os.path.dirname(egg_info),
project_name=dist_name,
metadata=metadata)
metadata=metadata,
)

@property
def has_hash_options(self):
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/req/req_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def add_requirement(self, install_req, parent_req_name=None,
raise InstallationError(
"Could not satisfy constraints for '%s': "
"installation from path or url cannot be "
"constrained to a version" % name)
"constrained to a version" % name,
)
# If we're now installing a constraint, mark the existing
# object for real installation.
existing_req.constraint = False
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def from_dist(cls, dist):
else:
logger.debug(
'Not sure how to uninstall: %s - Check: %s',
dist, dist.location)
dist, dist.location,
)

# find distutils scripts= scripts
if dist.has_metadata('scripts') and dist.metadata_isdir('scripts'):
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ def call_subprocess(cmd, show_stdout=True, cwd=None,
try:
proc = subprocess.Popen(
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
cwd=cwd, env=env)
cwd=cwd, env=env,
)
except Exception as exc:
logger.critical(
"Error %s while executing command %s", exc, command_desc,
Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/utils/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def check_dist_requires_python(dist):
)
except specifiers.InvalidSpecifier as e:
logger.warning(
"Package %s has an invalid Requires-Python entry %s - %s" % (
dist.project_name, requires_python, e))
"Package %s has an invalid Requires-Python entry %s - %s",
dist.project_name, requires_python, e,
)
return


Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def get_url(self, location):

def get_revision(self, location):
revision = self.run_command(
['revno'], show_stdout=False, cwd=location)
['revno'], show_stdout=False, cwd=location,
)
return revision.splitlines()[-1]

def get_src_requirement(self, dist, location):
Expand Down
6 changes: 4 additions & 2 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def get_url(self, location):
"""Return URL of the first remote encountered."""
remotes = self.run_command(
['config', '--get-regexp', r'remote\..*\.url'],
show_stdout=False, cwd=location)
show_stdout=False, cwd=location,
)
remotes = remotes.splitlines()
found_remote = remotes[0]
for remote in remotes:
Expand All @@ -217,7 +218,8 @@ def get_url(self, location):

def get_revision(self, location):
current_rev = self.run_command(
['rev-parse', 'HEAD'], show_stdout=False, cwd=location)
['rev-parse', 'HEAD'], show_stdout=False, cwd=location,
)
return current_rev.strip()

def _get_subdirectory(self, location):
Expand Down
9 changes: 6 additions & 3 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,8 @@ def build(self, requirements, session, autobuilding=False):
if req.is_wheel:
if not autobuilding:
logger.info(
'Skipping %s, due to already being wheel.', req.name)
'Skipping %s, due to already being wheel.', req.name,
)
elif autobuilding and req.editable:
pass
elif autobuilding and req.link and not req.link.is_artifact:
Expand All @@ -831,7 +832,8 @@ def build(self, requirements, session, autobuilding=False):
canonicalize_name(req.name)):
logger.info(
"Skipping bdist_wheel for %s, due to binaries "
"being disabled for it.", req.name)
"being disabled for it.", req.name,
)
continue
buildset.append(req)

Expand Down Expand Up @@ -888,7 +890,8 @@ def build(self, requirements, session, autobuilding=False):
# extract the wheel into the dir
unpack_url(
req.link, req.source_dir, None, False,
session=session)
session=session,
)
else:
build_failure.append(req)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_console_to_str(monkeypatch):
def test_console_to_str_warning(monkeypatch):
some_bytes = b"a\xE9b"

def check_warning(msg):
def check_warning(msg, *args, **kwargs):
assert msg.startswith(
"Subprocess output does not appear to be encoded as")

Expand Down

0 comments on commit 729990c

Please sign in to comment.