File tree Expand file tree Collapse file tree 6 files changed +21
-10
lines changed
Expand file tree Collapse file tree 6 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -77,9 +77,8 @@ So, what could `zipapps` be?
7777
7878## 4. Activate the ` .pyz ` environment
7979
80- 1 . one way is use ` zipimport ` (Recommended)
81- 1 . load from pyz file
82- 1 . python < 3.10: ` import zipimport; zipimport.zipimporter('bottle.pyz').load_module("ensure_zipapps") `
80+ 1 . use ` zipimport ` (Recommended)
81+ 1 . ` zipimport.zipimporter("some_lib_venv.pyz").find_spec("ensure_zipapps").loader.load_module("ensure_zipapps") `
8382 2 . automatically unzip cache, and add the path to sys.path
8483 1 . it can be run multiple times
85842 . if they are all pure-python code and ** no need to decompress**
Original file line number Diff line number Diff line change 1212 - Or ` zipapps.exe ... ` on Windows, or ` zipapps ` on Unix
1313 - Added ` --uv ` option to accept a path to uv, speeding up ` pip install `
1414 - Added ` --freeze-deps ` as an alias for ` --freeze-reqs `
15+ - fix Deprecated since 3.10 ` zipimporter.load_module `
1516- 2024.08.07
1617 - [ ** Compatible WARNING** ] : update ` sys_paths ` insert index from ` -1 ` to ` 0 `
1718 - disable ` --download-python ` , use ` python -m zipapps.download_python ` instead
Original file line number Diff line number Diff line change @@ -407,7 +407,9 @@ def test_env_usage():
407407 _clean_paths (root = False )
408408 create_app (output = "bottle_env.pyz" , unzip = "bottle" , pip_args = ["bottle" ])
409409 # activate sys.path and unzip cache
410- zipimport .zipimporter ("bottle_env.pyz" ).load_module ("ensure_zipapps" )
410+ spec = zipimport .zipimporter ("bottle_env.pyz" ).find_spec ("ensure_zipapps" )
411+ if spec and spec .loader :
412+ spec .loader .load_module ("ensure_zipapps" )
411413 import bottle
412414
413415 # using app unzip cache for `import ensure_zipapps`
@@ -762,7 +764,11 @@ def main():
762764
763765 count = 0
764766 start = 0
765- items = [(name , func ) for name , func in globals ().items () if name .startswith ("test_" ) and inspect .isfunction (func )]
767+ items = [
768+ (name , func )
769+ for name , func in globals ().items ()
770+ if name .startswith ("test_" ) and inspect .isfunction (func )
771+ ]
766772 name_list = ""
767773 for name , func in items :
768774 if name_list and name not in name_list :
Original file line number Diff line number Diff line change @@ -407,7 +407,7 @@ def main():
407407 default = "" ,
408408 dest = "uv_path" ,
409409 help = "the executable path of python-uv, to speed up pip install" ,
410- ) # internal use only
410+ )
411411 if len (sys .argv ) == 1 :
412412 parser .print_help ()
413413 handle_win32_embeded ()
Original file line number Diff line number Diff line change @@ -9,10 +9,14 @@ def activate(path=None):
99 path_str = path .absolute ().as_posix ()
1010 if zipfile .is_zipfile (path_str ):
1111 try :
12- _tmp = zipimport .zipimporter (path_str ).load_module ("ensure_zipapps" )
13- modules .pop (_tmp .__name__ , None )
14- del _tmp
15- return True
12+ spec = zipimport .zipimporter (path_str ).find_spec ("ensure_zipapps" )
13+ if spec and spec .loader :
14+ _tmp = spec .loader .load_module ("ensure_zipapps" )
15+ modules .pop (_tmp .__name__ , None )
16+ del _tmp
17+ return True
18+ else :
19+ raise ImportError (path_str )
1620 except ImportError as err :
1721 stderr .write (f"WARNING: activate failed for { err !r} \n " )
1822 raise err
Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ def kwargs(self):
224224 unzip_exclude = self .unzip_exclude ,
225225 chmod = self .chmod ,
226226 clear_zipapps_self = self .clear_zipapps_self ,
227+ uv_path = self .uv_path ,
227228 )
228229
229230 def ensure_args (self ):
You can’t perform that action at this time.
0 commit comments