@@ -42,8 +42,7 @@ def uninstall(version=None, packages=None):
4242 python -m compas_rhino.uninstall -v 6.0
4343
4444 """
45- if version not in ('5.0' , '6.0' , '7.0' , '8.0' ):
46- version = '6.0'
45+ version = compas_rhino ._check_rhino_version (version )
4746
4847 # We install COMPAS packages in the scripts folder
4948 # instead of directly as IPy module.
@@ -52,6 +51,9 @@ def uninstall(version=None, packages=None):
5251 # This is for old installs
5352 ipylib_path = compas_rhino ._get_ironpython_lib_path (version )
5453
54+ # Filter the provided list of packages
55+ # If no packages are provided
56+ # this first collects all installable packages from the environment.
5557 packages = _filter_installed_packages (version , packages )
5658
5759 # Also remove all broken symlinks
@@ -63,11 +65,8 @@ def uninstall(version=None, packages=None):
6365 if name not in packages :
6466 packages .append (name )
6567
66- print ('Uninstalling COMPAS packages from Rhino {0} scripts folder: \n {1}' .format (version , scripts_path ))
67-
68- results = []
68+ # Collect paths for removal based on package names
6969 symlinks_to_uninstall = []
70- exit_code = 0
7170
7271 for package in packages :
7372 symlink_path = os .path .join (scripts_path , package )
@@ -81,55 +80,67 @@ def uninstall(version=None, packages=None):
8180 if os .path .exists (legacy_path ):
8281 symlinks_to_uninstall .append (dict (name = package , link = legacy_path ))
8382
83+ # There is nothing to uninstall
8484 if not symlinks_to_uninstall :
85- print ('\n No packages to uninstall.' )
85+ print ('\n No packages to uninstall from Rhino {0} scripts folder: \n {1}.' .format (version , scripts_path ))
86+ return
8687
87- else :
88- uninstalled_packages = []
88+ # -------------------------
89+ # Start uninstalling
90+ # -------------------------
91+
92+ uninstalled_packages = []
93+ results = []
94+ exit_code = 0
8995
90- symlinks = [link ['link' ] for link in symlinks_to_uninstall ]
91- uninstall_results = compas ._os .remove_symlinks (symlinks )
96+ symlinks = [link ['link' ] for link in symlinks_to_uninstall ]
97+ uninstall_results = compas ._os .remove_symlinks (symlinks )
9298
93- for uninstall_data , success in zip (symlinks_to_uninstall , uninstall_results ):
94- if success :
95- uninstalled_packages .append (uninstall_data ['name' ])
96- result = 'OK'
97- else :
98- result = 'ERROR: Cannot remove symlink, try to run as administrator.'
99+ for uninstall_data , success in zip (symlinks_to_uninstall , uninstall_results ):
100+ if success :
101+ uninstalled_packages .append (uninstall_data ['name' ])
102+ result = 'OK'
103+ else :
104+ result = 'ERROR: Cannot remove symlink, try to run as administrator.'
99105
100- results .append ((uninstall_data ['name' ], result ))
106+ results .append ((uninstall_data ['name' ], result ))
101107
102- if not all (uninstall_results ):
103- exit_code = - 1
108+ if not all (uninstall_results ):
109+ exit_code = - 1
104110
105- if exit_code == - 1 :
106- results .append (('compas_bootstrapper' , 'WARNING: One or more packages failed, will not uninstall bootstrapper.' ))
111+ if exit_code == - 1 :
112+ results .append (('compas_bootstrapper' , 'WARNING: One or more packages failed, will not uninstall bootstrapper.' ))
107113
114+ else :
115+ if compas_rhino ._try_remove_bootstrapper (scripts_path ):
116+ results .append (('compas_bootstrapper' , 'OK' ))
108117 else :
109- if compas_rhino ._try_remove_bootstrapper (scripts_path ):
110- results .append (('compas_bootstrapper' , 'OK' ))
111- else :
112- results .append (('compas_bootstrapper' , 'ERROR: Cannot remove compas_bootstrapper, try to run as administrator.' ))
118+ results .append (('compas_bootstrapper' , 'ERROR: Cannot remove compas_bootstrapper, try to run as administrator.' ))
119+
120+ # Handle legacy bootstrapper
121+ # Again, only if possible...
122+ if ipylib_path :
123+ if not compas_rhino ._try_remove_bootstrapper (ipylib_path ):
124+ results .append (('compas_bootstrapper' , 'ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.' ))
113125
114- # Handle legacy bootstrapper
115- # Again, only if possible...
116- if ipylib_path :
117- if not compas_rhino ._try_remove_bootstrapper (ipylib_path ):
118- results .append (('compas_bootstrapper' , 'ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.' ))
126+ # -------------------------
127+ # Output results
128+ # -------------------------
119129
120- print ('\n The following packages have been detected and will be uninstalled:\n ' )
130+ print ('Uninstalling COMPAS packages from Rhino {0} scripts folder: \n {1}' .format (version , scripts_path ))
131+ print ('\n The following packages have been detected and will be uninstalled:\n ' )
121132
122- for package , status in results :
123- print (' {} {}' .format (package .ljust (20 ), status ))
133+ for package , status in results :
134+ print (' {} {}' .format (package .ljust (20 ), status ))
124135
125- if status != 'OK' :
126- exit_code = - 1
136+ if status != 'OK' :
137+ exit_code = - 1
127138
128- if exit_code == 0 and uninstalled_packages :
129- print ('\n Running post-uninstallation steps...\n ' )
139+ if exit_code == 0 and uninstalled_packages :
140+ print ('\n Running post-uninstallation steps...\n ' )
130141
131- if not _run_post_execution_steps (after_rhino_uninstall (uninstalled_packages )):
132- exit_code = - 1
142+ if not _run_post_execution_steps (after_rhino_uninstall (uninstalled_packages )):
143+ exit_code = - 1
133144
134145 print ('\n Uninstall completed.' )
135146
@@ -207,7 +218,13 @@ def after_rhino_uninstall(uninstalled_packages):
207218
208219 parser = argparse .ArgumentParser ()
209220
210- parser .add_argument ('-v' , '--version' , choices = ['5.0' , '6.0' , '7.0' , '8.0' ], default = '6.0' , help = "The version of Rhino to install the packages in." )
221+ parser .add_argument (
222+ '-v' ,
223+ '--version' ,
224+ choices = compas_rhino .SUPPORTED_VERSIONS ,
225+ default = compas_rhino .DEFAULT_VERSION ,
226+ help = "The version of Rhino to install the packages in."
227+ )
211228 parser .add_argument ('-p' , '--packages' , nargs = '+' , help = "The packages to uninstall." )
212229
213230 args = parser .parse_args ()
0 commit comments