1- import os
21import importlib .util
3- from rich . console import Console
2+ import os
43import sys
54
6- from status import status
7- import mirrors
8- import hooks
5+ from rich .console import Console
6+
97import get_package_list
10- import umbrella . autocorrect_package as Autocorrect
8+ import hooks
119import install
10+ import mirrors
11+ import umbrella .autocorrect_package as Autocorrect
12+ from status import status
1213
1314# init rich console
1415console = Console ()
1516
1617# Track packages currently being installed to prevent circular dependencies
1718_installing = set ()
1819
20+
1921def main (package , noconfirm = False ):
2022 local = False
2123 # check if package is local
@@ -31,7 +33,7 @@ def main(package, noconfirm=False):
3133 autocorrected = Autocorrect .main (package )
3234 if autocorrected != package :
3335 package = autocorrected
34-
36+
3537 # Prevent circular dependencies and infinite loops
3638 if package in _installing :
3739 return
@@ -41,7 +43,7 @@ def main(package, noconfirm=False):
4143 if not local :
4244 if get_package_list .main (package ) != True :
4345 return False
44-
46+
4547 # main
4648 try :
4749 # save installed package
@@ -75,7 +77,7 @@ def write_installed_versions(path, versions):
7577 # go to /tmp
7678 if not local :
7779 os .chdir ("/tmp/" )
78-
80+
7981 status ("Fetching package" )
8082
8183 # fetch all repos for the install script
@@ -84,7 +86,7 @@ def write_installed_versions(path, versions):
8486 for mirror in mirrors .install_script_places :
8587 url = f"{ mirror .rstrip ('/' )} /{ package } /install_script"
8688
87- result = os .system (f"curl -s -L -o install_script.py { url } " )
89+ os .system (f"curl -s -L -o install_script.py { url } " )
8890
8991 with open ("install_script.py" , "r" ) as f :
9092 script = f .read ()
@@ -102,7 +104,9 @@ def write_installed_versions(path, versions):
102104 exit (1 )
103105
104106 # import the script as a python library
105- spec = importlib .util .spec_from_file_location ("install_script" , "install_script.py" )
107+ spec = importlib .util .spec_from_file_location (
108+ "install_script" , "install_script.py"
109+ )
106110 install_script = importlib .util .module_from_spec (spec )
107111 spec .loader .exec_module (install_script )
108112
@@ -122,9 +126,16 @@ def write_installed_versions(path, versions):
122126 installed_version = installed_versions .get (package )
123127 if installed_version is not None and installed_version == script_version :
124128 status (f"{ package } is up to date ({ script_version } ). Exiting." , "ok" )
129+ status (
130+ f"You can use\n sudo car delete { package } && sudo car get { package } "
131+ )
132+ status ("to reinstall it" )
125133 return
126134 elif installed_version is not None and installed_version != script_version :
127- status (f"New version available for { package } : { installed_version } -> { script_version } . Reinstalling." , "warn" )
135+ status (
136+ f"New version available for { package } : { installed_version } -> { script_version } . Reinstalling." ,
137+ "warn" ,
138+ )
128139 elif installed_version is None :
129140 if not os .path .isfile (repro_path ):
130141 status ("No repro.car file. Creating" , "warn" )
@@ -138,11 +149,28 @@ def write_installed_versions(path, versions):
138149 # ask for confirmation
139150 if not noconfirm :
140151 status ("The following packages are going to be installed:" )
141- print (" " , end = "" )
152+ if "description" not in script :
153+ description = "No description defined."
154+ else :
155+ description = install_script .description
156+ print (
157+ f" { package } ={ install_script .version } - { description } "
158+ ) # appending to the list did not work for some reason
142159 if "car_deps" in script :
143- for i in install_script .car_deps :
144- print (i , end = ", " )
145- print (package ) # appending to the list did not work for some reason
160+ counter = 1
161+ if len (install_script .car_deps ) != 0 :
162+ print (" dependencies: " , end = "" )
163+ for i in install_script .car_deps :
164+ if counter != len (install_script .car_deps ):
165+ print (f"{ i } , " , end = "" )
166+ else :
167+ print (f"{ i } " , end = "" )
168+ print ()
169+ if "outdated = True" in script :
170+ if (
171+ package != "example"
172+ ): # example is set to be outdated for demonstration
173+ status (f'The package "{ package } " is outdated! ' , "error" )
146174 console .print ("::" , style = "blue bold" , end = " " )
147175 sure = input ("Install dependencies and build? (Y/n) " )
148176 if sure not in ("" , "y" , "Y" ):
@@ -152,7 +180,8 @@ def write_installed_versions(path, versions):
152180 if "deps" in script :
153181 try :
154182 install_script .deps ()
155- except Exception :pass
183+ except Exception :
184+ pass
156185 if "car_deps" in script :
157186 for i in install_script .car_deps :
158187 install .main (i , noconfirm = True )
@@ -161,7 +190,8 @@ def write_installed_versions(path, versions):
161190 if "build" in script :
162191 try :
163192 install_script .build ()
164- except Exception :pass
193+ except Exception :
194+ pass
165195
166196 # ask for confirmation
167197 # todo: make confirmation prompts better by mixing into one
@@ -175,7 +205,6 @@ def write_installed_versions(path, versions):
175205 status ("Installing" , "ok" )
176206 install_script .install ()
177207
178-
179208 if not "DoNotWriteVersion = True" in script :
180209 installed_versions [package ] = script_version
181210 write_installed_versions (repro_path , installed_versions )
@@ -197,7 +226,10 @@ def write_installed_versions(path, versions):
197226 except KeyboardInterrupt :
198227 # keyboard interrupt, suggest cleaning up
199228 status ("Installation interrupted" , "error" )
200- status ("There might be some files that were installed, but not removed. You can remove them manually." , "warn" )
229+ status (
230+ "There might be some files that were installed, but not removed. You can remove them manually." ,
231+ "warn" ,
232+ )
201233 status ("If you want to remove them, run the following command:" , "warn" )
202234 status ("sudo car delete " + package , "warn" )
203235 sys .exit (1 )
0 commit comments