summaryrefslogtreecommitdiff
path: root/tasks
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2014-12-22 18:32:34 -0500
committerDonald Stufft <donald@stufft.io>2014-12-22 18:32:34 -0500
commit61415ea2bfc328630de2429957adb6ab6eab263c (patch)
treea52ccd4af7a5fcebabfd57a5be89319825750817 /tasks
parent99f67cbed859d5b432e23f4bc096faacc205f1db (diff)
downloadpip-61415ea2bfc328630de2429957adb6ab6eab263c.tar.gz
Do some gymnastic to respect a certificate configured via config file
Diffstat (limited to 'tasks')
-rw-r--r--tasks/generate.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/tasks/generate.py b/tasks/generate.py
index a104c7f2d..cfc107aca 100644
--- a/tasks/generate.py
+++ b/tasks/generate.py
@@ -122,6 +122,20 @@ except ImportError:
def bootstrap(tmpdir=None):
# Import pip so we can use it to install pip and maybe setuptools too
import pip
+ from pip.commands.install import InstallCommand
+
+ # 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.
+ # 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 super(CertInstallCommand, self).parse_args(args)
+
+ pip.command_dict["install"] = CertInstallCommand
# We always want to install pip
packages = ["pip"]
@@ -153,10 +167,6 @@ def bootstrap(tmpdir=None):
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
- # Use an environment variable here so that users can still pass
- # --cert via sys.argv
- os.environ.setdefault("PIP_CERT", cert_path)
-
# Execute the included pip and use it to install the latest pip and
# setuptools from PyPI
sys.exit(pip.main(["install", "--upgrade"] + packages + args))