MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _bootstrap

Function _bootstrap

tools/python-3.11.9-amd64/Lib/ensurepip/__init__.py:140–202  ·  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

138
139
140def _bootstrap(*, root=None, upgrade=False, user=False,
141 altinstall=False, default_pip=False,
142 verbosity=0):
143 """
144 Bootstrap pip into the current Python installation (or the given root
145 directory). Returns pip command status code.
146
147 Note that calling this function will alter both sys.path and os.environ.
148 """
149 if altinstall and default_pip:
150 raise ValueError("Cannot use altinstall and default_pip together")
151
152 sys.audit("ensurepip.bootstrap", root)
153
154 _disable_pip_configuration_settings()
155
156 # By default, installing pip and setuptools installs all of the
157 # following scripts (X.Y == running Python version):
158 #
159 # pip, pipX, pipX.Y, easy_install, easy_install-X.Y
160 #
161 # pip 1.5+ allows ensurepip to request that some of those be left out
162 if altinstall:
163 # omit pip, pipX and easy_install
164 os.environ["ENSUREPIP_OPTIONS"] = "altinstall"
165 elif not default_pip:
166 # omit pip and easy_install
167 os.environ["ENSUREPIP_OPTIONS"] = "install"
168
169 with tempfile.TemporaryDirectory() as tmpdir:
170 # Put our bundled wheels into a temporary directory and construct the
171 # additional paths that need added to sys.path
172 additional_paths = []
173 for name, package in _get_packages().items():
174 if package.wheel_name:
175 # Use bundled wheel package
176 wheel_name = package.wheel_name
177 wheel_path = resources.files("ensurepip") / "_bundled" / wheel_name
178 whl = wheel_path.read_bytes()
179 else:
180 # Use the wheel package directory
181 with open(package.wheel_path, "rb") as fp:
182 whl = fp.read()
183 wheel_name = os.path.basename(package.wheel_path)
184
185 filename = os.path.join(tmpdir, wheel_name)
186 with open(filename, "wb") as fp:
187 fp.write(whl)
188
189 additional_paths.append(filename)
190
191 # Construct the arguments to be passed to the pip command
192 args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir]
193 if root:
194 args += ["--root", root]
195 if upgrade:
196 args += ["--upgrade"]
197 if user:

Callers 2

bootstrapFunction · 0.85
_mainFunction · 0.85

Calls 12

_get_packagesFunction · 0.85
_run_pipFunction · 0.85
basenameMethod · 0.80
openFunction · 0.50
itemsMethod · 0.45
filesMethod · 0.45
read_bytesMethod · 0.45
readMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected