Skip to content

Commit

Permalink
python bindings for wellen (#26)
Browse files Browse the repository at this point in the history
* remove ci for now

* we're getting somewhere..

* adding more methods

* clean up pywellen, add documenting makefile

* add regressions, add release job, add name

* rename

* have pywellen version same as workspace

* setup py

* woops, forgot to install pytest

---------

Co-authored-by: James Connolly <[email protected]>
  • Loading branch information
1024bees and James Connolly authored Oct 16, 2024
1 parent 245b1c8 commit 5f15ba9
Show file tree
Hide file tree
Showing 14 changed files with 834 additions and 2 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: python release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write

jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get the release version from the tag
if: env.VERSION == ''
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
outputs:
version: ${{ env.VERSION }}

linux:
runs-on: ubuntu-latest
needs: ["create-release"]

strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --manifest-path pywellen/Cargo.toml --out dist --find-interpreter
sccache: "true"
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist

macos:
runs-on: macos-latest
needs: ["create-release"]
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --manifest-path pywellen/Cargo.toml --out dist --find-interpreter
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --manifest-path pywellen/Cargo.toml --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
pytests:
name: Python tests
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
- name: Update Rust to ${{ matrix.toolchain }}
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: actions/checkout@v4
- name: Build
run: pip install -e . -v && pip install pytest
working-directory: pywellen
- name: Run tests
run: pytest tests/
working-directory: pywellen

semver:
name: Check Semantic Versioning
Expand Down
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,66 @@
flamegraph.svg
perf.data
perf.data.old

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[workspace]
resolver = "2"
members = ["wellen"]
members = ["wellen", "pywellen"]
default-members = ["wellen"]

[workspace.package]
Expand All @@ -23,6 +23,7 @@ keywords = ["vcd", "fst", "waveform", "wavedump"]
bytesize = "1.3.0"
fst-reader = "0.8.5"
leb128 = "0.2.5"

lz4_flex = "0.11.3"
memmap2 = "0.9.5"
rayon = "1.10.0"
Expand All @@ -37,6 +38,7 @@ clap = { version = "4.4.6", features = ["derive"] }
criterion = "0.5"
indicatif = "0.17.8"
proptest = "1.4.0"
wellen = { path = "wellen" }

[profile.release]
debug = true
72 changes: 72 additions & 0 deletions pywellen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version
16 changes: 16 additions & 0 deletions pywellen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "pywellen"
version.workspace = true
edition = "2021"
authors = ["James Connolly <[email protected]>"]

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

[dependencies]
bytemuck = "1.18.0"
num-bigint = "0.4.6"
pyo3 = { version = "0.21.1", features = ["num-bigint"] }
wellen = { workspace = true }
18 changes: 18 additions & 0 deletions pywellen/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: help develop wheel test

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


deps: ## Installs the required dependencies to develop pywellen -- we use pyenv to manage python versions
python3 -m venv dev && source dev/bin/activate && pip install pytest maturin


develop: ## Builds pywellen, and installs it into the current virtual env
maturin develop

wheel: ## Builds the pywellen wheel and is placed in dist/
maturin build --out dist

test: develop ## Builds and tests pywellen via pytest
pytest tests/
25 changes: 25 additions & 0 deletions pywellen/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[project]
name = "pywellen"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",


]
dynamic = ["version"]
license = "BSD-3-Clause"

authors = [{ name = "James Connolly", email = "[email protected]" }]


[build-system]
requires = ["maturin>=1.5,<2.0"]
build-backend = "maturin"


[tool.maturin]
features = ["pyo3/extension-module"]
1 change: 1 addition & 0 deletions pywellen/pywellen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pywellen.pywellen import *
Loading

0 comments on commit 5f15ba9

Please sign in to comment.