Skip to content

Commit 5706b7e

Browse files
authored
Merge pull request #947 from compas-dev/fix-gh-installation
Clean up the application paths for Rhino/GH
2 parents b58de87 + de039a7 commit 5706b7e

File tree

7 files changed

+255
-158
lines changed

7 files changed

+255
-158
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
* Changed default Rhino version for installation to `7.0`.
3333
* Fixed bug in `compas_ghpython` related to importing `Grasshopper` prematurely.
3434
* Changed `compas.artists.Artist.ITAM_ARTIST` to context-based dict.
35+
* Changed `compas_rhino.__init__.py` functions.
36+
* Changed `compas_ghpython.__init__.py` functions.
3537

3638
### Removed
3739

src/compas_ghpython/__init__.py

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,64 @@
2121
if compas.is_rhino():
2222
from .utilities import * # noqa: F401 F403
2323

24+
__all__ = [
25+
'get_grasshopper_managedplugin_path',
26+
'get_grasshopper_library_path',
27+
'get_grasshopper_userobjects_path'
28+
]
29+
__all_plugins__ = [
30+
'compas_ghpython.install',
31+
'compas_ghpython.uninstall',
32+
'compas_ghpython.artists',
33+
]
34+
35+
36+
# =============================================================================
37+
# General Helpers
38+
# =============================================================================
2439

25-
def get_grasshopper_plugin_path(version):
40+
41+
def _get_grasshopper_special_folder(version, folder_name):
42+
grasshopper = compas_rhino._get_grasshopper_plugin_path(version)
43+
return os.path.join(grasshopper, folder_name)
44+
45+
46+
# =============================================================================
47+
# Managed Plugin
48+
# =============================================================================
49+
50+
51+
def get_grasshopper_managedplugin_path(version):
2652
version = compas_rhino._check_rhino_version(version)
53+
managedplugins = compas_rhino._get_managedplugins_path(version)
2754

2855
if compas.WINDOWS:
29-
version = version.split('.')[0] # take the major only
30-
grasshopper_plugin_path = os.path.join(os.getenv('ProgramFiles'), 'Rhino {}'.format(version), 'Plug-ins', 'Grasshopper')
56+
gh_managedplugin_path = os.path.join(managedplugins, 'Grasshopper')
57+
3158
elif compas.OSX:
32-
lib_paths = {
33-
'6.0': ['/', 'Applications', 'Rhinoceros.app'],
34-
'7.0': ['/', 'Applications', 'Rhino 7.app', ]
35-
}
59+
gh_managedplugin_path = os.path.join(managedplugins, 'GrasshopperPlugin.rhp')
60+
61+
if not os.path.exists(gh_managedplugin_path):
62+
raise Exception("The Grasshopper (managed) Plug-in folder does not exist in this location: {}".format(gh_managedplugin_path))
3663

37-
if version not in lib_paths:
38-
raise Exception('Unsupported Rhino version')
64+
return gh_managedplugin_path
3965

40-
grasshopper_plugin_path = os.path.join(*lib_paths.get(version) +
41-
['Contents', 'Frameworks', 'RhCore.framework', 'Versions', 'A',
42-
'Resources', 'ManagedPlugIns', 'GrasshopperPlugin.rhp'])
43-
else:
44-
raise Exception('Unsupported platform')
45-
return grasshopper_plugin_path
66+
67+
# =============================================================================
68+
# GH Plugin Libraries path
69+
# =============================================================================
4670

4771

4872
def get_grasshopper_library_path(version):
4973
"""Retrieve Grasshopper's library (components) path"""
5074
return _get_grasshopper_special_folder(version, 'Libraries')
5175

5276

77+
# =============================================================================
78+
# GH Plugin UserObjects path
79+
# =============================================================================
80+
81+
5382
def get_grasshopper_userobjects_path(version):
5483
"""Retrieve Grasshopper's user objects path"""
5584
return _get_grasshopper_special_folder(version, 'UserObjects')
56-
57-
58-
def _get_grasshopper_special_folder(version, folder_name):
59-
if compas.WINDOWS:
60-
grasshopper_library_path = os.path.join(os.getenv('APPDATA'), 'Grasshopper', folder_name)
61-
elif compas.OSX:
62-
grasshopper_library_path = os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'McNeel', 'Rhinoceros', '{}'.format(version),
63-
'Plug-ins', 'Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)', folder_name)
64-
else:
65-
raise Exception('Unsupported platform')
66-
return grasshopper_library_path
67-
68-
69-
__all_plugins__ = [
70-
'compas_ghpython.install',
71-
'compas_ghpython.uninstall',
72-
'compas_ghpython.artists',
73-
]
74-
__all__ = [name for name in dir() if not name.startswith('_')]

src/compas_ghpython/components/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from compas._os import remove_symlinks
3232
from compas_ghpython import get_grasshopper_userobjects_path
3333
from compas_rhino import _check_rhino_version
34+
import compas_rhino
3435

3536

3637
def coerce_frame(plane):
@@ -46,7 +47,7 @@ def coerce_frame(plane):
4647

4748
def get_version_from_args():
4849
parser = argparse.ArgumentParser()
49-
parser.add_argument('-v', '--version', choices=['5.0', '6.0', '7.0'], default='6.0')
50+
parser.add_argument('-v', '--version', choices=compas_rhino.SUPPORTED_VERSIONS, default=compas_rhino.DEFAULT_VERSION)
5051
args = parser.parse_args()
5152
return _check_rhino_version(args.version)
5253

@@ -66,6 +67,7 @@ def install_userobjects(source):
6667
"""
6768
version = get_version_from_args()
6869

70+
# this dstdir potentially doesn't exist
6971
dstdir = get_grasshopper_userobjects_path(version)
7072
userobjects = glob.glob(os.path.join(source, '*.ghuser'))
7173

0 commit comments

Comments
 (0)