Skip to content

Commit f2ff76c

Browse files
committed
Fix task to build GH user components
1 parent 70dd689 commit f2ff76c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `compas_ghpython.fetch_ghio_lib` to simplify the loading of Grasshopper's IO library for extension developers.
13+
1214
### Changed
1315

1416
### Removed
@@ -52,9 +54,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5254
* Changed `compas_rhino.install_plugin` to remove broken symlinks.
5355
* Changed default Rhino version for installation to `7.0`.
5456
* Fixed bug in `compas_ghpython` related to importing `Grasshopper` prematurely.
55-
* Changed `compas.artists.Artist.ITAM_ARTIST` to context-based dict.
57+
* Changed `compas.artists.Artist.ITEM_ARTIST` to context-based dict.
5658
* Changed `compas_rhino.__init__.py` functions.
5759
* Changed `compas_ghpython.__init__.py` functions.
60+
* Renamed `compas_ghpython.get_grasshopper_plugin_path` to `compas_ghpython.get_grasshopper_managedplugin_path`.
5861

5962
### Removed
6063

src/compas_ghpython/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
compas_ghpython.utilities
1313
1414
"""
15+
import io
1516
import os
17+
import urllib
18+
import zipfile
19+
1620
import compas
1721
import compas_rhino
1822

@@ -24,7 +28,8 @@
2428
__all__ = [
2529
'get_grasshopper_managedplugin_path',
2630
'get_grasshopper_library_path',
27-
'get_grasshopper_userobjects_path'
31+
'get_grasshopper_userobjects_path',
32+
'fetch_ghio_lib'
2833
]
2934
__all_plugins__ = [
3035
'compas_ghpython.install',
@@ -82,3 +87,22 @@ def get_grasshopper_library_path(version):
8287
def get_grasshopper_userobjects_path(version):
8388
"""Retrieve Grasshopper's user objects path"""
8489
return _get_grasshopper_special_folder(version, 'UserObjects')
90+
91+
# =============================================================================
92+
# GH_IO Dll
93+
# =============================================================================
94+
95+
def fetch_ghio_lib(target_folder='temp'):
96+
"""Fetch the GH_IO.dll library from the NuGet packaging system."""
97+
ghio_dll = 'GH_IO.dll'
98+
filename = 'lib/net48/' + ghio_dll
99+
100+
response = urllib.request.urlopen('https://www.nuget.org/api/v2/package/Grasshopper/')
101+
dst_file = os.path.join(target_folder, ghio_dll)
102+
zip_file = zipfile.ZipFile(io.BytesIO(response.read()))
103+
104+
with zip_file.open(filename, 'r') as zipped_dll:
105+
with open(dst_file, 'wb') as fp:
106+
fp.write(zipped_dll.read())
107+
108+
return dst_file

tasks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def prepare_changelog(ctx):
189189

190190

191191
@task(help={
192-
'gh_io_folder': 'Folder where GH_IO.dll is located. Defaults to the Rhino 6.0 installation folder (platform-specific).',
192+
'gh_io_folder': 'Folder where GH_IO.dll is located. If not specified, it will try to download from NuGet.',
193193
'ironpython': 'Command for running the IronPython executable. Defaults to `ipy`.'})
194194
def build_ghuser_components(ctx, gh_io_folder=None, ironpython=None):
195195
"""Build Grasshopper user objects from source"""
@@ -199,9 +199,11 @@ def build_ghuser_components(ctx, gh_io_folder=None, ironpython=None):
199199
source_dir = os.path.abspath('src/compas_ghpython/components')
200200
target_dir = os.path.join(source_dir, 'ghuser')
201201
ctx.run('git clone https://github.com/compas-dev/compas-actions.ghpython_components.git {}'.format(action_dir))
202+
202203
if not gh_io_folder:
204+
gh_io_folder = 'temp'
203205
import compas_ghpython
204-
gh_io_folder = compas_ghpython.get_grasshopper_plugin_path('6.0')
206+
compas_ghpython.fetch_ghio_lib(gh_io_folder)
205207

206208
if not ironpython:
207209
ironpython = 'ipy'

0 commit comments

Comments
 (0)