Skip to content

Commit 9a34af0

Browse files
jessfrazgithub-actions[bot]graphite-app[bot]jacebrowning
authored
commit python types stubs (#7996)
* commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * chore(stubs): auto-update PyO3 .pyi * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * Update rust/kcl-python-bindings/pyproject.toml Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * Update .github/workflows/update-python-stubs.yml Co-authored-by: Jace Browning <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> * commit python types stubs Signed-off-by: Jessie Frazelle <[email protected]> --------- Signed-off-by: Jessie Frazelle <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> Co-authored-by: Jace Browning <[email protected]>
1 parent 6b2658d commit 9a34af0

File tree

3 files changed

+128
-7
lines changed

3 files changed

+128
-7
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Auto-update PyO3 stubs
2+
on:
3+
pull_request:
4+
branches: [main] # PRs _into_ main
5+
paths:
6+
- "rust/kcl-python-bindings/**" # run only when Rust/Python code changes
7+
- ".github/workflows/update-python-stubs.yml"
8+
permissions:
9+
contents: write # allow committing back to the PR branch
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
12+
cancel-in-progress: true
13+
jobs:
14+
build-and-stub:
15+
runs-on: namespace-profile-ubuntu-2-cores
16+
defaults:
17+
run:
18+
shell: bash -eux {0}
19+
steps:
20+
- uses: actions/create-github-app-token@v2
21+
id: app-token
22+
with:
23+
# required
24+
app-id: ${{ secrets.GH_ORG_APP_ID }}
25+
private-key: ${{ secrets.GH_ORG_APP_PRIVATE_KEY }}
26+
owner: ${{ github.repository_owner }}
27+
- name: Checkout the repo
28+
uses: actions/checkout@v4
29+
with:
30+
submodules: recursive
31+
token: ${{ steps.app-token.outputs.token }}
32+
ref: ${{ github.head_ref }}
33+
- name: Install toolchain + maturin
34+
uses: PyO3/maturin-action@v1 # Rust + Python + maturin
35+
with:
36+
working-directory: rust/kcl-python-bindings
37+
- name: Install deps & dev-install the crate
38+
run: |
39+
pip install pyo3-stubgen
40+
pip install --no-cache-dir --editable ./rust/kcl-python-bindings
41+
# ------------------------------------------------------------
42+
# 2. Re-generate the .pyi
43+
# ------------------------------------------------------------
44+
- name: Generate stubs
45+
run: |
46+
mkdir -p rust/kcl-python-bindings/stubs
47+
pyo3-stubgen kcl stubs
48+
ls -la stubs
49+
cp stubs/* rust/kcl-python-bindings/stubs/
50+
# ------------------------------------------------------------
51+
# 3. Commit & push if anything changed
52+
# ------------------------------------------------------------
53+
- name: Check for diff
54+
id: git-status
55+
run: |
56+
git add rust/kcl-python-bindings/stubs/*.pyi
57+
if git diff --cached --quiet; then
58+
echo "changed=false" >> "$GITHUB_OUTPUT"
59+
else
60+
echo "changed=true" >> "$GITHUB_OUTPUT"
61+
fi
62+
- name: Commit & push
63+
if: steps.git-status.outputs.changed == 'true'
64+
run: |
65+
git config --global user.name 'github-actions[bot]'
66+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
67+
git commit -m "chore(stubs): auto-update PyO3 .pyi"
68+
git push --force-with-lease

rust/kcl-python-bindings/pyproject.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@ build-backend = "maturin"
66
name = "zoo-kcl"
77
requires-python = ">=3.8"
88
classifiers = [
9-
"Programming Language :: Rust",
10-
"Programming Language :: Python :: Implementation :: CPython",
11-
"Programming Language :: Python :: Implementation :: PyPy",
9+
"Programming Language :: Rust",
10+
"Programming Language :: Python :: Implementation :: CPython",
11+
"Programming Language :: Python :: Implementation :: PyPy",
1212
]
1313
dynamic = ["version"]
1414

1515
[project.optional-dependencies]
16-
test = [
17-
"pytest",
18-
"pytest-asyncio",
19-
]
16+
test = ["pytest", "pytest-asyncio"]
2017

2118
[tool.maturin]
2219
features = ["pyo3/extension-module"]
20+
include = ["stubs/kcl.pyi"]
2321

2422
[tool.setuptools]
2523
include-package-data = false
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# flake8: noqa: PYI021
2+
def execute(path):
3+
"""Execute the kcl code from a file path."""
4+
5+
def execute_and_export(path, export_format):
6+
"""Execute a kcl file and export it to a specific file format."""
7+
8+
def execute_and_snapshot(path, image_format):
9+
"""Execute a kcl file and snapshot it in a specific format."""
10+
11+
def execute_and_snapshot_views(path, image_format, snapshot_options):
12+
...
13+
14+
def execute_code(code):
15+
"""Execute the kcl code."""
16+
17+
def execute_code_and_export(code, export_format):
18+
"""Execute the kcl code and export it to a specific file format."""
19+
20+
def execute_code_and_snapshot(code, image_format):
21+
"""Execute the kcl code and snapshot it in a specific format."""
22+
23+
def execute_code_and_snapshot_views(code, image_format, snapshot_options):
24+
"""
25+
Execute the kcl code and snapshot it in a specific format.
26+
Returns one image for each camera angle you provide.
27+
If you don't provide any camera angles, a default head-on camera angle will be used.
28+
"""
29+
30+
def format(code):
31+
"""Format the kcl code. This will return the formatted code."""
32+
33+
def format_dir(dir):
34+
"""Format a whole directory of kcl code."""
35+
36+
def import_and_snapshot(filepaths, format, image_format):
37+
...
38+
39+
def import_and_snapshot_views(filepaths, format, image_format, snapshot_options):
40+
...
41+
42+
def lint(code):
43+
"""Lint the kcl code."""
44+
45+
def mock_execute(path):
46+
"""Mock execute the kcl code from a file path."""
47+
48+
def mock_execute_code(code):
49+
"""Mock execute the kcl code."""
50+
51+
def parse(path):
52+
"""Parse the kcl code from a file path."""
53+
54+
def parse_code(code):
55+
"""Parse the kcl code."""

0 commit comments

Comments
 (0)