@@ -138,10 +138,14 @@ def bundle_python_resources(
138
138
zf ,
139
139
__graalpython__ .capi_home ,
140
140
f"{ vfs_prefix } /{ home_prefix } /lib-graalpython" ,
141
- data_only = True ,
141
+ path_filter = lambda file = None , dir = None : file and file . endswith ( ".py" ) ,
142
142
)
143
143
write_folder_to_zipfile (
144
- zf , __graalpython__ .stdlib_home , f"{ vfs_prefix } /{ home_prefix } /lib-python/3"
144
+ zf ,
145
+ __graalpython__ .stdlib_home ,
146
+ f"{ vfs_prefix } /{ home_prefix } /lib-python/3" ,
147
+ path_filter = lambda file = None , dir = None : dir
148
+ and dir in ["idlelib" , "ensurepip" , "tkinter" , "turtledemo" ],
145
149
)
146
150
147
151
if venv :
@@ -157,30 +161,27 @@ def bundle_python_resources(
157
161
os .unlink (name )
158
162
159
163
160
- def write_folder_to_zipfile (zf , folder , prefix , data_only = False ):
164
+ def write_folder_to_zipfile (zf , folder , prefix , path_filter = lambda file = None , dir = None : False ):
161
165
"""
162
166
Store a folder with Python modules. We do not store source code, instead,
163
- we for each py file we create a pyc entry rightaway. .py files are created
164
- as empty files, their hashed bitcode set to not check the file hash. This
165
- ensures that packages are still imported correctly without storing any
166
- source code in directly. Any other resources in the folder are stored
167
- as-is. If data_only is given, neither .py nor .pyc files are added to the
168
- archive.
167
+ we for each py file we create a pyc entry rightaway. Any other resources in the
168
+ folder are stored as-is. If data_only is given, neither .py nor .pyc files are
169
+ added to the archive.
169
170
"""
170
171
folder = folder .rstrip ("/\\ " )
171
172
for root , dirs , files in os .walk (folder ):
173
+ dirs [:] = filter (lambda d : not path_filter (dir = d ) and d != "__pycache__" , dirs )
172
174
for dir in dirs :
173
175
fullname = os .path .join (root , dir )
174
176
arcname = os .path .join (prefix , fullname [len (folder ) + 1 :])
175
177
zf .writestr (zipfile .ZipInfo (f"{ arcname } /" ), b"" )
176
178
for file in files :
179
+ if path_filter (file = file ):
180
+ continue
177
181
fullname = os .path .join (root , file )
178
182
arcname = os .path .join (prefix , fullname [len (folder ) + 1 :])
179
183
if file .endswith (".py" ):
180
- if data_only :
181
- continue
182
- zf .writestr (arcname , b"" )
183
- pycname = _frozen_importlib_external .cache_from_source (fullname )
184
+ arcname = os .path .splitext (arcname )[0 ] + ".pyc"
184
185
with io .open_code (fullname ) as sourcefile :
185
186
code = sourcefile .read ()
186
187
try :
@@ -191,10 +192,7 @@ def write_folder_to_zipfile(zf, folder, prefix, data_only=False):
191
192
data = _frozen_importlib_external ._code_to_hash_pyc (
192
193
bytecode , b"0" * 8 , checked = False
193
194
)
194
- arcname = os .path .join (prefix , pycname [len (folder ) + 1 :])
195
195
zf .writestr (arcname , data )
196
- elif file .endswith (".pyc" ):
197
- pass
198
196
else :
199
197
zf .write (fullname , arcname )
200
198
0 commit comments