MCPcopy
hub / github.com/pyodide/pyodide / create_zipfile

Function create_zipfile

tools/create_zipfile.py:74–143  ·  view source on GitHub ↗

Bundle Python standard libraries into a zip file. The basic idea of this function is similar to the standard library's {ref}`zipfile.PyZipFile` class. However, we need some additional functionality for Pyodide. For example: - We need to remove some unvendored modules, e.g. `s

(
    libdirs: list[Path],
    excludes: list[str] | None = None,
    stubs: list[str] | None = None,
    output: Path | str = "python",
    filterfunc: Callable[[str, list[str]], set[str]] | None = None,
    compression_level: int = 6,
)

Source from the content-addressed store, hash-verified

72
73
74def create_zipfile(
75 libdirs: list[Path],
76 excludes: list[str] | None = None,
77 stubs: list[str] | None = None,
78 output: Path | str = "python",
79 filterfunc: Callable[[str, list[str]], set[str]] | None = None,
80 compression_level: int = 6,
81) -> None:
82 """
83 Bundle Python standard libraries into a zip file.
84
85 The basic idea of this function is similar to the standard library's
86 {ref}`zipfile.PyZipFile` class.
87
88 However, we need some additional functionality for Pyodide. For example:
89
90 - We need to remove some unvendored modules, e.g. `sqlite3`
91 - We need an option to "not" compile the files in the zip file
92
93 hence this function.
94
95 Parameters
96 ----------
97 libdirs
98 List of paths to the directory containing the Python standard library or extra packages.
99
100 excludes
101 List of files to exclude from the zip file.
102
103 stubs
104 List of files that are replaced by JS implementations.
105
106 output
107 Path to the output zip file. Defaults to python.zip.
108
109 filterfunc
110 A function that filters the files to be included in the zip file.
111 This function will be passed to {ref}`shutil.copytree` 's ignore argument.
112 By default, Pyodide's default filter function is used.
113
114 compression_level
115 Level of zip compression to apply. 0 means no compression. If a strictly
116 positive integer is provided, ZIP_DEFLATED option is used.
117
118 Returns
119 -------
120 BytesIO
121 A BytesIO object containing the zip file.
122 """
123
124 archive = Path(output)
125 excludes = excludes or []
126 stubs = stubs or []
127
128 with TemporaryDirectory() as temp_dir_str:
129 temp_dir = Path(temp_dir_str)
130
131 for libdir in libdirs:

Callers 3

test_create_zipFunction · 0.90
test_import_from_zipFunction · 0.90
create_zipfile.pyFile · 0.85

Calls 2

default_filterfuncFunction · 0.85
make_zip_archiveFunction · 0.85

Tested by 2

test_create_zipFunction · 0.72
test_import_from_zipFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…