-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_utils.py
116 lines (94 loc) · 3.53 KB
/
setup_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import os
import sys
from typing import Dict, Optional
from .executors import CommandExecutor, FinallyCallback, LineCallback
_COMMAND_EXECUTOR: Optional[CommandExecutor] = None
def _get_command_executor() -> CommandExecutor:
global _COMMAND_EXECUTOR # pylint: disable=global-statement
if _COMMAND_EXECUTOR is None:
_COMMAND_EXECUTOR = CommandExecutor()
return _COMMAND_EXECUTOR
def is_installer_running() -> bool:
return _get_command_executor().is_running
def get_installer_exit_code() -> int:
return _get_command_executor().exit_code
def get_required_modules() -> Dict[str, bool]:
import pkgutil # pylint: disable=import-outside-toplevel
modules = {
'torch': False,
'numpy': False,
'smplx': False,
'scipy': False,
'chumpy': False,
'clip': False,
}
modules.update(
(m.name, True) for m in pkgutil.iter_modules() if m.name in modules
)
return modules
def install_python_modules(use_gpu=False, line_callback: Optional[LineCallback] = None, finally_callback: Optional[FinallyCallback] = None):
site_packages_path = next((p for p in sys.path if p.endswith('site-packages')), None)
target_option = ['--target', site_packages_path] if site_packages_path else []
_get_command_executor().exec_command(
# ensurepip
sys.executable, '-m', 'ensurepip',
line_callback=line_callback,
finally_callback=lambda e: e.exec_command(
# force install setuptools
sys.executable, '-m', 'pip', 'install',
*target_option,
'--disable-pip-version-check',
'--no-input',
'--ignore-installed',
'setuptools',
line_callback=line_callback,
finally_callback=lambda e: e.exec_command(
# and then install depending modules
sys.executable, '-m', 'pip', 'install',
*target_option,
'--disable-pip-version-check',
'--no-input',
# '--upgrade',
# '--upgrade-strategy', 'only-if-needed',
# '--no-cache-dir',
'--exists-action', 'i',
# '--ignore-installed',
'--extra-index-url', 'https://download.pytorch.org/whl/cu116' if use_gpu else 'https://download.pytorch.org/whl/cpu',
'torch',
'numpy<1.24.0',
'git+https://github.com/openai/CLIP.git',
'smplx',
'scipy',
'chumpy',
line_callback=line_callback, finally_callback=finally_callback
)
)
)
def uninstall_python_modules(line_callback: Optional[LineCallback] = None, finally_callback: Optional[FinallyCallback] = None):
_get_command_executor().exec_command(
sys.executable, '-m', 'pip', 'uninstall',
'--yes',
'torch',
'typing-extensions',
# 'certifi',
'chumpy',
'clip',
'ftfy',
# 'idna',
# 'numpy',
'pillow',
'regex',
'scipy',
'six',
'smplx',
'torchvision',
'tqdm',
# 'urllib3',
'wcwidth',
line_callback=line_callback, finally_callback=finally_callback
)
def list_python_modules(line_callback: Optional[LineCallback] = None, finally_callback: Optional[FinallyCallback] = None):
_get_command_executor().exec_command(
sys.executable, '-m', 'pip', 'list', '-v',
line_callback=line_callback, finally_callback=finally_callback
)