This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,79 +1,28 @@
#!/usr/bin/env python
from __future__ import absolute_import

import locale
import logging
import os
import optparse
import warnings

import sys
import re
import errno

# Upstream pip vendorizes a bunch of its dependencies. Debian de-vendorizes
# (unbundles) these dependencies to be compliant with Debian policy. Instead,
# these dependencies are packaged as wheel (.whl) files in a known location.
# When pip itself executes, we have to arrange for these wheels to show up
# earlier on sys.path than any other version of these packages, otherwise
# things can break. See for example Bug #744145.
#
# The location of the wheels differs depending on whether we're inside or
# outside a virtual environment, regardless of whether that venv was created
# with virtualenv or pyvenv. The first thing we have to do is figure out if
# we're inside or outside a venv, then search the appropriate wheel directory
# and add all the .whls found there to the front of sys.path. As per Debian
# Python Policy, only the wheels needed to support this de-vendorization will
# be present, so it's safe to add them all.
#
# venv determination is a bit of a black art, but this algorithm should work
# in both Python 2 (virtualenv-only) and Python 3 (pyvenv and virtualenv). -
# updated by barry@debian.org 2015-02-25

base_prefix = getattr(sys, 'base_prefix', None)
real_prefix = getattr(sys, 'real_prefix', None)
if base_prefix is None:
# Python 2 has no base_prefix at all. It also has no pyvenv. Fall back
# to checking real_prefix.
if real_prefix is None:
# We are not in a venv.
in_venv = False
else:
# We're in a Python 2 virtualenv created venv, but real_prefix should
# never be the same as sys.prefix.
assert sys.prefix != real_prefix
in_venv = True
elif sys.prefix != base_prefix:
# We're in a Python 3, pyvenv created venv.
in_venv = True
elif real_prefix is None:
# We're in Python 3, outside a venv, but base better equal prefix.
assert sys.prefix == base_prefix
in_venv = False
else:
# We're in a Python 3, virtualenv created venv.
assert real_prefix != sys.prefix
in_venv = True


if in_venv:
wheel_dir = os.path.join(sys.prefix, 'lib', 'python-wheels')
else:
wheel_dir = '/usr/share/python-wheels'

# We'll add all the wheels we find to the front of sys.path so that they're
# found first, even if the same dependencies are available in site-packages.
try:
for filename in os.listdir(wheel_dir):
if os.path.splitext(filename)[1] == '.whl':
sys.path.insert(0, os.path.join(wheel_dir, filename))
# FileNotFoundError doesn't exist in Python 2, but ignore it anyway.
except OSError as error:
if error.errno != errno.ENOENT:
raise


from pip.exceptions import InstallationError, CommandError, PipError
from pip.log import logger
from pip.util import get_installed_distributions, get_prog
from pip.utils import get_installed_distributions, get_prog
from pip.utils import deprecation, dist_is_editable
from pip.vcs import git, mercurial, subversion, bazaar # noqa
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.commands import commands, get_summaries, get_similar_commands
from pip.commands import get_summaries, get_similar_commands
from pip.commands import commands_dict
from pip._vendor.requests.packages.urllib3.exceptions import (
InsecureRequestWarning,
)


# assignment for flake8 to be happy

# This fixes a peculiarity when importing via __import__ - as we are
# initialising the pip module, "from pip import cmdoptions" is recursive
@@ -82,7 +31,13 @@
cmdoptions = pip.cmdoptions

# The version as used in the setup.py and the docs conf.py
__version__ = "1.5.6"
__version__ = "8.1.2"


logger = logging.getLogger(__name__)

# Hide the InsecureRequestWArning from urllib3
warnings.filterwarnings("ignore", category=InsecureRequestWarning)


def autocomplete():
@@ -128,7 +83,7 @@ def autocomplete():
print(dist)
sys.exit(1)

subcommand = commands[subcommand_name]()
subcommand = commands_dict[subcommand_name]()
options += [(opt.get_opt_string(), opt.nargs)
for opt in subcommand.parser.option_list_all
if opt.help != optparse.SUPPRESS_HELP]
@@ -172,13 +127,13 @@ 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)
parser.add_option_group(gen_opts)

parser.main = True # so the help formatter knows
parser.main = True # so the help formatter knows

# create command listing for description
command_summaries = get_summaries()
@@ -191,8 +146,8 @@ def create_main_parser():
def parseopts(args):
parser = create_main_parser()

# Note: parser calls disable_interspersed_args(), so the result of this call
# is to split the initial args into the general options before the
# Note: parser calls disable_interspersed_args(), so the result of this
# call is to split the initial args into the general options before the
# subcommand and everything else.
# For example:
# args: ['--timeout=5', 'install', '--user', 'INITools']
@@ -212,13 +167,9 @@ def parseopts(args):
sys.exit()

# the subcommand name
cmd_name = args_else[0].lower()

#all the args without the subcommand
cmd_args = args[:]
cmd_args.remove(args_else[0].lower())
cmd_name = args_else[0]

