Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(lots of) Misc Cleanups #4651

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pip/__init__.py
100755 → 100644
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
# OpenSSL 1.0.1 on MacOS
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
try:
from pip._vendor.requests.packages.urllib3.contrib import (
securetransport,
Expand All @@ -51,7 +51,6 @@
InsecureRequestWarning,
)


# assignment for flake8 to be happy

# This fixes a peculiarity when importing via __import__ - as we are
Expand Down Expand Up @@ -157,7 +156,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
40 changes: 22 additions & 18 deletions pip/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def main(self, args):
deprecation.RemovedInPip11Warning,
)

# TODO: try to get these passing down from the command?
# without resorting to os.environ to hold these.
# TODO: Try to get these passing down from the command without
# resorting to os.environ to hold these?

if options.no_input:
os.environ['PIP_NO_INPUT'] = '1'
Expand All @@ -212,8 +212,8 @@ def main(self, args):

try:
status = self.run(options, args)
# FIXME: all commands should return an exit status
# and when it is done, isinstance is not needed anymore
# FIXME: All commands should return an exit status
# and when it is done, isinstance is not needed anymore
if isinstance(status, int):
return status
except PreviousBuildDirError as exc:
Expand Down Expand Up @@ -242,13 +242,14 @@ def main(self, args):
return UNKNOWN_ERROR
finally:
# Check if we're using the latest version of pip available
if (not options.disable_pip_version_check and not
getattr(options, "no_index", False)):
with self._build_session(
options,
retries=0,
timeout=min(5, options.timeout)) as session:
_no_index = getattr(options, "no_index", False)
if not options.disable_pip_version_check and not _no_index:
session = self._build_session(
options, retries=0, timeout=min(5, options.timeout)
)
with session:
pip_version_check(session, options)

# Avoid leaking loggers
for handler in set(logging.root.handlers) - original_root_handlers:
# this method benefit from the Logger class internal lock
Expand All @@ -269,10 +270,12 @@ def populate_requirement_set(requirement_set, args, options, finder,
# requirement_set.require_hashes may be updated

for filename in options.constraints:
for req in parse_requirements(
filename,
constraint=True, finder=finder, options=options,
session=session, wheel_cache=wheel_cache):
parsed_constraints = parse_requirements(
filename,
constraint=True, finder=finder, options=options,
session=session, wheel_cache=wheel_cache
)
for req in parsed_constraints:
requirement_set.add_requirement(req)

for req in args:
Expand All @@ -293,10 +296,11 @@ def populate_requirement_set(requirement_set, args, options, finder,
)

for filename in options.requirements:
for req in parse_requirements(
filename,
finder=finder, options=options, session=session,
wheel_cache=wheel_cache):
parsed_reqs = parse_requirements(
filename, finder=finder, options=options, session=session,
wheel_cache=wheel_cache
)
for req in parsed_reqs:
requirement_set.add_requirement(req)
# If --require-hashes was a line in a requirements file, tell
# RequirementSet about it:
Expand Down
3 changes: 3 additions & 0 deletions pip/baseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def _update_defaults(self, defaults):
late_eval.add(option.dest)
opt_str = option.get_opt_string()
val = option.convert_value(opt_str, val)

# From take_action
args = option.callback_args or ()
kwargs = option.callback_kwargs or {}
Expand All @@ -214,6 +215,7 @@ def _update_defaults(self, defaults):

for key in late_eval:
defaults[key] = getattr(self.values, key)

self.values = None
return defaults

Expand All @@ -230,6 +232,7 @@ def get_default_values(self):
if isinstance(default, string_types):
opt_str = option.get_opt_string()
defaults[option.dest] = option.check_value(opt_str, default)

return optparse.Values(defaults)

def error(self, msg):
Expand Down
12 changes: 6 additions & 6 deletions pip/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
class Cache(object):
"""An abstract class - provides cache directories for data from links


:param cache_dir: The root of the cache.
:param format_control: A pip.index.FormatControl object to limit
binaries being read from the cache.
:param allowed_formats: which formats of files the cache should store.
('binary' and 'source' are the only allowed values)
:param cache_dir: The root of the cache.
:param format_control: A pip.index.FormatControl object to limit
binaries being read from the cache.
:param allowed_formats: Which formats of files the cache should store.
('binary' and 'source' are the only allowed values)
"""

def __init__(self, cache_dir, format_control, allowed_formats):
Expand Down Expand Up @@ -70,6 +69,7 @@ def _get_candidates(self, link, package_name):
if can_not_cache:
return []

# Check if the format of this cache is allowed to be used
canonical_name = canonicalize_name(package_name)
formats = pip.index.fmt_ctl_formats(
self.format_control, canonical_name
Expand Down
Loading