Skip to content

Commit

Permalink
feat: kcl python lib based pyo3
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Apr 15, 2024
1 parent 3ed460d commit dc72667
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 504 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@ jobs:
- name: Go code test
run: go test ./...

python-test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
working-directory: python
run: |
python3 -m pip install -r ./scripts/requirements.txt
python3 -m pip install pytest
python3 -m pip install setuptools wheel twine
- name: Python code test
working-directory: python
run: python3 -m pytest

java-test:
permissions:
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
Expand Down
116 changes: 116 additions & 0 deletions .github/workflows/python-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# This file is autogenerated by maturin v1.5.1
# To update, run
#
# maturin generate-ci github
#
name: python-test

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
working-directory: "python"
command: sdist
args: -o dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: python/dist

linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [ x86_64, aarch64 ]
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
working-directory: "python"
command: build
args: --release -o dist --find-interpreter
env:
# Workaround ring 0.17 build issue
CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: python/dist

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
working-directory: "python"
command: build
args: --release -o dist --find-interpreter
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: python/dist

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
working-directory: "python"
command: build
target: universal2-apple-darwin
args: --release -o dist --find-interpreter
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: python/dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
permissions:
contents: read
id-token: write
needs: [ macos, linux, windows ]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
path: python/dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: "contains(github.ref, '-')"
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
packages-dir: python/dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: "!contains(github.ref, '-')"
with:
skip-existing: true
packages-dir: python/dist
31 changes: 0 additions & 31 deletions .github/workflows/release_python.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ zz_*
*.so
*.dll
*.d
*.lock
*.ll
*.ll.lock
_a.out.*
Expand Down
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vs/
.vscode/
.idea/
venv

# kcl files
.pytest_cache
Expand Down
12 changes: 12 additions & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "kcl-python-lib"
version = "0.8.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.1"
kcl-lang = {path = "../"}
32 changes: 32 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# KCL Artifact Library for Python

## Developing

Setup virtualenv:

```shell
python3 -m venv venv
```

Activate venv:

```shell
source venv/bin/activate
```

Install maturin:

```shell
cargo install maturin
```

Build bindings:

```shell
maturin develop
```

Test

```shell
python3 -m pytest
```
1 change: 1 addition & 0 deletions python/kcl_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._kcl_lib import *
Loading

0 comments on commit dc72667

Please sign in to comment.