if cmd_name not in commands:
if cmd_name not in commands_dict:
guess = get_similar_commands(cmd_name)

msg = ['unknown command "%s"' % cmd_name]
@@ -227,41 +178,51 @@ def parseopts(args):

raise CommandError(' - '.join(msg))

# all the args without the subcommand
cmd_args = args[:]
cmd_args.remove(cmd_name)

return cmd_name, cmd_args


def main(initial_args=None):
if initial_args is None:
initial_args = sys.argv[1:]
def check_isolated(args):
isolated = False

if "--isolated" in args:
isolated = True

return isolated


def main(args=None):
if args is None:
args = sys.argv[1:]

# Configure our deprecation warnings to be sent through loggers
deprecation.install_warning_logger()

autocomplete()

try:
cmd_name, cmd_args = parseopts(initial_args)
except PipError:
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s" % e)
cmd_name, cmd_args = parseopts(args)
except PipError as exc:
sys.stderr.write("ERROR: %s" % exc)
sys.stderr.write(os.linesep)
sys.exit(1)

command = commands[cmd_name]()
return command.main(cmd_args)


def bootstrap():
"""
Bootstrapping function to be called from install-pip.py script.
"""
pkgs = ['pip']
# Needed for locale.getpreferredencoding(False) to work
# in pip.utils.encoding.auto_decode
try:
import setuptools
except ImportError:
pkgs.append('setuptools')
return main(['install', '--upgrade'] + pkgs + sys.argv[1:])
locale.setlocale(locale.LC_ALL, '')
except locale.Error as e:
# setlocale can apparently crash if locale are uninitialized
logger.debug("Ignoring error %s when setting locale", e)
command = commands_dict[cmd_name](isolated=check_isolated(cmd_args))
return command.main(cmd_args)

############################################################
## Writing freeze files

# ###########################################################
# # Writing freeze files

class FrozenRequirement(object):

@@ -275,48 +236,68 @@ def __init__(self, name, req, editable, comments=()):
_date_re = re.compile(r'-(20\d\d\d\d\d\d)$')

@classmethod
def from_dist(cls, dist, dependency_links, find_tags=False):
def from_dist(cls, dist, dependency_links):
location = os.path.normcase(os.path.abspath(dist.location))
comments = []
from pip.vcs import vcs, get_src_requirement
if vcs.get_backend_name(location):
if dist_is_editable(dist) and vcs.get_backend_name(location):
editable = True
try:
req = get_src_requirement(dist, location, find_tags)
except InstallationError:
ex = sys.exc_info()[1]
logger.warn("Error when trying to get requirement for VCS system %s, falling back to uneditable format" % ex)
req = get_src_requirement(dist, location)
except InstallationError as exc:
logger.warning(
"Error when trying to get requirement for VCS system %s, "
"falling back to uneditable format", exc
)
req = None
if req is None:
logger.warn('Could not determine repository location of %s' % location)
comments.append('## !! Could not determine repository location')
logger.warning(
'Could not determine repository location of %s', location
)
comments.append(
'## !! Could not determine repository location'
)
req = dist.as_requirement()
editable = False
else:
editable = False
req = dist.as_requirement()
specs = req.specs
assert len(specs) == 1 and specs[0][0] in ('==', '==='), specs
assert len(specs) == 1 and specs[0][0] in ["==", "==="], \
'Expected 1 spec with == or ===; specs = %r; dist = %r' % \
(specs, dist)
version = specs[0][1]
ver_match = cls._rev_re.search(version)
date_match = cls._date_re.search(version)
if ver_match or date_match:
svn_backend = vcs.get_backend('svn')
if svn_backend:
svn_location = svn_backend(
).get_location(dist, dependency_links)
svn_location = svn_backend().get_location(
dist,
dependency_links,
)
if not svn_location:
logger.warn(
'Warning: cannot find svn location for %s' % req)
comments.append('## FIXME: could not find svn URL in dependency_links for this package:')
logger.warning(
'Warning: cannot find svn location for %s', req)
comments.append(
'## FIXME: could not find svn URL in dependency_links '
'for this package:'
)
else:
comments.append('# Installing as editable to satisfy requirement %s:' % req)
comments.append(
'# Installing as editable to satisfy requirement %s:' %
req
)
if ver_match:
rev = ver_match.group(1)
else:
rev = '{%s}' % date_match.group(1)
editable = True
req = '%s@%s#egg=%s' % (svn_location, rev, cls.egg_name(dist))
req = '%s@%s#egg=%s' % (
svn_location,
rev,
cls.egg_name(dist)
)
return cls(dist.project_name, req, editable, comments)

@staticmethod
@@ -335,6 +316,4 @@ def __str__(self):


if __name__ == '__main__':
exit = main()
if exit:
sys.exit(exit)
sys.exit(main())
Binary file not shown.
@@ -1,7 +1,19 @@
from __future__ import absolute_import

