@@ -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 ())