Skip to content

Commit 5a75fba

Browse files
authored
Merge pull request #13 from ibois-epfl/main
Porting action workflow to Python 3.9.10 (ScriptComponent in V8)
2 parents 594edab + fc88595 commit 5a75fba

File tree

21 files changed

+650
-31
lines changed

21 files changed

+650
-31
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,46 @@ name: build
33
on: [push]
44

55
jobs:
6-
build:
7-
name: windows-ironpython
6+
build_cpy_ghuser_components:
87
runs-on: windows-latest
98
steps:
109
- uses: actions/checkout@v2
1110
- uses: NuGet/setup-nuget@v1.0.5
11+
12+
- name: Install CPython and pythonnet package
13+
run: |
14+
choco install python --version=3.9.10
15+
python -m pip install pythonnet==3.0.3
16+
17+
- name: Run
18+
uses: ./
19+
with:
20+
source: examples/cpy
21+
target: build
22+
interpreter: cpython
23+
24+
- uses: actions/upload-artifact@v2
25+
with:
26+
name: cpy_ghuser-components
27+
path: build
28+
29+
build_ipy_ghuser_components:
30+
runs-on: windows-latest
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: NuGet/setup-nuget@v1.0.5
34+
1235
- name: Install IronPython
1336
run: |
1437
choco install ironpython --version=2.7.8.1
15-
- name: Install dependencies
16-
run: |
17-
nuget install Grasshopper -OutputDirectory ./lib -source https://api.nuget.org/v3/index.json
38+
1839
- name: Run
19-
run: |
20-
ipy componentize.py examples build
40+
uses: ./
41+
with:
42+
source: examples/ipy
43+
target: build
44+
2145
- uses: actions/upload-artifact@v2
2246
with:
23-
name: ghuser-components
24-
path: build
47+
name: ipy_ghuser-components
48+
path: build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# avoid temp folder
132+
temp/

README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# GHPython Componentizer
22

3-
> A github action to make Grasshopper development 164% <sup><small>[1]</small></sup> version-control friendlier and 82% more pleasant.
3+
> A github action to make Grasshopper development 165% <sup><small>[1]</small></sup> version-control friendlier and 83% more pleasant.
44
5-
Imagine if you could write your grasshopper components in Python code in an actual text file with a powerful editor?
5+
Imagine if you could write your grasshopper components in Python code (both IronPython for RhinoV7 and less, or CPython for RhinoV8) in an actual text file with a powerful editor?
66
Git wouldn't hate you and life would be so much beautiful. 🐵
77

88
Well, here's an action for you then! 🦸‍♀️
@@ -14,25 +14,29 @@ Well, here's an action for you then! 🦸‍♀️
1414
### Usage from Github Actions
1515

1616
The recommended way to use this tool is as a Github Action.
17-
It needs to be run on a windows runner and IronPython/NuGet need to be pre-installed.
17+
It needs to be run on a windows runner and IronPython/NuGet or Python3/pythonnet/Nuget depending of which component you want to build, needs to be pre-installed.
1818

1919
Copy the following workflow code into a `.github/workflows/main.yml` file in your repository.
2020
Make sure you have the components definition (see below for details) stored in a source folder.
2121
Replace the `source` and `target` to match your folder structure.
22+
To specify the interpreter to use, you can define the action parameter `interpreter` to either `ironpython` or `python3` (by default it is `ironpython`).
23+
24+
For IronPython (RhinoV7 and less):
2225

2326
```yaml
2427
on: [push]
2528

2629
jobs:
27-
build_ghuser_components:
30+
build_ipy_ghuser_components:
2831
runs-on: windows-latest
29-
name: Build components
3032
steps:
3133
- uses: actions/checkout@v2
3234
- uses: NuGet/setup-nuget@v1.0.5
35+
3336
- name: Install IronPython
3437
run: |
3538
choco install ironpython --version=2.7.8.1
39+
3640
- uses: compas-dev/compas-actions.ghpython_components@v2
3741
with:
3842
source: components
@@ -43,28 +47,60 @@ jobs:
4347
# upload them as artifacts:
4448
- uses: actions/upload-artifact@v2
4549
with:
46-
name: ghuser-components
50+
name: ipy_ghuser-components
4751
path: build
52+
```
4853
54+
For Python3 (RhinoV8):
55+
56+
```yaml
57+
on: [push]
58+
59+
jobs:
60+
build_cpy_ghuser_components:
61+
runs-on: windows-latest
62+
steps:
63+
- uses: actions/checkout@v2
64+
- uses: NuGet/setup-nuget@v1.0.5
65+
66+
- name: Install CPython and pythonnet package
67+
run: |
68+
choco install python --version=3.9.10
69+
python -m pip install pythonnet==3.0.3
70+
71+
- uses: compas-dev/compas-actions.ghpython_components@v2
72+
with:
73+
source: components
74+
target: build
75+
interpreter: cpython # optional, defaults to ironpython
76+
77+
- uses: actions/upload-artifact@v2
78+
with:
79+
name: cpy_ghuser-components
80+
path: build
4981
```
5082
83+
5184
Commit, push and enjoy! 🍿
5285
5386
### Usage on the command line
5487
5588
Alternatively, you can also use this tool directly from the command line.
56-
Make sure to have IronPython installed and the `GH_IO.dll` assembly available.
89+
Make sure to have IronPython or Python3/pythonnet installed and the `GH_IO.dll` assembly available.
5790
Then start the script pointing it to a source and target folder, e.g.:
5891