import os
import sys
from .runner import run

# If we are running from a wheel, add the wheel to sys.path
# This allows the usage python pip-*.whl/pip install pip-*.whl
if __package__ == '':
# __file__ is pip-*.whl/pip/__main__.py
# first dirname call strips of '/__main__.py', second strips off '/pip'
# Resulting path is the name of the wheel itself
# Add that to sys.path so we can import pip
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

import pip # noqa

if __name__ == '__main__':
exit = run()
if exit:
sys.exit(exit)
sys.exit(pip.main())
Binary file not shown.

This file was deleted.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
@@ -1,14 +1,23 @@
"""Base option parser setup"""
from __future__ import absolute_import

import sys
import optparse
import os
import re
import textwrap
from distutils.util import strtobool

from pip.backwardcompat import ConfigParser, string_types
from pip.locations import default_config_file
from pip.util import get_terminal_size, get_prog
from pip._vendor.six import string_types
from pip._vendor.six.moves import configparser
from pip.locations import (
legacy_config_file, config_basename, running_under_virtualenv,
site_config_files
)
from pip.utils import appdirs, get_terminal_size


_environ_prefix_re = re.compile(r"^PIP_", re.I)


class PrettyHelpFormatter(optparse.IndentedHelpFormatter):
@@ -67,11 +76,11 @@ def format_description(self, description):
label = 'Commands'
else:
label = 'Description'
#some doc strings have inital newlines, some don't
# some doc strings have initial newlines, some don't
description = description.lstrip('\n')
#some doc strings have final newlines and spaces, some don't
# some doc strings have final newlines and spaces, some don't
description = description.rstrip()
#dedent, then reindent
# dedent, then reindent
description = self.indent_lines(textwrap.dedent(description), " ")
description = '%s:\n%s\n' % (label, description)
return description
@@ -91,13 +100,15 @@ def indent_lines(self, text, indent):


class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
"""Custom help formatter for use in ConfigOptionParser that updates
the defaults before expanding them, allowing them to show up correctly
in the help listing"""
"""Custom help formatter for use in ConfigOptionParser.
This is updates the defaults before expanding them, allowing
them to show up correctly in the help listing.
"""

def expand_default(self, option):
if self.parser is not None:
self.parser.update_defaults(self.parser.defaults)
self.parser._update_defaults(self.parser.defaults)
return optparse.IndentedHelpFormatter.expand_default(self, option)


@@ -125,58 +136,116 @@ class ConfigOptionParser(CustomOptionParser):
"""Custom option parser which updates its defaults by checking the
configuration files and environmental variables"""

isolated = False

def __init__(self, *args, **kwargs):
self.config = ConfigParser.RawConfigParser()
self.config = configparser.RawConfigParser()
self.name = kwargs.pop('name')
self.isolated = kwargs.pop("isolated", False)
self.files = self.get_config_files()
if self.files:
self.config.read(self.files)
assert self.name
optparse.OptionParser.__init__(self, *args, **kwargs)

def get_config_files(self):
# the files returned by this method will be parsed in order with the
# first files listed being overridden by later files in standard
# ConfigParser fashion
config_file = os.environ.get('PIP_CONFIG_FILE', False)
if config_file == os.devnull:
return []
if config_file and os.path.exists(config_file):
return [config_file]
return [default_config_file]

# at the base we have any site-wide configuration
files = list(site_config_files)

# per-user configuration next
if not self.isolated:
if config_file and os.path.exists(config_file):
files.append(config_file)
else:
# This is the legacy config file, we consider it to be a lower
# priority than the new file location.
files.append(legacy_config_file)

# This is the new config file, we consider it to be a higher
# priority than the legacy file.
files.append(
os.path.join(
appdirs.user_config_dir("pip"),
config_basename,
)
)

# finally virtualenv configuration first trumping others
if running_under_virtualenv():
venv_config_file = os.path.join(
sys.prefix,
config_basename,
)
if os.path.exists(venv_config_file):
files.append(venv_config_file)

return files

def check_default(self, option, key, val):
try:
return option.check_value(key, val)
except optparse.OptionValueError:
e = sys.exc_info()[1]
print("An error occurred during configuration: %s" % e)
except optparse.OptionValueError as exc:
print("An error occurred during configuration: %s" % exc)
sys.exit(3)

def update_defaults(self, defaults):
def _update_defaults(self, defaults):
"""Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists)."""
# Then go and look for the other sources of configuration:
config = {}
# 1. config files
for section in ('global', self.name):
config.update(self.normalize_keys(self.get_config_section(section)))
config.update(
self.normalize_keys(self.get_config_section(section))
)
# 2. environmental variables
config.update(self.normalize_keys(self.get_environ_vars()))
if not self.isolated:
config.update(self.normalize_keys(self.get_environ_vars()))
# Accumulate complex default state.
self.values = optparse.Values(self.defaults)
late_eval = set()
# Then set the options with those values
for key, val in config.items():
# ignore empty values
if not val:
continue

