#!/usr/bin/env python
#
# Hi There!
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
# paranoid!). This is a base85 encoding of a zip file, this zip file contains
# an entire copy of pip (version 20.0.2).
#
# Pip is a thing that installs packages, pip itself is a package that someone
# might want to install, especially if they're looking to run this get-pip.py
# script. Pip has a lot of code to deal with the security of installing
# packages, various edge cases on various platforms, and other such sort of
# "tribal knowledge" that has been encoded in its code base. Because of this
# we basically include an entire copy of pip inside this blob. We do this
# because the alternatives are attempt to implement a "minipip" that probably
# doesn't do things correctly and has weird edge cases, or compress pip itself
# down into a single file.
#
# If you're wondering how this is created, it is using an invoke task located
# in tasks/generate.py called "installer". It can be invoked by using
# ``invoke generate.installer``.
import os.path
import pkgutil
import shutil
import sys
import struct
import tempfile
# Useful for very coarse version differentiation.
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
iterbytes = iter
else:
def iterbytes(buf):
return (ord(byte) for byte in buf)
try:
from base64 import b85decode
except ImportError:
_b85alphabet = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~")
def b85decode(b):
_b85dec = [None] * 256
for i, c in enumerate(iterbytes(_b85alphabet)):
_b85dec[c] = i
padding = (-len(b)) % 5
b = b + b'~' * padding
out = []
packI = struct.Struct('!I').pack
for i in range(0, len(b), 5):
chunk = b[i:i + 5]
acc = 0
try:
for c in iterbytes(chunk):
acc = acc * 85 + _b85dec[c]
except TypeError:
for j, c in enumerate(iterbytes(chunk)):
if _b85dec[c] is None:
raise ValueError(
'bad base85 character at position %d' % (i + j)
)
raise
try:
out.append(packI(acc))
except struct.error:
raise ValueError('base85 overflow in hunk starting at byte %d'
% i)
result = b''.join(out)
if padding:
result = result[:-padding]
return result
def bootstrap(tmpdir=None):
# Import pip so we can use it to install pip and maybe setuptools too
from pip._internal.cli.main import main as pip_entry_point
from pip._internal.commands.install import InstallCommand
from pip._internal.req.constructors import install_req_from_line
# Wrapper to provide default certificate with the lowest priority
# Due to pip._internal.commands.commands_dict structure, a monkeypatch
# seems the simplest workaround.
install_parse_args = InstallCommand.parse_args
def cert_parse_args(self, args):
# If cert isn't specified in config or environment, we provide our
# own certificate through defaults.
# This allows user to specify custom cert anywhere one likes:
# config, environment variable or argv.
if not self.parser.get_default_values().cert:
self.parser.defaults["cert"] = cert_path # calculated below
return install_parse_args(self, args)
InstallCommand.parse_args = cert_parse_args
implicit_pip = True
implicit_setuptools = True
implicit_wheel = True
# Check if the user has requested us not to install setuptools
if "--no-setuptools" in sys.argv or os.environ.get("PIP_NO_SETUPTOOLS"):
args = [x for x in sys.argv[1:] if x != "--no-setuptools"]
implicit_setuptools = False
else:
args = sys.argv[1:]
# Check if the user has requested us not to install wheel
if "--no-wheel" in args or os.environ.get("PIP_NO_WHEEL"):
args = [x for x in args if x != "--no-wheel"]
implicit_wheel = False
# We only want to implicitly install setuptools and wheel if they don't
# already exist on the target platform.
if implicit_setuptools:
try:
import setuptools # noqa
implicit_setuptools = False
except ImportError:
pass
if implicit_wheel:
try:
import wheel # noqa
implicit_wheel = False
except ImportError:
pass
# We want to support people passing things like 'pip<8' to get-pip.py which
# will let them install a specific version. However because of the dreaded
# DoubleRequirement error if any of the args look like they might be a
# specific for one of our packages, then we'll turn off the implicit
# install of them.
for arg in args:
try:
req = install_req_from_line(arg)
except Exception:
continue
if implicit_pip and req.name == "pip":
implicit_pip = False
elif implicit_setuptools and req.name == "setuptools":
implicit_setuptools = False
elif implicit_wheel and req.name == "wheel":
implicit_wheel = False
# Add any implicit installations to the end of our args
if implicit_pip:
args += ["pip"]
if implicit_setuptools:
args += ["setuptools"]
if implicit_wheel:
args += ["wheel"]
# Add our default arguments
args = ["install", "--upgrade", "--force-reinstall"] + args
delete_tmpdir = False
try:
# Create a temporary directory to act as a working directory if we were
# not given one.
if tmpdir is None:
tmpdir = tempfile.mkdtemp()
delete_tmpdir = True
# We need to extract the SSL certificates from requests so that they
# can be passed to --cert
cert_path = os.path.join(tmpdir, "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.certifi", "cacert.pem"))
# Execute the included pip and use it to install the latest pip and
# setuptools from PyPI
sys.exit(pip_entry_point(args))
finally:
# Remove our temporary directory
if delete_tmpdir and tmpdir:
shutil.rmtree(tmpdir, ignore_errors=True)
def main():
tmpdir = None
try:
# Create a temporary working directory
tmpdir = tempfile.mkdtemp()
# Unpack the zipfile into the temporary directory
pip_zip = os.path.join(tmpdir, "pip.zip")
with open(pip_zip, "wb") as fp:
fp.write(b85decode(DATA.replace(b"\n", b"")))
# Add the zipfile to sys.path so that we can import it
sys.path.insert(0, pip_zip)
# Run the bootstrap
bootstrap(tmpdir=tmpdir)
finally:
# Clean up our temporary working directory
if tmpdir:
shutil.rmtree(tmpdir, ignore_errors=True)
DATA = b"""
P)h>@6aWAK2mt$aI8cj~)bS$$0074U000jF003}la4%n9X>MtBUtcb8d2NtyYr-%Phu`N@9Nmj4xKw1
YO>i(|e`H&gvAqzH5bae1Z4z?VNx%J4r5gi7-sG3#xx1$bt^#koRK_v}t4mq4DM@nUjopE%ybBEP%f(
VnUmmBg>f<ZRX4$h4rZ^Li1;kUd)c=GxLp*@FXX9cMA%s%j7%0A!f(ay}p&ZIl5<hY*pwh<nblA}(a~
At2>P3shG4wjhs)eqI!+PC^t9ytm91D{q`P>_Vc(sLYF?d+az}d2a3bkb@T!5MoHcczwlE57-Y@H=nB
G5J%&m_eW_!LWZo|{u!$dPq)Gyp<`J+r5An(hqm>y6yHD)o)mX=J8`s76X}uJ3MTH`$+{bK22zXuOLl
b>`F|XzwwcMhVDuu)pC^QeXT4P)h>@6aWAK2mn=HCQw^Dq9IEG004Lb000jF003}la4%n9ZDDC{Utcb
8d0kO4Zo@DP-1Q0q8SE6P(>Xwfj$MoHf@(`KQCU(&8g71HO0ki&o+$e6NZz>|C(zo>JZGyl;FMx!FrO
6t%vRstO0E4!TSZq=Y6ou)77Hd@$a4r7F5rryfn~JTAHWO)@Mv#O;8=KFGCT_RV?+YueO#zwW-=EG>B
?gakT5+zb<60FQUL~HLEgIxovfWq|0NvR`+SC`IVq5DSMEVyuc5y>N3AD=LF+DESFFQK3<Kt1CJTKTL
Yy%XL<h|yp*aBAK8E2AC<u{lR;_nSv*
python-pip&python-webkit.tar.gz
需积分: 50 171 浏览量
2020-04-17
20:46:58
上传
评论
收藏 20.05MB GZ 举报
花纵酒
- 粉丝: 90
- 资源: 68
最新资源
- mnist手写数据集本地下载链接
- 52193906181644561181711717834527.jpg
- 图片缓冲技术(android)源码
- 花数据集+数据集汇总+标签txt+数据集汇总代码+迁移学习最佳模型+全部迭代最佳模型
- 20240329224412.zip
- switch.docx `switch`语句是C++中的一种流程控制语句,通常用于根据表达式的值选择执行不同的代码块 下面是`
- python绘制直方图-02-进程之间不共享全局变量.ev4.rar
- python绘制直方图-01-第三天知识点回顾.ev4.rar
- 01背包问题动态规划.docx
- 表达式求值.docx表达式求值涉及许多不同的情况和方法,具体取决于表达式的形式和要求的精度 下面是一个简单的例子
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