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

Function generate_source_files

PC/layout/main.py:374–427  ·  view source on GitHub ↗
(ns)

Source from the content-addressed store, hash-verified

372
373
374def generate_source_files(ns):
375 if ns.zip_lib:
376 zip_name = PYTHON_ZIP_NAME
377 zip_path = ns.temp / zip_name
378 if zip_path.is_file():
379 zip_path.unlink()
380 elif zip_path.is_dir():
381 log_error(
382 "Cannot create zip file because a directory exists by the same name"
383 )
384 return
385 log_info("Generating {} in {}", zip_name, ns.temp)
386 ns.temp.mkdir(parents=True, exist_ok=True)
387 with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
388 for dest, src in get_lib_layout(ns):
389 _write_to_zip(zf, dest, src, ns, checked=False)
390
391 if ns.include_underpth:
392 log_info("Generating {} in {}", PYTHON_PTH_NAME, ns.temp)
393 ns.temp.mkdir(parents=True, exist_ok=True)
394 with open(ns.temp / PYTHON_PTH_NAME, "w", encoding="utf-8") as f:
395 if ns.zip_lib:
396 print(PYTHON_ZIP_NAME, file=f)
397 if ns.include_pip:
398 print("packages", file=f)
399 else:
400 print("Lib", file=f)
401 print("Lib/site-packages", file=f)
402 if not ns.flat_dlls:
403 print("DLLs", file=f)
404 print(".", file=f)
405 print(file=f)
406 print("# Uncomment to run site.main() automatically", file=f)
407 print("#import site", file=f)
408
409 if ns.include_pip:
410 log_info("Extracting pip")
411 extract_pip_files(ns)
412
413 if ns.include_install_json:
414 log_info("Generating __install__.json in {}", ns.temp)
415 ns.temp.mkdir(parents=True, exist_ok=True)
416 with open(ns.temp / "__install__.json", "w", encoding="utf-8") as f:
417 json.dump(calculate_install_json(ns), f, indent=2)
418 elif ns.include_install_embed_json:
419 log_info("Generating embeddable __install__.json in {}", ns.temp)
420 ns.temp.mkdir(parents=True, exist_ok=True)
421 with open(ns.temp / "__install__.json", "w", encoding="utf-8") as f:
422 json.dump(calculate_install_json(ns, for_embed=True), f, indent=2)
423 elif ns.include_install_test_json:
424 log_info("Generating test __install__.json in {}", ns.temp)
425 ns.temp.mkdir(parents=True, exist_ok=True)
426 with open(ns.temp / "__install__.json", "w", encoding="utf-8") as f:
427 json.dump(calculate_install_json(ns, for_test=True), f, indent=2)
428
429
430def _create_zip_file(ns):

Callers 1

mainFunction · 0.85

Calls 12

log_errorFunction · 0.85
log_infoFunction · 0.85
get_lib_layoutFunction · 0.85
_write_to_zipFunction · 0.85
extract_pip_filesFunction · 0.85
calculate_install_jsonFunction · 0.85
openFunction · 0.50
is_fileMethod · 0.45
unlinkMethod · 0.45
is_dirMethod · 0.45
mkdirMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…