Skip to content

Commit 5e3ba4c

Browse files
committed
- fix deprecated warning since 3.10 zipimporter.load_module
1 parent 229cbe2 commit 5e3ba4c

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ jobs:
7070
python -m pip install .
7171
- name: Test with pytest
7272
run: |
73-
pip install pytest uv
74-
pytest -x
73+
pip install uv
74+
uvx pytest -x

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
- Can also be used as `uvx zipapps ...`
1212
- Or `zipapps.exe ...` on Windows, or `zipapps` on Unix
1313
- Added `--uv` option to accept a path to uv, speeding up `pip install`
14+
- `--uv=uv` or `--uv=path/to/uv`
1415
- Added `--freeze-deps` as an alias for `--freeze-reqs`
15-
- fix Deprecated since 3.10 `zipimporter.load_module`
16+
- fix deprecated warning since 3.10 `zipimporter.load_module`
1617
- 2024.08.07
1718
- [**Compatible WARNING**]: update `sys_paths` insert index from `-1` to `0`
1819
- disable `--download-python`, use `python -m zipapps.download_python` instead

test_utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ def test_quiet_mode():
4040
def test_freeze():
4141
# test --freeze-reqs
4242
_clean_paths(root=False)
43-
output = subprocess.check_output(
44-
[sys.executable, "-m", "zipapps", "--freeze-reqs", "-", "six==1.16.0"]
45-
)
43+
output = subprocess.Popen(
44+
[sys.executable, "-m", "zipapps", "--freeze-reqs", "-", "six==1.16.0"],
45+
stderr=subprocess.STDOUT,
46+
stdout=subprocess.PIPE,
47+
).communicate()[0]
4648
assert b"six==1.16.0" in output.strip(), output
4749

4850

@@ -405,6 +407,7 @@ def test_unzip_with_auto_unzip():
405407
def test_env_usage():
406408
# test ensure path for venv usage
407409
import importlib
410+
408411
_clean_paths(root=False)
409412
create_app(output="bottle_env.pyz", unzip="bottle", pip_args=["bottle"])
410413
# activate sys.path and unzip cache
@@ -644,21 +647,25 @@ def test_chmod():
644647
_clean_paths(root=False)
645648
app_path = create_app(unzip="*", pip_args=["six"], lazy_install=True)
646649
subprocess.Popen([sys.executable, str(app_path), "--activate-zipapps"]).wait()
647-
assert Path("app.pyz").stat().st_mode != 33279
650+
temp = oct(app_path.stat().st_mode)[-3:]
651+
assert temp != "777", temp
648652
for _path in Path("zipapps_cache/app").rglob("*"):
649653
if _path.name == "six.py":
650-
assert _path.stat().st_mode != 33279, _path.stat().st_mode
654+
temp = oct(_path.stat().st_mode)[-3:]
655+
assert temp != "777", temp
651656
break
652657

653658
_clean_paths(root=False)
654659
app_path = create_app(
655660
unzip="*", pip_args=["six"], lazy_install=True, chmod="777"
656661
)
657662
subprocess.Popen([sys.executable, str(app_path), "--activate-zipapps"]).wait()
658-
assert Path("app.pyz").stat().st_mode == 33279
663+
temp = oct(app_path.stat().st_mode)[-3:]
664+
assert temp == "777", temp
659665
for _path in Path("zipapps_cache/app").rglob("*"):
660666
if _path.name == "six.py":
661-
assert _path.stat().st_mode == 33279, _path.stat().st_mode
667+
temp = oct(_path.stat().st_mode)[-3:]
668+
assert temp == "777", temp
662669
break
663670

664671

zipapps/activate_zipapps.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import importlib
1+
import zipimport
22
import sys
33
import zipfile
44
from pathlib import Path
@@ -9,9 +9,14 @@ def activate(path=None):
99
path_str = path.absolute().as_posix()
1010
if zipfile.is_zipfile(path_str):
1111
try:
12-
ensure_zipapps = importlib.import_module("ensure_zipapps")
13-
del ensure_zipapps
14-
sys.modules.pop("ensure_zipapps", None)
12+
importer = zipimport.zipimporter(path_str)
13+
spec = importer.find_spec("ensure_zipapps")
14+
if spec and spec.loader is not None:
15+
ensure_zipapps = spec.loader.load_module("ensure_zipapps")
16+
del ensure_zipapps
17+
sys.modules.pop("ensure_zipapps", None)
18+
else:
19+
raise ImportError(f"Cannot find 'ensure_zipapps' in {path_str!r}")
1520
except ImportError as err:
1621
sys.stderr.write(f"WARNING: activate failed for {err!r}\n")
1722
raise err

0 commit comments

Comments
 (0)