MCPcopy Index your code
hub / github.com/kivy/python-for-android / get_package_as_folder

Function get_package_as_folder

pythonforandroid/pythonpackage.py:251–403  ·  view source on GitHub ↗

This function downloads the given package / dependency and extracts the raw contents into a folder. Afterwards, it returns a tuple with the type of distribution obtained, and the temporary folder it extracted to. It is the caller's responsibility to delete the retur

(dependency)

Source from the content-addressed store, hash-verified

249
250
251def get_package_as_folder(dependency):
252 """ This function downloads the given package / dependency and extracts
253 the raw contents into a folder.
254
255 Afterwards, it returns a tuple with the type of distribution obtained,
256 and the temporary folder it extracted to. It is the caller's
257 responsibility to delete the returned temp folder after use.
258
259 Examples of returned values:
260
261 ("source", "/tmp/pythonpackage-venv-e84toiwjw")
262 ("wheel", "/tmp/pythonpackage-venv-85u78uj")
263
264 What the distribution type will be depends on what pip decides to
265 download.
266 """
267
268 venv_parent = tempfile.mkdtemp(
269 prefix="pythonpackage-venv-"
270 )
271 try:
272 # Create a venv to install into:
273 try:
274 if int(sys.version.partition(".")[0]) < 3:
275 # Python 2.x has no venv.
276 subprocess.check_output([
277 sys.executable, # no venv conflict possible,
278 # -> no need to use system python
279 "-m", "virtualenv",
280 "--python=" + _get_system_python_executable(),
281 os.path.join(venv_parent, 'venv')
282 ], cwd=venv_parent)
283 else:
284 # On modern Python 3, use venv.
285 subprocess.check_output([
286 _get_system_python_executable(), "-m", "venv",
287 os.path.join(venv_parent, 'venv')
288 ], cwd=venv_parent)
289 except subprocess.CalledProcessError as e:
290 output = e.output.decode('utf-8', 'replace')
291 raise ValueError(
292 'venv creation unexpectedly ' +
293 'failed. error output: ' + str(output)
294 )
295 venv_path = os.path.join(venv_parent, "venv")
296
297 # Update pip and wheel in venv for latest feature support:
298 try:
299 filenotfounderror = FileNotFoundError
300 except NameError: # Python 2.
301 filenotfounderror = OSError
302 try:
303 subprocess.check_output([
304 os.path.join(venv_path, "bin", "pip"),
305 "install", "-U", "pip", "wheel",
306 ])
307 except filenotfounderror:
308 raise RuntimeError(

Calls 6

ensure_dirFunction · 0.90
rmdirFunction · 0.90
to_unicodeFunction · 0.85
transform_dep_for_pipFunction · 0.85
formatMethod · 0.80

Tested by 1