MCPcopy Index your code
hub / github.com/python/cpython / _bootstrap

Function _bootstrap

Lib/ensurepip/__init__.py:125–184  ·  view source on GitHub ↗

Bootstrap pip into the current Python installation (or the given root directory). Returns pip command status code. Note that calling this function will alter both sys.path and os.environ.

(*, root=None, upgrade=False, user=False,
              altinstall=False, default_pip=False,
              verbosity=0)

Source from the content-addressed store, hash-verified

123
124
125def _bootstrap(*, root=None, upgrade=False, user=False,
126 altinstall=False, default_pip=False,
127 verbosity=0):
128 """
129 Bootstrap pip into the current Python installation (or the given root
130 directory). Returns pip command status code.
131
132 Note that calling this function will alter both sys.path and os.environ.
133 """
134
135 try:
136 import zlib
137 except ImportError:
138 raise ModuleNotFoundError(
139 "ensurepip requires the standard library module 'zlib' "
140 "to install pip."
141 ) from None
142
143 if altinstall and default_pip:
144 raise ValueError("Cannot use altinstall and default_pip together")
145
146 sys.audit("ensurepip.bootstrap", root)
147
148 _disable_pip_configuration_settings()
149
150 # By default, installing pip installs all of the
151 # following scripts (X.Y == running Python version):
152 #
153 # pip, pipX, pipX.Y
154 #
155 # pip 1.5+ allows ensurepip to request that some of those be left out
156 if altinstall:
157 # omit pip, pipX
158 os.environ["ENSUREPIP_OPTIONS"] = "altinstall"
159 elif not default_pip:
160 # omit pip
161 os.environ["ENSUREPIP_OPTIONS"] = "install"
162
163 with tempfile.TemporaryDirectory() as tmpdir:
164 # Put our bundled wheels into a temporary directory and construct the
165 # additional paths that need added to sys.path
166 tmpdir_path = Path(tmpdir)
167 with _get_pip_whl_path_ctx() as bundled_wheel_path:
168 tmp_wheel_path = tmpdir_path / bundled_wheel_path.name
169 copy2(bundled_wheel_path, tmp_wheel_path)
170
171 # Construct the arguments to be passed to the pip command
172 args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir]
173 if root:
174 args += ["--root", root]
175 if upgrade:
176 args += ["--upgrade"]
177 if user:
178 args += ["--user"]
179 if verbosity:
180 args += ["-" + "v" * verbosity]
181 if sys.implementation.cache_tag is None:
182 args += ["--no-compile"]

Callers 2

bootstrapFunction · 0.85
_mainFunction · 0.85

Calls 5

PathClass · 0.90
copy2Function · 0.90
_get_pip_whl_path_ctxFunction · 0.85
_run_pipFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…