Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f0513e3
Start python bindings with maturin
orottier Jun 8, 2024
7232a50
ignore .env
orottier Jun 8, 2024
3c364e9
It's alive
orottier Jun 8, 2024
559caba
Get OscillatorNode to work in Python
orottier Jun 10, 2024
9c0db75
Cleanup
orottier Jun 11, 2024
a467764
Update pyproject.toml
orottier Jun 11, 2024
427bec1
Move python workflow to root, will probably fail
orottier Jun 11, 2024
1aa6883
Actually move GitHub workflow for Python
orottier Jun 11, 2024
b796d57
Python workflow: specify Cargo.toml manifest in subdirectory
orottier Jun 11, 2024
4e6dc4c
Python workflow: install Jack and Alsa on Linux runners
orottier Jun 11, 2024
500a146
Python workflow: install pkg-config
orottier Jun 11, 2024
3902cce
Python workflow: ignore musl build for now - fails on pkg-config
orottier Jun 11, 2024
9b00033
Python workflow: install alsa as well
orottier Jun 11, 2024
413cb88
Python workflow: install packages inside the Docker
orottier Jun 11, 2024
b919453
Python workflow: do not sudo in Docker
orottier Jun 11, 2024
89051bf
Python workflow: linux image needs yum instead of apt?
orottier Jun 12, 2024
f1a9810
Python workflow: on run yum on Linux x64 and Arm, add -y
orottier Jun 12, 2024
cb07a5f
Python workflow: do not install pkg-config on linux
orottier Jun 12, 2024
662e16c
Python workflow: force install any alsa
orottier Jun 12, 2024
35a2252
Python workflow: install different alsa dep
orottier Jun 12, 2024
ecf7613
Python workflow: ARM pkg-config does not support cross compile
orottier Jun 12, 2024
87e4852
Why suggest to install `alsa` when it does not exist
orottier Jun 12, 2024
40a0e3f
Python workflow: just ignore linux
orottier Jun 12, 2024
eb30733
Python workflow: manual release
orottier Jun 12, 2024
832ca59
Python workflow: auto-release (once)
orottier Jun 12, 2024
c930e96
Python workflow: when releasing, do not specify manifest-path
orottier Jun 12, 2024
5077198
Python: use getter/setter for AudioParam value
orottier Jun 13, 2024
330a7f7
Python workflow: revert to only release on tags
orottier Jun 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# This file is autogenerated by maturin v1.6.0
# To update, run
#
# maturin generate-ci github
#
name: python

on:
push:
branches:
- "*"
tags:
- "*"
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
# Ignore linux for now - cannot install Alsa?
# linux:
# runs-on: ${{ matrix.platform.runner }}
# strategy:
# matrix:
# platform:
# - runner: ubuntu-latest
# target: x86_64
# - runner: ubuntu-latest
# target: x86
# # - runner: ubuntu-latest
# # target: aarch64
# # - runner: ubuntu-latest
# # target: armv7
# # - runner: ubuntu-latest
# # target: s390x
# # - runner: ubuntu-latest
# # target: ppc64le
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: 3.x
# - name: Build wheels
# uses: PyO3/maturin-action@v1
# with:
# target: ${{ matrix.platform.target }}
# args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
# sccache: "true"
# before-script-linux: yum update -y && yum install -y alsa-dev alsa-utils alsa-lib
# manylinux: auto
# - name: Upload wheels
# uses: actions/upload-artifact@v4
# with:
# name: wheels-linux-${{ matrix.platform.target }}
# path: dist
#
# Ignore musl for now - issue with pkg-config installed but not found.
#
# musllinux:
# runs-on: ${{ matrix.platform.runner }}
# strategy:
# matrix:
# platform:
# - runner: ubuntu-latest
# target: x86_64
# - runner: ubuntu-latest
# target: x86
# - runner: ubuntu-latest
# target: aarch64
# - runner: ubuntu-latest
# target: armv7
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: 3.x
# - name: Build wheels
# uses: PyO3/maturin-action@v1
# with:
# target: ${{ matrix.platform.target }}
# args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
# sccache: "true"
# before-script-linux: yum update -y && yum install -y alsa-utils alsa-lib
# manylinux: musllinux_1_2
# - name: Upload wheels
# uses: actions/upload-artifact@v4
# with:
# name: wheels-musllinux-${{ matrix.platform.target }}
# path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.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: --out dist --manifest-path python/Cargo.toml
- 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, musllinux, windows, macos, sdist] # musl and linux ignored for now
needs: [windows, 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-*/*
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ include = [
]
rust-version = "1.76"

[workspace]
members = ["python"]

[dependencies]
almost = "0.2.0"
arc-swap = "1.6"
Expand Down
73 changes: 73 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/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
/.env
14 changes: 14 additions & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "web_audio_api"
version = "0.1.0"
edition = "2021"

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

[dependencies]
pyo3 = "0.21.1"
web-audio-api-rs = { path = "../", package = "web-audio-api" }
25 changes: 25 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Python bindings for web-audio-api-rs

## Local development

```bash
# cd to this directory

# if not already, create a virtual env
python3 -m venv .env

# enter the virtual env
source .env/bin/activate

# (re)build the package
maturin develop
```

```python
import web_audio_api
ctx = web_audio_api.AudioContext()
osc = web_audio_api.OscillatorNode(ctx)
osc.connect(ctx.destination())
osc.start()
osc.frequency().set_value(300)
```
15 changes: 15 additions & 0 deletions python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import web_audio_api
from time import sleep

ctx = web_audio_api.AudioContext()
osc = web_audio_api.OscillatorNode(ctx)
osc.connect(ctx.destination())
osc.start()

print("freq =", osc.frequency().value);
sleep(4)

osc.frequency().value = 300
print("freq =", osc.frequency().value);

sleep(4)
23 changes: 23 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
requires = ["maturin>=1.6,<2.0"]
build-backend = "maturin"

[project]
name = "web-audio-api"
version = "0.1.0"
requires-python = ">=3.8"
description = "A Rust/Python implementation of the Web Audio API, for use in non-browser contexts"
license = {text = "MIT License"}
keywords = ["web-audio-api", "audio", "sound", "dsp"]
classifiers = [
"Programming Language :: Rust",
"Topic :: Multimedia :: Sound/Audio",
"Programming Language :: Python :: Implementation :: PyPy",
]

[project.urls]
Repository = "https://github.com/orottier/web-audio-api-rs"
Issues = "https://github.com/orottier/web-audio-api-rs/issues"

[tool.maturin]
features = ["pyo3/extension-module"]
Loading
Loading