42
42
43
43
GREEN = "\033 [92m"
44
44
RED = "\033 [91m"
45
+ YELLOW = "\033 [93m"
45
46
RESET = "\033 [0m"
46
47
48
+
47
49
def check_package (name : str ) -> bool :
48
50
try :
49
51
importlib .import_module (name )
@@ -69,9 +71,10 @@ def is_tcl_tk_installed( name: str ) -> bool:
69
71
except subprocess .CalledProcessError :
70
72
return False
71
73
72
- def prompt_user_install (package_name : str ) -> bool :
74
+ def prompt_user_install (package_name : str , is_system_package : bool = False ) -> bool :
73
75
74
- response = input (f"Would you like to install { package_name } ? [Y/n]: " ).strip ().lower ()
76
+ package_type = "system" if is_system_package else "Python"
77
+ response = input (f"{ YELLOW } Would you like to install the { package_type } package \' { package_name } \' ? [Y/n]: { RESET } " ).strip ().lower ()
75
78
return response in ("" , "y" , "yes" )
76
79
77
80
def install_tcl_tk (name :str ) -> bool :
@@ -90,13 +93,14 @@ def install_system_dependencies():
90
93
91
94
if sys .platform == "darwin" :
92
95
if not shutil .which ("brew" ):
93
- if prompt_user_install ("Homebrew" ):
96
+ print (f"{ YELLOW } Homebrew is a system package manager for macOS.{ RESET } " )
97
+ if prompt_user_install ("Homebrew" , True ):
94
98
subprocess .check_call ([
95
99
"/bin/bash" , "-c" ,
96
100
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
97
101
])
98
102
else :
99
- print (" Cannot continue without Homebrew. Please install it and rerun." )
103
+ print (f" { RED } Cannot continue without Homebrew. Please install it and rerun.{ RESET } " )
100
104
sys .exit (1 )
101
105
102
106
tcl_tk = "tcl-tk@8"
@@ -106,7 +110,7 @@ def install_system_dependencies():
106
110
sys .stdout .write (f"{ GREEN } Installed{ RESET } \n " )
107
111
else :
108
112
sys .stdout .write (f"{ RED } Not installed{ RESET } \n " )
109
- if prompt_user_install (tcl_tk ):
113
+ if prompt_user_install (tcl_tk , True ):
110
114
install_tcl_tk (tcl_tk )
111
115
else :
112
116
print (f"{ RED } Cannot continue without { tcl_tk } . Please install it and try again.{ RESET } " )
@@ -144,6 +148,7 @@ def setup_tkinter():
144
148
145
149
packages = ["cffi" , "setuptools" ]
146
150
151
+ to_install = []
147
152
for pkg in packages :
148
153
sys .stdout .write (f"Checking { pkg } ..." )
149
154
sys .stdout .flush ()
@@ -152,13 +157,16 @@ def setup_tkinter():
152
157
sys .stdout .write (f"{ GREEN } Installed{ RESET } \n " )
153
158
else :
154
159
sys .stdout .write (f"{ RED } Not installed{ RESET } \n " )
155
- if prompt_user_install (pkg ):
156
- subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , pkg ])
157
- print (f"{ GREEN } { pkg } installed successfully.{ RESET } " )
160
+ to_install .append (pkg )
158
161
159
- else :
160
- print (f"Cannot continue without { pkg } . Please install using: \" pip install { pkg } \" " )
161
- sys .exit (1 )
162
+ if to_install :
163
+ if prompt_user_install (', ' .join (to_install )):
164
+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , * to_install ])
165
+ print (f"{ GREEN } { ', ' .join (to_install )} installed successfully.{ RESET } " )
166
+ else :
167
+ print (f"{ RED } Cannot continue without: { ', ' .join (to_install )} { RESET } " )
168
+ print (f"Please install manually using: pip install { ' ' .join (to_install )} " )
169
+ sys .exit (1 )
162
170
163
171
install_system_dependencies ()
164
172
run_tkinter_build_script ()
0 commit comments