Skip to content

Commit 4edd43d

Browse files
committed
this should work now
1 parent 9f4f7d5 commit 4edd43d

File tree

3 files changed

+64
-43
lines changed

3 files changed

+64
-43
lines changed

src/compas_rhino/install.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
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)

src/compas_rhino/install_plugin.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def install_plugin(plugin, version=None):
1717
----------
1818
plugin : str
1919
The path to the plugin folder.
20-
version : {'5.0', '6.0', '7.0'}, optional
20+
version : {'5.0', '6.0', '7.0', '8.0'}, optional
2121
The version of Rhino for which the plugin should be installed.
2222
Default is ``'6.0'``.
2323
@@ -58,14 +58,29 @@ def install_plugin(plugin, version=None):
5858
python -m compas_rhino.install_plugin -v 7.0 ui/Rhino/XXX
5959
6060
"""
61-
if version not in ('5.0', '6.0', '7.0'):
61+
if version not in ('5.0', '6.0', '7.0', '8.0'):
6262
version = '6.0'
6363

6464
if not os.path.isdir(plugin):
6565
raise Exception('Cannot find the plugin: {}'.format(plugin))
6666

6767
plugin_dir = os.path.abspath(plugin)
6868

69+
# clean up the plugin directory
70+
71+
# # Also remove all broken symlinks
72+
# # because ... they're broken!
73+
# broken = []
74+
# for name in os.listdir(plugin_dir):
75+
# path = os.path.join(plugin_dir, name)
76+
# if os.path.islink(path):
77+
# if not os.path.exists(path):
78+
# broken.append(path)
79+
# if broken:
80+
# pass
81+
82+
# proceed with the installation
83+
6984
plugin_path, plugin_name = os.path.split(plugin_dir)
7085
if not plugin_path:
7186
plugin_path = os.getcwd()
@@ -98,15 +113,13 @@ def install_plugin(plugin, version=None):
98113
source = plugin_dir
99114
destination = os.path.join(python_plugins_path, plugin_fullname)
100115

101-
print('Installing PlugIn {} to Rhino PythonPlugIns.'.format(plugin_name))
116+
print('\nInstalling PlugIn {} to Rhino PythonPlugIns.'.format(plugin_name))
102117

103118
remove_symlinks([destination])
104119
create_symlinks([(source, destination)])
105120

106-
print()
107-
print('PlugIn {} Installed.'.format(plugin_name))
108-
print()
109-
print('Restart Rhino and open the Python editor at least once to make it available.')
121+
print('\nPlugIn {} Installed.'.format(plugin_name))
122+
print('\nRestart Rhino and open the Python editor at least once to make it available.')
110123

111124

112125
# ==============================================================================
@@ -118,10 +131,10 @@ def install_plugin(plugin, version=None):
118131
import argparse
119132

120133
parser = argparse.ArgumentParser(
121-
description='COMPAS Rhino PLugin Installation command-line utility.')
134+
description='COMPAS Rhino Plugin Installation command-line utility.')
122135

123136
parser.add_argument('plugin', help="The path to the plugin directory.")
124-
parser.add_argument('-v', '--version', choices=['5.0', '6.0', '7.0'], default='6.0', help="The version of Rhino.")
137+
parser.add_argument('-v', '--version', choices=['5.0', '6.0', '7.0', '8.0'], default='6.0', help="The version of Rhino.")
125138

126139
args = parser.parse_args()
127140

src/compas_rhino/uninstall.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def uninstall(version=None, packages=None):
2323
2424
Parameters
2525
----------
26-
version : {'5.0', '6.0', '7.0'}, optional
26+
version : {'5.0', '6.0', '7.0', '8.0'}, optional
2727
The version number of Rhino.
2828
Default is ``'6.0'``.
2929
packages : list of str, optional
@@ -42,7 +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'):
45+
if version not in ('5.0', '6.0', '7.0', '8.0'):
4646
version = '6.0'
4747

4848
# We install COMPAS packages in the scripts folder
@@ -52,18 +52,17 @@ def uninstall(version=None, packages=None):
5252
# This is for old installs
5353
ipylib_path = compas_rhino._get_ironpython_lib_path(version)
5454

55-
# If no specific packages are provided for uninstall
56-
# everything should be removed,
57-
# and not just the default packages
58-
# or the packages that the bootstrapper is aware of.
59-
if not packages:
60-
packages = []
61-
for name in os.listdir(scripts_path):
62-
if name.startswith('compas') and not name.endswith('.py'):
63-
packages.append(name)
64-
6555
packages = _filter_installed_packages(version, packages)
6656

57+
# Also remove all broken symlinks
58+
# because ... they're broken!
59+
for name in os.listdir(scripts_path):
60+
path = os.path.join(scripts_path, name)
61+
if os.path.islink(path):
62+
if not os.path.exists(path):
63+
if name not in packages:
64+
packages.append(name)
65+
6766
print('Uninstalling COMPAS packages from Rhino {0} scripts folder: \n{1}'.format(version, scripts_path))
6867

6968
results = []
@@ -208,7 +207,7 @@ def after_rhino_uninstall(uninstalled_packages):
208207

209208
parser = argparse.ArgumentParser()
210209

211-
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.")
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.")
212211
parser.add_argument('-p', '--packages', nargs='+', help="The packages to uninstall.")
213212

214213
args = parser.parse_args()

0 commit comments

Comments
 (0)