Skip to content

Commit b19d15e

Browse files
author
lidong
committed
fix test_pip_install_target
1 parent ff572b7 commit b19d15e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

test_utils.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -724,20 +724,26 @@ def test_pip_install_target():
724724
"./mock_dir", ["six", "--no-cache-dir"], force=False, sys_path=None
725725
)
726726
assert time.time() - start_time > 0.1
727-
sys.modules.pop("six", None)
728-
import six
727+
try:
728+
sys.modules.pop("six", None)
729+
import six
729730

730-
assert "mock_dir" not in six.__file__
731+
assert "mock_dir" not in six.__file__
732+
except ImportError:
733+
pass
731734
# hit md5 cache, force=False, sys_path ignored
732735
start_time = time.time()
733736
assert not pip_install_target(
734737
"./mock_dir", ["six", "--no-cache-dir"], force=False, sys_path=0
735738
)
736739
assert time.time() - start_time < 0.1
737-
sys.modules.pop("six", None)
738-
import six
740+
try:
741+
sys.modules.pop("six", None)
742+
import six
739743

740-
assert "mock_dir" not in six.__file__
744+
assert "mock_dir" not in six.__file__
745+
except ImportError:
746+
pass
741747
# test force=True, sys_path=0 worked
742748
start_time = time.time()
743749
assert pip_install_target(
@@ -759,7 +765,7 @@ def main():
759765
count = 0
760766
items = list(globals().items())
761767
total = len(items)
762-
name_list = ''
768+
name_list = ""
763769
for name, func in items:
764770
if name_list and name not in name_list:
765771
continue

zipapps/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ def pip_install_target(
652652
md5_path = target / ZipApp.get_md5(pip_args)
653653
if not force and md5_path.exists():
654654
return False
655+
if force:
656+
shutil.rmtree(target.as_posix())
655657
ZipApp._pip_install(target_dir=target, pip_args=pip_args)
656658
if rm_patterns:
657659
ZipApp._rm_with_patterns(target, patterns=rm_patterns.split(","))

0 commit comments

Comments
 (0)