59-
ipy componentize.py examples build
92+
ipy componentize_ipy.py examples/ipy build
93+
python componentize_cpy.py examples/cpy build
6094

6195
Optionally, tag it with a version:
6296

63-
ipy componentize.py examples build --version 0.1.2
97+
ipy componentize_ipy.py examples/ipy build --version 0.1.2
98+
python componentize_cpy.py examples/cpy build --version 0.1.2
6499

65100
An optional name prefix can help tell components apart from other similarly named ones:
66101

67-
ipy componentize.py examples build --prefix "(PACKAGE-NAME)"
102+
ipy componentize_ipy.py examples/ipy build --prefix "(PACKAGE-NAME)"
103+
python componentize_cpy.py examples/cpy build --prefix "(PACKAGE-NAME)"
68104

69105
## How to create components
70106

@@ -96,8 +132,7 @@ An alternative is to include them in your packaging steps, e.g. calling `python
96132

97133
## Python code
98134

99-
* Supports both procedural and GH_Component SDK modes (see `isAdvancedMode` in metadata)
100-
* Supports a small set of templated variables that can be used in code:
135+
Supports a small set of templated variables that can be used in code:
101136
* `{{version}}`: Gets replaced with the version, if specified in the command-line.
102137
* `{{name}}`: Gets replaced with the name of the component as defined in the metadata file.
103138
* `{{ghuser_name}}`: Gets replaced with the name of the `.ghuser` file being generated.
@@ -120,10 +155,11 @@ An alternative is to include them in your packaging steps, e.g. calling `python
120155
* `128`: Expose the object in the seventh section on the toolbar.
121156
* `instanceGuid`: **(optional)** Statically define a GUID for this instance. Defaults to a new Guid.
122157
* `ghpython`
123-
* `hideOutput`: **(optional)** Defines whether to hide or not `out` output parameter. Defaults to `True`.
124-
* `hideInput`: **(optional)** Defines whether to hide or not the `code` input parameter. Defaults to `True`.
125-
* `isAdvancedMode`: **(optional)** Defines whether the script is in advanced mode (aka GH_Component SDK mode) or procedural mode. Defaults to `False`.
126-
* `marshalOutGuids`: **(optional)** Defines whether output Guids will be looked up or not. Defaults to `True`. Change to `False` to preserve output Guids.
158+
* `hideOutput`: **(optional ⚠️ only IronPython)** Defines whether to hide or not `out` output parameter. Defaults to `True`.
159+
* `hideInput`: **(optional ⚠️ only IronPython)** Defines whether to hide or not the `code` input parameter. Defaults to `True`.
160+
* `isAdvancedMode`: **(optional ⚠️ only IronPython)** Defines whether the script is in advanced mode (aka GH_Component SDK mode) or procedural mode. Defaults to `False`.
161+
* `marshalOutGuids`: **(optional ⚠️ only IronPython)** Defines whether output Guids will be looked up or not. Defaults to `True`. Change to `False` to preserve output Guids.
162+
* `marshalGuids`: **(optional ⚠️ only CPython)** Defines whether input Guids will be looked up or not. Defaults to `True`. Change to `False` to preserve input Guids.
127163
* `iconDisplay`: **(optional)** Defines whether to display the icon or not. Defaults to `0`.
128164
* `0` : Application setting
129165
* `1` : Text display

action.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ inputs:
1010
prefix:
1111
description: 'Add this prefix to the name of each generated component'
1212
required: false
13+
interpreter:
14+
description: 'Python interpreter to use: ironpython, or cpython'
15+
required: false
16+
default: 'ironpython'
17+
1318
runs:
1419
using: 'composite'
1520
steps:
16-
- run: nuget install Grasshopper -OutputDirectory ./lib -source https://api.nuget.org/v3/index.json
21+
- name: Install Grasshopper
22+
run: nuget install Grasshopper -OutputDirectory ./lib -source https://api.nuget.org/v3/index.json
1723
shell: pwsh
18-
- run: |
19-
$command="ipy"
20-
$params="${{ github.action_path }}/componentize.py", "${{ inputs.source }}", "${{ inputs.target }}", "--ghio", "./lib"
21-
$prefix="${{ inputs.prefix }}"
24+
25+
- name: Launch componentizer
26+
run: |
27+
if ("${{ inputs.interpreter }}" -eq "cpython") {
28+
$command="python"
29+
$componentizer="${{ github.action_path }}/componentize_cpy.py"
30+
} else {
31+
$command="ipy"
32+
$componentizer="${{ github.action_path }}/componentize_ipy.py"
33+
}
34+
$params=$componentizer, "${{ inputs.source }}", "${{ inputs.target }}", "--ghio", "./lib"
35+
$prefix="${{ inputs.prefix }}"
2236
if( $prefix )
2337
{
2438
$params=$params + "--prefix", "$prefix"

0 commit comments

Comments
 (0)