Skip to content

Commit 33be86b

Browse files
committedJun 4, 2024
fix pip_install_target
1 parent 4262207 commit 33be86b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed
 

‎zipapps/main.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,29 @@ def pip_install_target(
646646
pip_args: list,
647647
rm_patterns: str = "*.dist-info,__pycache__",
648648
force=False,
649+
clear_dir=False,
649650
sys_path: typing.Optional[int] = None,
650651
):
652+
"""
653+
Installs target dependencies using pip and cleans up the installed files afterwards.
654+
655+
Args:
656+
target (Path): The target directory for dependency installation.
657+
pip_args (list): List of arguments for the pip install command.
658+
rm_patterns (str, optional): Patterns of files to remove after installation, defaults to "*.dist-info,__pycache__".
659+
force (bool, optional): Flag to force reinstallation, defaults to False.
660+
clear_dir (bool, optional): will rmtree the target directory while clear_dir=True.
661+
sys_path (typing.Optional[int], optional): If provided, inserts the target directory at the specified position in sys.path.
662+
663+
Returns:
664+
bool: Returns True if the installation is successful.
665+
"""
651666
target = Path(target)
652667
md5_path = target / ZipApp.get_md5(pip_args)
653668
if not force and md5_path.exists():
654669
return False
655-
if force:
656-
shutil.rmtree(target.as_posix())
670+
if clear_dir and target.is_dir():
671+
shutil.rmtree(target.as_posix(), ignore_errors=True)
657672
ZipApp._pip_install(target_dir=target, pip_args=pip_args)
658673
if rm_patterns:
659674
ZipApp._rm_with_patterns(target, patterns=rm_patterns.split(","))
@@ -663,4 +678,5 @@ def pip_install_target(
663678
sys.path.insert(sys_path, target.absolute().as_posix())
664679
return True
665680

681+
666682
create_app = ZipApp.create_app

0 commit comments

Comments
 (0)
Failed to load comments.