| 78 | |
| 79 | |
| 80 | def bootstrap(tmpdir=None): |
| 81 | # Import pip so we can use it to install pip and maybe setuptools too |
| 82 | from pip._internal.cli.main import main as pip_entry_point |
| 83 | from pip._internal.commands.install import InstallCommand |
| 84 | from pip._internal.req.constructors import install_req_from_line |
| 85 | |
| 86 | # Wrapper to provide default certificate with the lowest priority |
| 87 | # Due to pip._internal.commands.commands_dict structure, a monkeypatch |
| 88 | # seems the simplest workaround. |
| 89 | install_parse_args = InstallCommand.parse_args |
| 90 | def cert_parse_args(self, args): |
| 91 | # If cert isn't specified in config or environment, we provide our |
| 92 | # own certificate through defaults. |
| 93 | # This allows user to specify custom cert anywhere one likes: |
| 94 | # config, environment variable or argv. |
| 95 | if not self.parser.get_default_values().cert: |
| 96 | self.parser.defaults["cert"] = cert_path # calculated below |
| 97 | return install_parse_args(self, args) |
| 98 | InstallCommand.parse_args = cert_parse_args |
| 99 | |
| 100 | implicit_pip = True |
| 101 | implicit_setuptools = True |
| 102 | implicit_wheel = True |
| 103 | |
| 104 | # Check if the user has requested us not to install setuptools |
| 105 | if "--no-setuptools" in sys.argv or os.environ.get("PIP_NO_SETUPTOOLS"): |
| 106 | args = [x for x in sys.argv[1:] if x != "--no-setuptools"] |
| 107 | implicit_setuptools = False |
| 108 | else: |
| 109 | args = sys.argv[1:] |
| 110 | |
| 111 | # Check if the user has requested us not to install wheel |
| 112 | if "--no-wheel" in args or os.environ.get("PIP_NO_WHEEL"): |
| 113 | args = [x for x in args if x != "--no-wheel"] |
| 114 | implicit_wheel = False |
| 115 | |
| 116 | # We only want to implicitly install setuptools and wheel if they don't |
| 117 | # already exist on the target platform. |
| 118 | if implicit_setuptools: |
| 119 | try: |
| 120 | import setuptools # noqa |
| 121 | implicit_setuptools = False |
| 122 | except ImportError: |
| 123 | pass |
| 124 | if implicit_wheel: |
| 125 | try: |
| 126 | import wheel # noqa |
| 127 | implicit_wheel = False |
| 128 | except ImportError: |
| 129 | pass |
| 130 | |
| 131 | # We want to support people passing things like 'pip<8' to get-pip.py which |
| 132 | # will let them install a specific version. However because of the dreaded |
| 133 | # DoubleRequirement error if any of the args look like they might be a |
| 134 | # specific for one of our packages, then we'll turn off the implicit |
| 135 | # install of them. |
| 136 | for arg in args: |
| 137 | try: |