Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../lib/python2..../site-pac.../pip
File: basecommand.py
"""Base Command class, and related routines"""
[0] Fix | Delete
from __future__ import absolute_import
[1] Fix | Delete
[2] Fix | Delete
import logging
[3] Fix | Delete
import os
[4] Fix | Delete
import sys
[5] Fix | Delete
import optparse
[6] Fix | Delete
import warnings
[7] Fix | Delete
[8] Fix | Delete
from pip import cmdoptions
[9] Fix | Delete
from pip.index import PackageFinder
[10] Fix | Delete
from pip.locations import running_under_virtualenv
[11] Fix | Delete
from pip.download import PipSession
[12] Fix | Delete
from pip.exceptions import (BadCommand, InstallationError, UninstallationError,
[13] Fix | Delete
CommandError, PreviousBuildDirError)
[14] Fix | Delete
[15] Fix | Delete
from pip.compat import logging_dictConfig
[16] Fix | Delete
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
[17] Fix | Delete
from pip.req import InstallRequirement, parse_requirements
[18] Fix | Delete
from pip.status_codes import (
[19] Fix | Delete
SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,
[20] Fix | Delete
PREVIOUS_BUILD_DIR_ERROR,
[21] Fix | Delete
)
[22] Fix | Delete
from pip.utils import deprecation, get_prog, normalize_path
[23] Fix | Delete
from pip.utils.logging import IndentingFormatter
[24] Fix | Delete
from pip.utils.outdated import pip_version_check
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
__all__ = ['Command']
[28] Fix | Delete
[29] Fix | Delete
[30] Fix | Delete
logger = logging.getLogger(__name__)
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
class Command(object):
[34] Fix | Delete
name = None
[35] Fix | Delete
usage = None
[36] Fix | Delete
hidden = False
[37] Fix | Delete
log_streams = ("ext://sys.stdout", "ext://sys.stderr")
[38] Fix | Delete
[39] Fix | Delete
def __init__(self, isolated=False):
[40] Fix | Delete
parser_kw = {
[41] Fix | Delete
'usage': self.usage,
[42] Fix | Delete
'prog': '%s %s' % (get_prog(), self.name),
[43] Fix | Delete
'formatter': UpdatingDefaultsHelpFormatter(),
[44] Fix | Delete
'add_help_option': False,
[45] Fix | Delete
'name': self.name,
[46] Fix | Delete
'description': self.__doc__,
[47] Fix | Delete
'isolated': isolated,
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
self.parser = ConfigOptionParser(**parser_kw)
[51] Fix | Delete
[52] Fix | Delete
# Commands should add options to this option group
[53] Fix | Delete
optgroup_name = '%s Options' % self.name.capitalize()
[54] Fix | Delete
self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
[55] Fix | Delete
[56] Fix | Delete
# Add the general options
[57] Fix | Delete
gen_opts = cmdoptions.make_option_group(
[58] Fix | Delete
cmdoptions.general_group,
[59] Fix | Delete
self.parser,
[60] Fix | Delete
)
[61] Fix | Delete
self.parser.add_option_group(gen_opts)
[62] Fix | Delete
[63] Fix | Delete
def _build_session(self, options, retries=None, timeout=None):
[64] Fix | Delete
session = PipSession(
[65] Fix | Delete
cache=(
[66] Fix | Delete
normalize_path(os.path.join(options.cache_dir, "http"))
[67] Fix | Delete
if options.cache_dir else None
[68] Fix | Delete
),
[69] Fix | Delete
retries=retries if retries is not None else options.retries,
[70] Fix | Delete
insecure_hosts=options.trusted_hosts,
[71] Fix | Delete
)
[72] Fix | Delete
[73] Fix | Delete
# Handle custom ca-bundles from the user
[74] Fix | Delete
if options.cert:
[75] Fix | Delete
session.verify = options.cert
[76] Fix | Delete
[77] Fix | Delete
# Handle SSL client certificate
[78] Fix | Delete
if options.client_cert:
[79] Fix | Delete
session.cert = options.client_cert
[80] Fix | Delete
[81] Fix | Delete
# Handle timeouts
[82] Fix | Delete
if options.timeout or timeout:
[83] Fix | Delete
session.timeout = (
[84] Fix | Delete
timeout if timeout is not None else options.timeout
[85] Fix | Delete
)
[86] Fix | Delete
[87] Fix | Delete
# Handle configured proxies
[88] Fix | Delete
if options.proxy:
[89] Fix | Delete
session.proxies = {
[90] Fix | Delete
"http": options.proxy,
[91] Fix | Delete
"https": options.proxy,
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
# Determine if we can prompt the user for authentication or not
[95] Fix | Delete
session.auth.prompting = not options.no_input
[96] Fix | Delete
[97] Fix | Delete
return session
[98] Fix | Delete
[99] Fix | Delete
def parse_args(self, args):
[100] Fix | Delete
# factored out for testability
[101] Fix | Delete
return self.parser.parse_args(args)
[102] Fix | Delete
[103] Fix | Delete
def main(self, args):
[104] Fix | Delete
options, args = self.parse_args(args)
[105] Fix | Delete
[106] Fix | Delete
if options.quiet:
[107] Fix | Delete
if options.quiet == 1:
[108] Fix | Delete
level = "WARNING"
[109] Fix | Delete
if options.quiet == 2:
[110] Fix | Delete
level = "ERROR"
[111] Fix | Delete
else:
[112] Fix | Delete
level = "CRITICAL"
[113] Fix | Delete
elif options.verbose:
[114] Fix | Delete
level = "DEBUG"
[115] Fix | Delete
else:
[116] Fix | Delete
level = "INFO"
[117] Fix | Delete
[118] Fix | Delete
# The root logger should match the "console" level *unless* we
[119] Fix | Delete
# specified "--log" to send debug logs to a file.
[120] Fix | Delete
root_level = level
[121] Fix | Delete
if options.log:
[122] Fix | Delete
root_level = "DEBUG"
[123] Fix | Delete
[124] Fix | Delete
logging_dictConfig({
[125] Fix | Delete
"version": 1,
[126] Fix | Delete
"disable_existing_loggers": False,
[127] Fix | Delete
"filters": {
[128] Fix | Delete
"exclude_warnings": {
[129] Fix | Delete
"()": "pip.utils.logging.MaxLevelFilter",
[130] Fix | Delete
"level": logging.WARNING,
[131] Fix | Delete
},
[132] Fix | Delete
},
[133] Fix | Delete
"formatters": {
[134] Fix | Delete
"indent": {
[135] Fix | Delete
"()": IndentingFormatter,
[136] Fix | Delete
"format": "%(message)s",
[137] Fix | Delete
},
[138] Fix | Delete
},
[139] Fix | Delete
"handlers": {
[140] Fix | Delete
"console": {
[141] Fix | Delete
"level": level,
[142] Fix | Delete
"class": "pip.utils.logging.ColorizedStreamHandler",
[143] Fix | Delete
"stream": self.log_streams[0],
[144] Fix | Delete
"filters": ["exclude_warnings"],
[145] Fix | Delete
"formatter": "indent",
[146] Fix | Delete
},
[147] Fix | Delete
"console_errors": {
[148] Fix | Delete
"level": "WARNING",
[149] Fix | Delete
"class": "pip.utils.logging.ColorizedStreamHandler",
[150] Fix | Delete
"stream": self.log_streams[1],
[151] Fix | Delete
"formatter": "indent",
[152] Fix | Delete
},
[153] Fix | Delete
"user_log": {
[154] Fix | Delete
"level": "DEBUG",
[155] Fix | Delete
"class": "pip.utils.logging.BetterRotatingFileHandler",
[156] Fix | Delete
"filename": options.log or "/dev/null",
[157] Fix | Delete
"delay": True,
[158] Fix | Delete
"formatter": "indent",
[159] Fix | Delete
},
[160] Fix | Delete
},
[161] Fix | Delete
"root": {
[162] Fix | Delete
"level": root_level,
[163] Fix | Delete
"handlers": list(filter(None, [
[164] Fix | Delete
"console",
[165] Fix | Delete
"console_errors",
[166] Fix | Delete
"user_log" if options.log else None,
[167] Fix | Delete
])),
[168] Fix | Delete
},
[169] Fix | Delete
# Disable any logging besides WARNING unless we have DEBUG level
[170] Fix | Delete
# logging enabled. These use both pip._vendor and the bare names
[171] Fix | Delete
# for the case where someone unbundles our libraries.
[172] Fix | Delete
"loggers": dict(
[173] Fix | Delete
(
[174] Fix | Delete
name,
[175] Fix | Delete
{
[176] Fix | Delete
"level": (
[177] Fix | Delete
"WARNING"
[178] Fix | Delete
if level in ["INFO", "ERROR"]
[179] Fix | Delete
else "DEBUG"
[180] Fix | Delete
),
[181] Fix | Delete
},
[182] Fix | Delete
)
[183] Fix | Delete
for name in ["pip._vendor", "distlib", "requests", "urllib3"]
[184] Fix | Delete
),
[185] Fix | Delete
})
[186] Fix | Delete
[187] Fix | Delete
if sys.version_info[:2] == (2, 6):
[188] Fix | Delete
warnings.warn(
[189] Fix | Delete
"Python 2.6 is no longer supported by the Python core team, "
[190] Fix | Delete
"please upgrade your Python. A future version of pip will "
[191] Fix | Delete
"drop support for Python 2.6",
[192] Fix | Delete
deprecation.Python26DeprecationWarning
[193] Fix | Delete
)
[194] Fix | Delete
[195] Fix | Delete
# TODO: try to get these passing down from the command?
[196] Fix | Delete
# without resorting to os.environ to hold these.
[197] Fix | Delete
[198] Fix | Delete
if options.no_input:
[199] Fix | Delete
os.environ['PIP_NO_INPUT'] = '1'
[200] Fix | Delete
[201] Fix | Delete
if options.exists_action:
[202] Fix | Delete
os.environ['PIP_EXISTS_ACTION'] = ' '.join(options.exists_action)
[203] Fix | Delete
[204] Fix | Delete
if options.require_venv:
[205] Fix | Delete
# If a venv is required check if it can really be found
[206] Fix | Delete
if not running_under_virtualenv():
[207] Fix | Delete
logger.critical(
[208] Fix | Delete
'Could not find an activated virtualenv (required).'
[209] Fix | Delete
)
[210] Fix | Delete
sys.exit(VIRTUALENV_NOT_FOUND)
[211] Fix | Delete
[212] Fix | Delete
try:
[213] Fix | Delete
status = self.run(options, args)
[214] Fix | Delete
# FIXME: all commands should return an exit status
[215] Fix | Delete
# and when it is done, isinstance is not needed anymore
[216] Fix | Delete
if isinstance(status, int):
[217] Fix | Delete
return status
[218] Fix | Delete
except PreviousBuildDirError as exc:
[219] Fix | Delete
logger.critical(str(exc))
[220] Fix | Delete
logger.debug('Exception information:', exc_info=True)
[221] Fix | Delete
[222] Fix | Delete
return PREVIOUS_BUILD_DIR_ERROR
[223] Fix | Delete
except (InstallationError, UninstallationError, BadCommand) as exc:
[224] Fix | Delete
logger.critical(str(exc))
[225] Fix | Delete
logger.debug('Exception information:', exc_info=True)
[226] Fix | Delete
[227] Fix | Delete
return ERROR
[228] Fix | Delete
except CommandError as exc:
[229] Fix | Delete
logger.critical('ERROR: %s', exc)
[230] Fix | Delete
logger.debug('Exception information:', exc_info=True)
[231] Fix | Delete
[232] Fix | Delete
return ERROR
[233] Fix | Delete
except KeyboardInterrupt:
[234] Fix | Delete
logger.critical('Operation cancelled by user')
[235] Fix | Delete
logger.debug('Exception information:', exc_info=True)
[236] Fix | Delete
[237] Fix | Delete
return ERROR
[238] Fix | Delete
except:
[239] Fix | Delete
logger.critical('Exception:', exc_info=True)
[240] Fix | Delete
[241] Fix | Delete
return UNKNOWN_ERROR
[242] Fix | Delete
finally:
[243] Fix | Delete
# Check if we're using the latest version of pip available
[244] Fix | Delete
if (not options.disable_pip_version_check and not
[245] Fix | Delete
getattr(options, "no_index", False)):
[246] Fix | Delete
with self._build_session(
[247] Fix | Delete
options,
[248] Fix | Delete
retries=0,
[249] Fix | Delete
timeout=min(5, options.timeout)) as session:
[250] Fix | Delete
pip_version_check(session)
[251] Fix | Delete
[252] Fix | Delete
return SUCCESS
[253] Fix | Delete
[254] Fix | Delete
[255] Fix | Delete
class RequirementCommand(Command):
[256] Fix | Delete
[257] Fix | Delete
@staticmethod
[258] Fix | Delete
def populate_requirement_set(requirement_set, args, options, finder,
[259] Fix | Delete
session, name, wheel_cache):
[260] Fix | Delete
"""
[261] Fix | Delete
Marshal cmd line args into a requirement set.
[262] Fix | Delete
"""
[263] Fix | Delete
for filename in options.constraints:
[264] Fix | Delete
for req in parse_requirements(
[265] Fix | Delete
filename,
[266] Fix | Delete
constraint=True, finder=finder, options=options,
[267] Fix | Delete
session=session, wheel_cache=wheel_cache):
[268] Fix | Delete
requirement_set.add_requirement(req)
[269] Fix | Delete
[270] Fix | Delete
for req in args:
[271] Fix | Delete
requirement_set.add_requirement(
[272] Fix | Delete
InstallRequirement.from_line(
[273] Fix | Delete
req, None, isolated=options.isolated_mode,
[274] Fix | Delete
wheel_cache=wheel_cache
[275] Fix | Delete
)
[276] Fix | Delete
)
[277] Fix | Delete
[278] Fix | Delete
for req in options.editables:
[279] Fix | Delete
requirement_set.add_requirement(
[280] Fix | Delete
InstallRequirement.from_editable(
[281] Fix | Delete
req,
[282] Fix | Delete
default_vcs=options.default_vcs,
[283] Fix | Delete
isolated=options.isolated_mode,
[284] Fix | Delete
wheel_cache=wheel_cache
[285] Fix | Delete
)
[286] Fix | Delete
)
[287] Fix | Delete
[288] Fix | Delete
found_req_in_file = False
[289] Fix | Delete
for filename in options.requirements:
[290] Fix | Delete
for req in parse_requirements(
[291] Fix | Delete
filename,
[292] Fix | Delete
finder=finder, options=options, session=session,
[293] Fix | Delete
wheel_cache=wheel_cache):
[294] Fix | Delete
found_req_in_file = True
[295] Fix | Delete
requirement_set.add_requirement(req)
[296] Fix | Delete
# If --require-hashes was a line in a requirements file, tell
[297] Fix | Delete
# RequirementSet about it:
[298] Fix | Delete
requirement_set.require_hashes = options.require_hashes
[299] Fix | Delete
[300] Fix | Delete
if not (args or options.editables or found_req_in_file):
[301] Fix | Delete
opts = {'name': name}
[302] Fix | Delete
if options.find_links:
[303] Fix | Delete
msg = ('You must give at least one requirement to '
[304] Fix | Delete
'%(name)s (maybe you meant "pip %(name)s '
[305] Fix | Delete
'%(links)s"?)' %
[306] Fix | Delete
dict(opts, links=' '.join(options.find_links)))
[307] Fix | Delete
else:
[308] Fix | Delete
msg = ('You must give at least one requirement '
[309] Fix | Delete
'to %(name)s (see "pip help %(name)s")' % opts)
[310] Fix | Delete
logger.warning(msg)
[311] Fix | Delete
[312] Fix | Delete
def _build_package_finder(self, options, session,
[313] Fix | Delete
platform=None, python_versions=None,
[314] Fix | Delete
abi=None, implementation=None):
[315] Fix | Delete
"""
[316] Fix | Delete
Create a package finder appropriate to this requirement command.
[317] Fix | Delete
"""
[318] Fix | Delete
index_urls = [options.index_url] + options.extra_index_urls
[319] Fix | Delete
if options.no_index:
[320] Fix | Delete
logger.debug('Ignoring indexes: %s', ','.join(index_urls))
[321] Fix | Delete
index_urls = []
[322] Fix | Delete
[323] Fix | Delete
return PackageFinder(
[324] Fix | Delete
find_links=options.find_links,
[325] Fix | Delete
format_control=options.format_control,
[326] Fix | Delete
index_urls=index_urls,
[327] Fix | Delete
trusted_hosts=options.trusted_hosts,
[328] Fix | Delete
allow_all_prereleases=options.pre,
[329] Fix | Delete
process_dependency_links=options.process_dependency_links,
[330] Fix | Delete
session=session,
[331] Fix | Delete
platform=platform,
[332] Fix | Delete
versions=python_versions,
[333] Fix | Delete
abi=abi,
[334] Fix | Delete
implementation=implementation,
[335] Fix | Delete
)
[336] Fix | Delete
[337] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function