Skip to content

Commit

Permalink
feat: Add Python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny committed Oct 14, 2023
1 parent a72f90f commit 531ac2a
Show file tree
Hide file tree
Showing 23 changed files with 2,128 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
release:
types:
- published
name: Publish bindings
name: Publish C bindings
jobs:
build-binaries:
if: startsWith(github.ref_name, 'accesskit_c-v')
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
clang-format-version: 15
check-path: bindings/c

- name: black --check
uses: psf/black@stable

test:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/python-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on:
push:
tags:
- 'accesskit_python-v*'

name: Publish Python bindings

jobs:
build-wheels:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
python-arch: x64
rust-target: x86_64
- os: macos-latest
python-arch: x64
rust-target: universal2-apple-darwin
- os: ubuntu-latest
python-arch: x64
rust-target: x86_64
- os: ubuntu-latest
python-arch: x64
rust-target: i686
skip-wheel-installation: true
- os: windows-latest
python-arch: x64
rust-target: x64
- os: windows-latest
python-arch: x86
rust-target: x86

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.7
architecture: ${{ matrix.python-arch }}
- uses: dtolnay/rust-toolchain@stable
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.rust-target }}
manylinux: auto
args: --release --out dist --sdist
- name: Test wheel installation
if: matrix.skip-wheel-installation != true
run: |
pip install accesskit --no-index --find-links dist --force-reinstall
python -c "import accesskit"
- name: Upload wheel
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [build-wheels]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
pip install --upgrade twine
twine upload --skip-existing *
57 changes: 41 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ members = [
"platforms/windows",
"platforms/winit",
"bindings/c",
"bindings/python",
]
default-members = [
"common",
"consumer",
"platforms/winit",
"bindings/c",
"bindings/python",
]

[profile.release]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ While we expect GUI toolkit developers to eventually integrate AccessKit into th

### Language bindings

UI toolkit developers who merely want to use AccessKit should not be required to use Rust directly. In addition to a direct Rust API, AccessKit provides a C API covering both the core data structures and all platform adapters. This C API can be used from a variety of languages. The Rust source for the C bindings is in [the `bindings/c directory`](https://github.com/AccessKit/accesskit/tree/main/bindings/c). The AccessKit project also provides a pre-built package, including a header file, both dynamic and static libraries, and sample code, for the C API, so toolkit developers won't need to deal with Rust at all. The latest pre-built package can be found in [AccessKit's GitHub releases](https://github.com/AccessKit/accesskit/releases); search for the name "accesskit_c".
UI toolkit developers who merely want to use AccessKit should not be required to use Rust directly.

AccessKit provides a C API covering both the core data structures and all platform adapters. This C API can be used from a variety of languages. The Rust source for the C bindings is in [the `bindings/c directory`](https://github.com/AccessKit/accesskit/tree/main/bindings/c). The AccessKit project also provides a pre-built package, including a header file, both dynamic and static libraries, and sample code, for the C API, so toolkit developers won't need to deal with Rust at all. The latest pre-built package can be found in [AccessKit's GitHub releases](https://github.com/AccessKit/accesskit/releases); search for the name "accesskit_c".

Bindings for the Python programming language are also available. Rust source code is in [the `bindings/python directory`](https://github.com/AccessKit/accesskit/tree/main/bindings/python). Releases can be found on [PyPI](https://pypi.org/project/accesskit/) and can be included in your project using `pip`.

While many languages can use a C API, we also plan to provide libraries that make it easier to safely use AccessKit from languages other than Rust and C. In particular, we're planning to provide such a library for Java and other JVM-based languages.

Expand Down
11 changes: 11 additions & 0 deletions bindings/python/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
30 changes: 30 additions & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "accesskit_python"
version = "0.1.0"
authors = ["Arnold Loubriat <datatriny@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "Python bindings to the AccessKit library"
readme = "README.md"
publish = false
edition = "2021"

[lib]
name = "accesskit"
crate-type = ["cdylib"]
doc = false

[features]
extension-module = ["pyo3/extension-module"]

[dependencies]
accesskit = { version = "0.12.0", path = "../../common", features = ["pyo3"] }
pyo3 = { version = "0.20", features = ["abi3-py37", "multiple-pymethods"] }

[target.'cfg(target_os = "windows")'.dependencies]
accesskit_windows = { version = "0.15.0", path = "../../platforms/windows" }

[target.'cfg(target_os = "macos")'.dependencies]
accesskit_macos = { version = "0.10.0", path = "../../platforms/macos" }

[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
accesskit_unix = { version = "0.6.0", path = "../../platforms/unix" }
3 changes: 3 additions & 0 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AccessKit

These are the bindings to use AccessKit from Python.
Loading

0 comments on commit 531ac2a

Please sign in to comment.