Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethreitz committed Mar 14, 2018
1 parent c2f7f69 commit 2fa5b84
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions get-pipenv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

# Note, this script is based off of https://bootstrap.pypa.io/get-pip.py
#
# Hi There!
Expand All @@ -21,9 +20,7 @@
# 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``.

# Note, this get-pip.py installer is modified to meet pipenv's needs.

import os.path
import pkgutil
import shutil
Expand All @@ -34,30 +31,32 @@
# 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!#$%&()*+-;<=>?@^_`{|}~")
_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
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]
chunk = b[i: i + 5]
acc = 0
try:
for c in iterbytes(chunk):
Expand All @@ -68,12 +67,13 @@ def b85decode(b):
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)
raise ValueError('base85 overflow in hunk starting at byte %d' % i)

result = b''.join(out)
if padding:
Expand All @@ -87,8 +87,10 @@ def bootstrap(tmpdir=None):
from pip.commands.install import InstallCommand
from pip.req import InstallRequirement


# Wrapper to provide default certificate with the lowest priority
class CertInstallCommand(InstallCommand):

def parse_args(self, args):
# If cert isn't specified in config or environment, we provide our
# own certificate through defaults.
Expand All @@ -99,38 +101,35 @@ def parse_args(self, args):
return super(CertInstallCommand, self).parse_args(args)

pip.commands_dict["install"] = CertInstallCommand

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
Expand All @@ -148,32 +147,27 @@ def parse_args(self, args):
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"]

# Pipenv modifications here.
args += ["pipenv"]

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.requests", "cacert.pem"))

# Execute the included pip and use it to install the latest pip and
# setuptools from PyPI
sys.exit(pip.main(["install", "--upgrade"] + args))
Expand All @@ -188,15 +182,12 @@ def main():
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:
Expand Down Expand Up @@ -20062,7 +20053,5 @@ def main():
PHp0u%!j0000806LatN$y5^m0m3X0LEPa02%-Q00000000000HlEirV;>fX>ct$E-)@JE@WwQbS-IaW
^XT2MMF<gL{Liw1^@s60RI600O3&p0G!hj0000
"""


if __name__ == "__main__":
main()
main()

0 comments on commit 2fa5b84

Please sign in to comment.