4242
4343GREEN = "\033 [92m"
4444RED = "\033 [91m"
45+ YELLOW = "\033 [93m"
4546RESET = "\033 [0m"
4647
48+
4749def check_package (name : str ) -> bool :
4850 try :
4951 importlib .import_module (name )
@@ -69,9 +71,10 @@ def is_tcl_tk_installed( name: str ) -> bool:
6971 except subprocess .CalledProcessError :
7072 return False
7173
72- def prompt_user_install (package_name : str ) -> bool :
74+ def prompt_user_install (package_name : str , is_system_package : bool = False ) -> bool :
7375
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 ()
7578 return response in ("" , "y" , "yes" )
7679
7780def install_tcl_tk (name :str ) -> bool :
@@ -90,13 +93,14 @@ def install_system_dependencies():
9093
9194 if sys .platform == "darwin" :
9295 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 ):
9498 subprocess .check_call ([
9599 "/bin/bash" , "-c" ,
96100 "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
97101 ])
98102 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 } " )
100104 sys .exit (1 )
101105
102106 tcl_tk = "tcl-tk@8"
@@ -106,7 +110,7 @@ def install_system_dependencies():
106110 sys .stdout .write (f"{ GREEN } Installed{ RESET } \n " )
107111 else :
108112 sys .stdout .write (f"{ RED } Not installed{ RESET } \n " )
109- if prompt_user_install (tcl_tk ):
113+ if prompt_user_install (tcl_tk , True ):
110114 install_tcl_tk (tcl_tk )
111115 else :
112116 print (f"{ RED } Cannot continue without { tcl_tk } . Please install it and try again.{ RESET } " )
@@ -144,6 +148,7 @@ def setup_tkinter():
144148
145149 packages = ["cffi" , "setuptools" ]
146150
151+ to_install = []
147152 for pkg in packages :
148153 sys .stdout .write (f"Checking { pkg } ..." )
149154 sys .stdout .flush ()
@@ -152,13 +157,16 @@ def setup_tkinter():
152157 sys .stdout .write (f"{ GREEN } Installed{ RESET } \n " )
153158 else :
154159 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 )
158161
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 )
162170
163171 install_system_dependencies ()
164172 run_tkinter_build_script ()
0 commit comments