Skip to content

Commit

Permalink
Merge pull request #947 from compas-dev/fix-gh-installation
Browse files Browse the repository at this point in the history
Clean up the application paths for Rhino/GH
  • Loading branch information
tomvanmele authored Dec 10, 2021
2 parents b58de87 + de039a7 commit 5706b7e
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 158 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed default Rhino version for installation to `7.0`.
* Fixed bug in `compas_ghpython` related to importing `Grasshopper` prematurely.
* Changed `compas.artists.Artist.ITAM_ARTIST` to context-based dict.
* Changed `compas_rhino.__init__.py` functions.
* Changed `compas_ghpython.__init__.py` functions.

### Removed

Expand Down
78 changes: 44 additions & 34 deletions src/compas_ghpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,64 @@
if compas.is_rhino():
from .utilities import * # noqa: F401 F403

__all__ = [
'get_grasshopper_managedplugin_path',
'get_grasshopper_library_path',
'get_grasshopper_userobjects_path'
]
__all_plugins__ = [
'compas_ghpython.install',
'compas_ghpython.uninstall',
'compas_ghpython.artists',
]


# =============================================================================
# General Helpers
# =============================================================================

def get_grasshopper_plugin_path(version):

def _get_grasshopper_special_folder(version, folder_name):
grasshopper = compas_rhino._get_grasshopper_plugin_path(version)
return os.path.join(grasshopper, folder_name)


# =============================================================================
# Managed Plugin
# =============================================================================


def get_grasshopper_managedplugin_path(version):
version = compas_rhino._check_rhino_version(version)
managedplugins = compas_rhino._get_managedplugins_path(version)

if compas.WINDOWS:
version = version.split('.')[0] # take the major only
grasshopper_plugin_path = os.path.join(os.getenv('ProgramFiles'), 'Rhino {}'.format(version), 'Plug-ins', 'Grasshopper')
gh_managedplugin_path = os.path.join(managedplugins, 'Grasshopper')

elif compas.OSX:
lib_paths = {
'6.0': ['/', 'Applications', 'Rhinoceros.app'],
'7.0': ['/', 'Applications', 'Rhino 7.app', ]
}
gh_managedplugin_path = os.path.join(managedplugins, 'GrasshopperPlugin.rhp')

if not os.path.exists(gh_managedplugin_path):
raise Exception("The Grasshopper (managed) Plug-in folder does not exist in this location: {}".format(gh_managedplugin_path))

if version not in lib_paths:
raise Exception('Unsupported Rhino version')
return gh_managedplugin_path

grasshopper_plugin_path = os.path.join(*lib_paths.get(version) +
['Contents', 'Frameworks', 'RhCore.framework', 'Versions', 'A',
'Resources', 'ManagedPlugIns', 'GrasshopperPlugin.rhp'])
else:
raise Exception('Unsupported platform')
return grasshopper_plugin_path

# =============================================================================
# GH Plugin Libraries path
# =============================================================================


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


# =============================================================================
# GH Plugin UserObjects path
# =============================================================================


def get_grasshopper_userobjects_path(version):
"""Retrieve Grasshopper's user objects path"""
return _get_grasshopper_special_folder(version, 'UserObjects')


def _get_grasshopper_special_folder(version, folder_name):
if compas.WINDOWS:
grasshopper_library_path = os.path.join(os.getenv('APPDATA'), 'Grasshopper', folder_name)
elif compas.OSX:
grasshopper_library_path = os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'McNeel', 'Rhinoceros', '{}'.format(version),
'Plug-ins', 'Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)', folder_name)
else:
raise Exception('Unsupported platform')
return grasshopper_library_path


__all_plugins__ = [
'compas_ghpython.install',
'compas_ghpython.uninstall',
'compas_ghpython.artists',
]
__all__ = [name for name in dir() if not name.startswith('_')]
4 changes: 3 additions & 1 deletion src/compas_ghpython/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from compas._os import remove_symlinks
from compas_ghpython import get_grasshopper_userobjects_path
from compas_rhino import _check_rhino_version
import compas_rhino


def coerce_frame(plane):
Expand All @@ -46,7 +47,7 @@ def coerce_frame(plane):

def get_version_from_args():
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', choices=['5.0', '6.0', '7.0'], default='6.0')
parser.add_argument('-v', '--version', choices=compas_rhino.SUPPORTED_VERSIONS, default=compas_rhino.DEFAULT_VERSION)
args = parser.parse_args()
return _check_rhino_version(args.version)

Expand All @@ -66,6 +67,7 @@ def install_userobjects(source):
"""
version = get_version_from_args()

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

Expand Down
Loading

0 comments on commit 5706b7e

Please sign in to comment.