1919]
2020
2121
22- def install (version = None , packages = None ):
22+ def install (version = None , packages = None , clean = False ):
2323 """Install COMPAS for Rhino.
2424
2525 Parameters
2626 ----------
27- version : {'5.0', '6.0', '7.0'}, optional
27+ version : {'5.0', '6.0', '7.0', '8.0' }, optional
2828 The version number of Rhino.
2929 Default is ``'6.0'``.
3030 packages : list of str, optional
3131 List of packages to install or None to use default package list.
32- Default is ``['compas', 'compas_rhino', 'compas_ghpython']``.
32+ Default is the result of ``installable_rhino_packages``,
33+ which collects all installable packages in the current environment.
34+ clean : bool, optional
35+ If ``True``, this will clean up the entire scripts folder and remove
36+ also existing symlinks that are not importable in the current environment.
3337
3438 Examples
3539 --------
@@ -44,7 +48,7 @@ def install(version=None, packages=None):
4448
4549 """
4650
47- if version not in ('5.0' , '6.0' , '7.0' ):
51+ if version not in ('5.0' , '6.0' , '7.0' , '8.0' ):
4852 version = '6.0'
4953
5054 # We install COMPAS packages in the scripts folder
@@ -70,25 +74,29 @@ def install(version=None, packages=None):
7074 try :
7175 importlib .import_module (name )
7276 except ImportError :
73- symlink_path = os .path .join (scripts_path , name )
74- symlinks_to_uninstall .append (dict (name = name , link = symlink_path ))
77+ path = os .path .join (scripts_path , name )
78+ symlinks_to_uninstall .append (dict (name = name , link = path ))
7579 packages .remove (name )
7680
77- # check all the compas packages/folders in the scripts directory
78- # if one of them is not importable from the current env
79- # it should be listed for un-installation
80- # otherwise it should be added to the list of packages to install
81- # if it wasn't already in there
81+ # Also remove all broken symlinks from the scripts folder
82+ # because ... they're broken!
83+ # If it is an actual folder or a file, leave it alone
84+ # because probably someone put it there on purpose.
8285 for name in os .listdir (scripts_path ):
83- if name .startswith ('compas' ) and not name .endswith ('.py' ):
84- try :
85- importlib .import_module (name )
86- except ImportError :
87- symlink_path = os .path .join (scripts_path , name )
88- symlinks_to_uninstall .append (dict (name = name , link = symlink_path ))
86+ path = os .path .join (scripts_path , name )
87+ if os .path .islink (path ):
88+ if not os .path .exists (path ):
89+ symlinks_to_uninstall .append (dict (name = name , link = path ))
8990 else :
90- if name not in packages :
91- packages .append (name )
91+ if clean :
92+ try :
93+ importlib .import_module (name )
94+ except ImportError :
95+ path = os .path .join (scripts_path , name )
96+ symlinks_to_uninstall .append (dict (name = name , link = path ))
97+ else :
98+ if name not in packages :
99+ packages .append (name )
92100
93101 # add all of the packages in the list of installable packages
94102 # to the list of symlinks to uninstall
@@ -314,9 +322,10 @@ def _filter_installable_packages(version, packages):
314322
315323 parser = argparse .ArgumentParser ()
316324
317- parser .add_argument ('-v' , '--version' , choices = ['5.0' , '6.0' , '7.0' ], default = '6.0' , help = "The version of Rhino to install the packages in." )
325+ 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." )
318326 parser .add_argument ('-p' , '--packages' , nargs = '+' , help = "The packages to install." )
327+ parser .add_argument ('--clean' , dest = 'clean' , default = False , action = 'store_true' )
319328
320329 args = parser .parse_args ()
321330
322- install (version = args .version , packages = args .packages )
331+ install (version = args .version , packages = args .packages , clean = args . clean )
0 commit comments