| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Build Grasshopper .ghuser components out of plain Python source bundles. 🐵
Write your Grasshopper components as real Python files, in a real editor, under version control, and compile them into .ghuser components for the CPython (Python 3) interpreter of Rhino 8.
This package is the standalone version of the componentizer behind the compas-actions.ghpython_components GitHub action: same tool, usable from your own scripts, build systems or CI, without going through the action.
pip install ghpython_componentizerghpython-componentizer <source> <target>For example, to build all component bundles under components into a build folder:
ghpython-componentizer components buildOptionally, tag the components with a version, which replaces the {{version}} template variable in the code:
ghpython-componentizer components build --version 0.1.2An optional name prefix can help tell components apart from other similarly named ones:
ghpython-componentizer components build --prefix "(PACKAGE-NAME)"If you already have a copy of GH_IO.dll (e.g. from a NuGet restore), point the tool at the folder containing it to skip the download:
ghpython-componentizer components build --ghio ./libThe tool is also runnable as a module, which is handy when the scripts folder is not on PATH:
python -m ghpython_componentizer components buildfrom ghpython_componentizer import build_components
build_components("components", "build", version="0.1.2", prefix="(COMPAS)")Or one component at a time:
from ghpython_componentizer import create_ghuser_component
create_ghuser_component("components/MyComponent", "build/MyComponent.ghuser")Both functions download GH_IO.dll from NuGet on first use, unless the ghio_dir argument points at a folder that contains it.
from ghpython_componentizer import run_componentizer
run_componentizer("components", "build", version="0.1.2", prefix="(COMPAS)")This does the same as build_components, but in a subprocess started with the environment the platform needs. On macOS that is the only thing that works from a process that is already running, see below. Everywhere else the two are interchangeable.
Only Mono can load the net48 assemblies this tool needs, and Mono draws the component icons through the native libgdiplus library. Homebrew installs libgdiplus in a prefix the dynamic loader does not search by default, so without help the build fails with a System.TypeInitializationException while embedding the icon.
DYLD_LIBRARY_PATH is only read when a process starts, so it cannot be fixed from inside a running process. The command line therefore relaunches itself once, with the right environment, and everything works out of the box:
brew install mono mono-libgdiplus
ghpython-componentizer components buildFrom Python, build_components and create_ghuser_component cannot fix the environment of the process calling them: they raise a RuntimeError explaining what to do. Use run_componentizer instead, or start your own subprocess with the environment returned by componentizer_env:
import subprocess
import sys
from ghpython_componentizer import componentizer_env
# Note: no shell in between, macOS strips DYLD_* variables when it starts one.
subprocess.run(
[sys.executable, "-m", "ghpython_componentizer", "components", "build"],
env=componentizer_env(),
check=True,
)The same caveat applies to the interpreter itself: macOS strips DYLD_* variables when starting a protected binary, so build with a Python from python.org, Homebrew or uv rather than /usr/bin/python3.
components/
└── My_Component/
├── code.py
├── icon.png
└── metadata.json
Supports a small set of templated variables that can be used in code:
GHUser components have one important limitation: once used in a document, they forget who they are. They don't know they were created out of a ghuser component, they will be simple script components. This has an important consequence: if you update the ghuser components, those already in use will NOT be automatically updated.
This package builds components for the CPython (Python 3) interpreter of Rhino 8 only. Components for the IronPython interpreters of Rhino 7 and Rhino 8 are still built with the scripts of the GitHub action.
pip install -e ".[dev]"
pytest
ruff check .
ruff format .Most of the test suite covers the parts that do not require a .NET runtime, so it runs on any platform. The tests marked dotnet build the examples into actual components and read them back, and skip themselves when there is no runtime to do it with:
pytest -m "not dotnet" # unit tests only
pytest -m dotnet # build the example componentsLinting and formatting follow the same ruff rules as the other COMPAS packages, configured in pyproject.toml.
Releases are prepared and published by pull request, with the shared compas-actions.
Merging it runs the release workflow: it builds the distributions, publishes them to PyPI through trusted publishing and creates the tagged GitHub release, with the changelog section as release notes. No API token is involved: PyPI needs a publisher configured for this repository, the release.yml workflow and the pypi environment.
This package is maintained by Gramazio Kohler Research @gramaziokohler and it is published under an MIT License.
| Back | FazBrowse Home | New Git URL |