option = self.get_option(key)
if option is not None:
# ignore empty values
if not val:
continue
if option.action in ('store_true', 'store_false', 'count'):
val = strtobool(val)
if option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
else:
val = self.check_default(option, key, val)

defaults[option.dest] = val
# Ignore options not present in this parser. E.g. non-globals put
# in [global] by users that want them to apply to all applicable
# commands.
if option is None:
continue

if option.action in ('store_true', 'store_false', 'count'):
val = strtobool(val)
elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
elif option.action == 'callback':
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 {}
option.callback(option, opt_str, val, self, *args, **kwargs)
else:
val = self.check_default(option, key, val)

defaults[option.dest] = val

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

def normalize_keys(self, items):
@@ -197,20 +266,20 @@ def get_config_section(self, name):
return self.config.items(name)
return []

def get_environ_vars(self, prefix='PIP_'):
def get_environ_vars(self):
"""Returns a generator with all environmental vars with prefix PIP_"""
for key, val in os.environ.items():
if key.startswith(prefix):
yield (key.replace(prefix, '').lower(), val)
if _environ_prefix_re.search(key):
yield (_environ_prefix_re.sub("", key).lower(), val)

def get_default_values(self):
"""Overridding to make updating the defaults after instantiation of
the option parser possible, update_defaults() does the dirty work."""
the option parser possible, _update_defaults() does the dirty work."""
if not self.process_default_values:
# Old, pre-Optik 1.5 behaviour.
return optparse.Values(self.defaults)

defaults = self.update_defaults(self.defaults.copy()) # ours
defaults = self._update_defaults(self.defaults.copy()) # ours
for option in self._get_all_options():
default = defaults.get(option.dest)
if isinstance(default, string_types):
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
@@ -1,80 +1,75 @@
"""
Package containing all pip commands
"""
from __future__ import absolute_import


from pip.commands.bundle import BundleCommand
from pip.commands.completion import CompletionCommand
from pip.commands.download import DownloadCommand
from pip.commands.freeze import FreezeCommand
from pip.commands.hash import HashCommand
from pip.commands.help import HelpCommand
from pip.commands.list import ListCommand
from pip.commands.search import SearchCommand
from pip.commands.show import ShowCommand
from pip.commands.install import InstallCommand
from pip.commands.uninstall import UninstallCommand
from pip.commands.unzip import UnzipCommand
from pip.commands.zip import ZipCommand
from pip.commands.wheel import WheelCommand


commands = {
BundleCommand.name: BundleCommand,
commands_dict = {
CompletionCommand.name: CompletionCommand,
FreezeCommand.name: FreezeCommand,
HashCommand.name: HashCommand,
HelpCommand.name: HelpCommand,
SearchCommand.name: SearchCommand,
ShowCommand.name: ShowCommand,
InstallCommand.name: InstallCommand,
UninstallCommand.name: UninstallCommand,
UnzipCommand.name: UnzipCommand,
ZipCommand.name: ZipCommand,
DownloadCommand.name: DownloadCommand,
ListCommand.name: ListCommand,
WheelCommand.name: WheelCommand,
}


commands_order = [
InstallCommand,
DownloadCommand,
UninstallCommand,
FreezeCommand,
ListCommand,
ShowCommand,
SearchCommand,
WheelCommand,
ZipCommand,
UnzipCommand,
BundleCommand,
HashCommand,
CompletionCommand,
HelpCommand,
]


def get_summaries(ignore_hidden=True, ordered=True):
def get_summaries(ordered=True):
"""Yields sorted (command name, command summary) tuples."""

if ordered:
cmditems = _sort_commands(commands, commands_order)
cmditems = _sort_commands(commands_dict, commands_order)
else:
cmditems = commands.items()
cmditems = commands_dict.items()

for name, command_class in cmditems:
if ignore_hidden and command_class.hidden:
continue

yield (name, command_class.summary)


def get_similar_commands(name):
"""Command name auto-correct."""
from difflib import get_close_matches

close_commands = get_close_matches(name, commands.keys())
name = name.lower()

close_commands = get_close_matches(name, commands_dict.keys())

if close_commands:
guess = close_commands[0]
return close_commands[0]
else:
guess = False

return guess
return False


def _sort_commands(cmddict, order):
Binary file not shown.

This file was deleted.

Binary file not shown.
@@ -1,3 +1,5 @@
from __future__ import absolute_import

import sys
from pip.basecommand import Command

@@ -30,24 +32,28 @@
class CompletionCommand(Command):
"""A helper command to be used for command completion."""
name = 'completion'
summary = 'A helper command to be used for command completion'
hidden = True
summary = 'A helper command used for command completion'

def __init__(self, *args, **kw):
super(CompletionCommand, self).__init__(*args, **kw)
self.parser.add_option(

cmd_opts = self.cmd_opts

cmd_opts.add_option(
'--bash', '-b',
action='store_const',
const='bash',
dest='shell',
help='Emit completion code for bash')
self.parser.add_option(
cmd_opts.add_option(
'--zsh', '-z',
action='store_const',
const='zsh',
dest='shell',
help='Emit completion code for zsh')

self.parser.insert_option_group(0, cmd_opts)

def run(self, options, args):
"""Prints the completion code of the given shell"""
shells = COMPLETION_SCRIPTS.keys()
@@ -56,4 +62,6 @@ def run(self, options, args):
script = COMPLETION_SCRIPTS.get(options.shell, '')
print(BASE_COMPLETION % {'script': script, 'shell': options.shell})
else:
sys.stderr.write('ERROR: You must pass %s\n' % ' or '.join(shell_options))
sys.stderr.write(
'ERROR: You must pass %s\n' % ' or '.join(shell_options)
)
Binary file not shown.
@@ -1,20 +1,28 @@
import re
from __future__ import absolute_import

import sys
import pip

from pip.req import InstallRequirement
from pip.log import logger
import pip
from pip.compat import stdlib_pkgs
from pip.basecommand import Command
from pip.util import get_installed_distributions
import pkg_resources
from pip.operations.freeze import freeze
from pip.wheel import WheelCache


DEV_PKGS = ('pip', 'setuptools', 'distribute', 'wheel')


class FreezeCommand(Command):
"""Output installed packages in requirements format."""
"""
Output installed packages in requirements format.
packages are listed in a case-insensitive sorted order.
"""
name = 'freeze'
usage = """
%prog [options]"""
summary = 'Output installed packages in requirements format.'
log_streams = ("ext://sys.stderr", "ext://sys.stderr")

def __init__(self, *args, **kw):
super(FreezeCommand, self).__init__(*args, **kw)
@@ -25,90 +33,54 @@ def __init__(self, *args, **kw):
action='store',
default=None,
metavar='file',
help="Use the order in the given requirements file and it's comments when generating output.")
help="Use the order in the given requirements file and its "
"comments when generating output.")
self.cmd_opts.add_option(
'-f', '--find-links',
dest='find_links',
action='append',
default=[],
metavar='URL',
help='URL for finding packages, which will be added to the output.')
help='URL for finding packages, which will be added to the '
'output.')
self.cmd_opts.add_option(
'-l', '--local',
dest='local',
action='store_true',
default=False,
help='If in a virtualenv that has global access, do not output globally-installed packages.')
help='If in a virtualenv that has global access, do not output '
'globally-installed packages.')
self.cmd_opts.add_option(
'--user',
dest='user',
action='store_true',
default=False,
help='Only output packages installed in user-site.')
self.cmd_opts.add_option(
'--all',
dest='freeze_all',
action='store_true',
help='Do not skip these packages in the output:'
' %s' % ', '.join(DEV_PKGS))

self.parser.insert_option_group(0, self.cmd_opts)

def setup_logging(self):
logger.move_stdout_to_stderr()

def run(self, options, args):
requirement = options.requirement
find_links = options.find_links or []
local_only = options.local
## FIXME: Obviously this should be settable:
find_tags = False
skip_match = None

skip_regex = options.skip_requirements_regex
if skip_regex:
skip_match = re.compile(skip_regex)

dependency_links = []
format_control = pip.index.FormatControl(set(), set())
wheel_cache = WheelCache(options.cache_dir, format_control)
skip = set(stdlib_pkgs)
if not options.freeze_all:
skip.update(DEV_PKGS)

f = sys.stdout
freeze_kwargs = dict(
requirement=options.requirement,
find_links=options.find_links,
local_only=options.local,
user_only=options.user,
skip_regex=options.skip_requirements_regex,
isolated=options.isolated_mode,
wheel_cache=wheel_cache,
skip=skip)

for dist in pkg_resources.working_set:
if dist.has_metadata('dependency_links.txt'):
dependency_links.extend(dist.get_metadata_lines('dependency_links.txt'))
for link in find_links:
if '#egg=' in link:
dependency_links.append(link)
for link in find_links:
f.write('-f %s\n' % link)
installations = {}
for dist in get_installed_distributions(local_only=local_only):
req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
installations[req.name] = req
if requirement:
req_f = open(requirement)
for line in req_f:
if not line.strip() or line.strip().startswith('#'):
f.write(line)
continue
if skip_match and skip_match.search(line):
f.write(line)
continue
elif line.startswith('-e') or line.startswith('--editable'):
if line.startswith('-e'):
line = line[2:].strip()
else:
line = line[len('--editable'):].strip().lstrip('=')
line_req = InstallRequirement.from_editable(line, default_vcs=options.default_vcs)
elif (line.startswith('-r') or line.startswith('--requirement')
or line.startswith('-Z') or line.startswith('--always-unzip')
or line.startswith('-f') or line.startswith('-i')
or line.startswith('--extra-index-url')
or line.startswith('--find-links')
or line.startswith('--index-url')):
f.write(line)
continue
else:
line_req = InstallRequirement.from_line(line)
if not line_req.name:
logger.notify("Skipping line because it's not clear what it would install: %s"
% line.strip())
logger.notify(" (add #egg=PackageName to the URL to avoid this warning)")
continue
if line_req.name not in installations:
logger.warn("Requirement file contains %s, but that package is not installed"
% line.strip())
continue
f.write(str(installations[line_req.name]))
del installations[line_req.name]
f.write('## The following requirements were added by pip --freeze:\n')
for installation in sorted(installations.values(), key=lambda x: x.name):
f.write(str(installation))
for line in freeze(**freeze_kwargs):
sys.stdout.write(line + '\n')
Binary file not shown.
@@ -1,3 +1,5 @@
from __future__ import absolute_import

from pip.basecommand import Command, SUCCESS
from pip.exceptions import CommandError

@@ -10,15 +12,15 @@ class HelpCommand(Command):
summary = 'Show help for commands.'

def run(self, options, args):
from pip.commands import commands, get_similar_commands
from pip.commands import commands_dict, get_similar_commands

try:
# 'pip help' with no args is handled by pip.__init__.parseopt()
cmd_name = args[0] # the command we need help for
except IndexError:
return SUCCESS

if cmd_name not in commands:
if cmd_name not in commands_dict:
guess = get_similar_commands(cmd_name)

msg = ['unknown command "%s"' % cmd_name]
@@ -27,7 +29,7 @@ def run(self, options, args):

raise CommandError(' - '.join(msg))

command = commands[cmd_name]()
command = commands_dict[cmd_name]()
command.parser.print_help()

return SUCCESS
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
@@ -1,22 +1,31 @@
from __future__ import absolute_import

import logging
import warnings

from pip.basecommand import Command
from pip.exceptions import DistributionNotFound, BestVersionAlreadyInstalled
from pip.exceptions import CommandError
from pip.index import PackageFinder
from pip.log import logger
from pip.req import InstallRequirement
from pip.util import get_installed_distributions, dist_is_editable
from pip.utils import (
get_installed_distributions, dist_is_editable)
from pip.utils.deprecation import RemovedInPip10Warning
from pip.cmdoptions import make_option_group, index_group


logger = logging.getLogger(__name__)


class ListCommand(Command):
"""List installed packages, including editables."""
"""
List installed packages, including editables.
Packages are listed in a case-insensitive sorted order.
"""
name = 'list'
usage = """
%prog [options]"""
summary = 'List installed packages.'

# distributions to skip (python itself is reported by pkg_resources.working_set)
skip = ['python']

def __init__(self, *args, **kw):
super(ListCommand, self).__init__(*args, **kw)

@@ -26,12 +35,12 @@ def __init__(self, *args, **kw):
'-o', '--outdated',
action='store_true',
default=False,
help='List outdated packages (excluding editables)')
help='List outdated packages')
cmd_opts.add_option(
'-u', '--uptodate',
action='store_true',
default=False,
help='List uptodate packages (excluding editables)')
help='List uptodate packages')
cmd_opts.add_option(
'-e', '--editable',
action='store_true',
@@ -41,13 +50,23 @@ def __init__(self, *args, **kw):
'-l', '--local',
action='store_true',
default=False,
help='If in a virtualenv that has global access, do not list globally-installed packages.')
help=('If in a virtualenv that has global access, do not list '
'globally-installed packages.'),
)
self.cmd_opts.add_option(
'--user',
dest='user',
action='store_true',
default=False,
help='Only output packages installed in user-site.')

cmd_opts.add_option(
'--pre',
action='store_true',
default=False,
help="Include pre-release and development versions. By default, pip only finds stable versions.")
help=("Include pre-release and development versions. By default, "
"pip only finds stable versions."),
)

index_opts = make_option_group(index_group, self.parser)

@@ -58,105 +77,133 @@ def _build_package_finder(self, options, index_urls, session):
"""
Create a package finder appropriate to this list command.
"""
return PackageFinder(find_links=options.find_links,
index_urls=index_urls,
allow_external=options.allow_external,
allow_unverified=options.allow_unverified,
allow_all_external=options.allow_all_external,
allow_all_prereleases=options.pre,
process_dependency_links=
options.process_dependency_links,
session=session,
)
return PackageFinder(
find_links=options.find_links,
index_urls=index_urls,
allow_all_prereleases=options.pre,
trusted_hosts=options.trusted_hosts,
process_dependency_links=options.process_dependency_links,
session=session,
)

def run(self, options, args):
if options.allow_external:
warnings.warn(
"--allow-external has been deprecated and will be removed in "
"the future. Due to changes in the repository protocol, it no "
"longer has any effect.",
RemovedInPip10Warning,
)

if options.allow_all_external:
warnings.warn(
"--allow-all-external has been deprecated and will be removed "
"in the future. Due to changes in the repository protocol, it "
"no longer has any effect.",
RemovedInPip10Warning,
)

if options.allow_unverified:
warnings.warn(
"--allow-unverified has been deprecated and will be removed "
"in the future. Due to changes in the repository protocol, it "
"no longer has any effect.",
RemovedInPip10Warning,
)
if options.outdated and options.uptodate:
raise CommandError(
"Options --outdated and --uptodate cannot be combined.")

if options.outdated:
self.run_outdated(options)
elif options.uptodate:
self.run_uptodate(options)
elif options.editable:
self.run_editables(options)
else:
self.run_listing(options)

def run_outdated(self, options):
for dist, remote_version_raw, remote_version_parsed in self.find_packages_latests_versions(options):
if remote_version_parsed > dist.parsed_version:
logger.notify('%s (Current: %s Latest: %s)' % (dist.project_name,
dist.version, remote_version_raw))
for dist, latest_version, typ in sorted(
self.find_packages_latest_versions(options),
key=lambda p: p[0].project_name.lower()):
if latest_version > dist.parsed_version:
logger.info(
'%s - Latest: %s [%s]',
self.output_package(dist), latest_version, typ,
)

def find_packages_latests_versions(self, options):
def find_packages_latest_versions(self, options):
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.notify('Ignoring indexes: %s' % ','.join(index_urls))
logger.info('Ignoring indexes: %s', ','.join(index_urls))
index_urls = []

if options.use_mirrors:
logger.deprecated("1.7",
"--use-mirrors has been deprecated and will be removed"
" in the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")

if options.mirrors:
logger.deprecated("1.7",
"--mirrors has been deprecated and will be removed in "
" the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")
index_urls += options.mirrors

dependency_links = []
for dist in get_installed_distributions(local_only=options.local, skip=self.skip):
for dist in get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable):
if dist.has_metadata('dependency_links.txt'):
dependency_links.extend(
dist.get_metadata_lines('dependency_links.txt'),
)

session = self._build_session(options)

finder = self._build_package_finder(options, index_urls, session)
finder.add_dependency_links(dependency_links)

installed_packages = get_installed_distributions(local_only=options.local, include_editables=False, skip=self.skip)
for dist in installed_packages:
req = InstallRequirement.from_line(dist.key, None)
try:
link = finder.find_requirement(req, True)

# If link is None, means installed version is most up-to-date
if link is None:
with self._build_session(options) as session:
finder = self._build_package_finder(options, index_urls, session)
finder.add_dependency_links(dependency_links)

installed_packages = get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable,
)
for dist in installed_packages:
typ = 'unknown'
all_candidates = finder.find_all_candidates(dist.key)
if not options.pre:
# Remove prereleases
all_candidates = [candidate for candidate in all_candidates
if not candidate.version.is_prerelease]

if not all_candidates:
continue
except DistributionNotFound:
continue
except BestVersionAlreadyInstalled:
remote_version = req.installed_version
else:
# It might be a good idea that link or finder had a public method
# that returned version
remote_version = finder._link_package_versions(link, req.name)[0]
remote_version_raw = remote_version[2]
remote_version_parsed = remote_version[0]
yield dist, remote_version_raw, remote_version_parsed
best_candidate = max(all_candidates,
key=finder._candidate_sort_key)
remote_version = best_candidate.version
if best_candidate.location.is_wheel:
typ = 'wheel'
else:
typ = 'sdist'
yield dist, remote_version, typ

def run_listing(self, options):
installed_packages = get_installed_distributions(local_only=options.local, skip=self.skip)
installed_packages = get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable,
)
self.output_package_listing(installed_packages)

def run_editables(self, options):
installed_packages = get_installed_distributions(local_only=options.local, editables_only=True)
self.output_package_listing(installed_packages)
def output_package(self, dist):
if dist_is_editable(dist):
return '%s (%s, %s)' % (
dist.project_name,
dist.version,
dist.location,
)
else:
return '%s (%s)' % (dist.project_name, dist.version)

def output_package_listing(self, installed_packages):
installed_packages = sorted(installed_packages, key=lambda dist: dist.project_name.lower())
installed_packages = sorted(
installed_packages,
key=lambda dist: dist.project_name.lower(),
)
for dist in installed_packages:
if dist_is_editable(dist):
line = '%s (%s, %s)' % (dist.project_name, dist.version, dist.location)
else:
line = '%s (%s)' % (dist.project_name, dist.version)
logger.notify(line)
logger.info(self.output_package(dist))

def run_uptodate(self, options):
uptodate = []
for dist, remote_version_raw, remote_version_parsed in self.find_packages_latests_versions(options):
if dist.parsed_version == remote_version_parsed:
for dist, version, typ in self.find_packages_latest_versions(options):
if dist.parsed_version == version:
uptodate.append(dist)
self.output_package_listing(uptodate)
Binary file not shown.
@@ -1,16 +1,21 @@
from __future__ import absolute_import

import logging
import sys
import textwrap

import pip.download

from pip.basecommand import Command, SUCCESS
from pip.util import get_terminal_size
from pip.log import logger
from pip.backwardcompat import xmlrpclib, reduce, cmp
from pip.download import PipXmlrpcTransport
from pip.models import PyPI
from pip.utils import get_terminal_size
from pip.utils.logging import indent_log
from pip.exceptions import CommandError
from pip.status_codes import NO_MATCHES_FOUND
import pkg_resources
from distutils.version import StrictVersion, LooseVersion
from pip._vendor import pkg_resources
from pip._vendor.six.moves import xmlrpc_client


logger = logging.getLogger(__name__)


class SearchCommand(Command):
@@ -26,7 +31,7 @@ def __init__(self, *args, **kw):
'--index',
dest='index',
metavar='URL',
default='https://pypi.python.org/pypi',
default=PyPI.pypi_url,
help='Base URL of Python Package Index (default %default)')

self.parser.insert_option_group(0, self.cmd_opts)
@@ -35,9 +40,7 @@ def run(self, options, args):
if not args:
raise CommandError('Missing required argument (search query).')
query = args
index_url = options.index

pypi_hits = self.search(query, index_url)
pypi_hits = self.search(query, options)
hits = transform_hits(pypi_hits)

terminal_width = None
@@ -49,10 +52,13 @@ def run(self, options, args):
return SUCCESS
return NO_MATCHES_FOUND

def search(self, query, index_url):
pypi = xmlrpclib.ServerProxy(index_url)
hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits
def search(self, query, options):
index_url = options.index
with self._build_session(options) as session:
transport = PipXmlrpcTransport(index_url, session)
pypi = xmlrpc_client.ServerProxy(index_url, transport)
hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits


def transform_hits(hits):
@@ -71,7 +77,12 @@ def transform_hits(hits):
score = 0

if name not in packages.keys():
packages[name] = {'name': name, 'summary': summary, 'versions': [version], 'score': score}
packages[name] = {
'name': name,
'summary': summary,
'versions': [version],
'score': score,
}
else:
packages[name]['versions'].append(version)

@@ -80,53 +91,55 @@ def transform_hits(hits):
packages[name]['summary'] = summary
packages[name]['score'] = score

# each record has a unique name now, so we will convert the dict into a list sorted by score
package_list = sorted(packages.values(), key=lambda x: x['score'], reverse=True)
# each record has a unique name now, so we will convert the dict into a
# list sorted by score
package_list = sorted(
packages.values(),
key=lambda x: x['score'],
reverse=True,
)
return package_list


def print_results(hits, name_column_width=25, terminal_width=None):
def print_results(hits, name_column_width=None, terminal_width=None):
if not hits:
return
if name_column_width is None:
name_column_width = max([
len(hit['name']) + len(hit.get('versions', ['-'])[-1])
for hit in hits
]) + 4

installed_packages = [p.project_name for p in pkg_resources.working_set]
for hit in hits:
name = hit['name']
summary = hit['summary'] or ''
version = hit.get('versions', ['-'])[-1]
if terminal_width is not None:
# wrap and indent summary to fit terminal
summary = textwrap.wrap(summary, terminal_width - name_column_width - 5)
summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)
line = '%s - %s' % (name.ljust(name_column_width), summary)
target_width = terminal_width - name_column_width - 5
if target_width > 10:
# wrap and indent summary to fit terminal
summary = textwrap.wrap(summary, target_width)
summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)

line = '%-*s - %s' % (name_column_width,
'%s (%s)' % (name, version), summary)
try:
logger.notify(line)
logger.info(line)
if name in installed_packages:
dist = pkg_resources.get_distribution(name)
logger.indent += 2
try:
with indent_log():
latest = highest_version(hit['versions'])
if dist.version == latest:
logger.notify('INSTALLED: %s (latest)' % dist.version)
logger.info('INSTALLED: %s (latest)', dist.version)
else:
logger.notify('INSTALLED: %s' % dist.version)
logger.notify('LATEST: %s' % latest)
finally:
logger.indent -= 2
logger.info('INSTALLED: %s', dist.version)
logger.info('LATEST: %s', latest)
except UnicodeEncodeError:
pass


def compare_versions(version1, version2):
try:
return cmp(StrictVersion(version1), StrictVersion(version2))
# in case of abnormal version number, fall back to LooseVersion
except ValueError:
pass
try:
return cmp(LooseVersion(version1), LooseVersion(version2))
except TypeError:
# certain LooseVersion comparions raise due to unorderable types,
# fallback to string comparison
return cmp([str(v) for v in LooseVersion(version1).version],
[str(v) for v in LooseVersion(version2).version])


def highest_version(versions):
return reduce((lambda v1, v2: compare_versions(v1, v2) == 1 and v1 or v2), versions)
return next(iter(
sorted(versions, key=pkg_resources.parse_version, reverse=True)
))
Binary file not shown.