Skip to content

Commit 2449324

Browse files
authored
[core] package kernels-data as a python wrapper. (#475)
* package kernels-data as a python wrapper. * up * release * 0.0.1 * mirror casing./ * change to load. * up * prevent double conversion * mypy
1 parent 178616a commit 2449324

17 files changed

Lines changed: 839 additions & 6 deletions

File tree

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# This file is autogenerated by maturin v1.13.1
2+
# To update, run
3+
#
4+
# maturin generate-ci github -m kernels-data/bindings/python/Cargo.toml -o .github/workflows/kernels_data_python_release.yaml
5+
#
6+
# Post-generation edits:
7+
# - manifest paths made relative
8+
# - publish step switched from `uv publish` + API token to
9+
# `PyO3/maturin-action` + PyPI trusted publishing (see plan.md §3a, §3b)
10+
# - pull_request trigger gained `paths-ignore` for docs-only PRs
11+
name: CI
12+
13+
on:
14+
push:
15+
branches:
16+
- main
17+
- master
18+
tags:
19+
- '*'
20+
pull_request:
21+
paths-ignore:
22+
- "docs/**"
23+
- "*.md"
24+
workflow_dispatch:
25+
26+
permissions:
27+
contents: read
28+
29+
jobs:
30+
linux:
31+
runs-on: ${{ matrix.platform.runner }}
32+
strategy:
33+
matrix:
34+
platform:
35+
- runner: ubuntu-22.04
36+
target: x86_64
37+
- runner: ubuntu-22.04
38+
target: x86
39+
- runner: ubuntu-22.04
40+
target: aarch64
41+
- runner: ubuntu-22.04
42+
target: armv7
43+
- runner: ubuntu-22.04
44+
target: s390x
45+
- runner: ubuntu-22.04
46+
target: ppc64le
47+
steps:
48+
- uses: actions/checkout@v6
49+
- uses: actions/setup-python@v6
50+
with:
51+
python-version: 3.8
52+
- name: Build wheels
53+
uses: PyO3/maturin-action@v1
54+
with:
55+
target: ${{ matrix.platform.target }}
56+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml
57+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
58+
manylinux: auto
59+
- name: Build free-threaded wheels
60+
uses: PyO3/maturin-action@v1
61+
with:
62+
target: ${{ matrix.platform.target }}
63+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml -i python3.14t
64+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
65+
manylinux: auto
66+
- name: Upload wheels
67+
uses: actions/upload-artifact@v6
68+
with:
69+
name: wheels-linux-${{ matrix.platform.target }}
70+
path: dist
71+
72+
musllinux:
73+
runs-on: ${{ matrix.platform.runner }}
74+
strategy:
75+
matrix:
76+
platform:
77+
- runner: ubuntu-22.04
78+
target: x86_64
79+
- runner: ubuntu-22.04
80+
target: x86
81+
- runner: ubuntu-22.04
82+
target: aarch64
83+
- runner: ubuntu-22.04
84+
target: armv7
85+
steps:
86+
- uses: actions/checkout@v6
87+
- uses: actions/setup-python@v6
88+
with:
89+
python-version: 3.8
90+
- name: Build wheels
91+
uses: PyO3/maturin-action@v1
92+
with:
93+
target: ${{ matrix.platform.target }}
94+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml
95+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
96+
manylinux: musllinux_1_2
97+
- name: Build free-threaded wheels
98+
uses: PyO3/maturin-action@v1
99+
with:
100+
target: ${{ matrix.platform.target }}
101+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml -i python3.14t
102+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
103+
manylinux: musllinux_1_2
104+
- name: Upload wheels
105+
uses: actions/upload-artifact@v6
106+
with:
107+
name: wheels-musllinux-${{ matrix.platform.target }}
108+
path: dist
109+
110+
windows:
111+
runs-on: ${{ matrix.platform.runner }}
112+
strategy:
113+
matrix:
114+
platform:
115+
- runner: windows-latest
116+
target: x64
117+
python_arch: x64
118+
- runner: windows-latest
119+
target: x86
120+
python_arch: x86
121+
- runner: windows-11-arm
122+
target: aarch64
123+
python_arch: arm64
124+
steps:
125+
- uses: actions/checkout@v6
126+
- uses: actions/setup-python@v6
127+
with:
128+
python-version: 3.13
129+
architecture: ${{ matrix.platform.python_arch }}
130+
- name: Build wheels
131+
uses: PyO3/maturin-action@v1
132+
with:
133+
target: ${{ matrix.platform.target }}
134+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml
135+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
136+
- uses: actions/setup-python@v6
137+
with:
138+
python-version: 3.14t
139+
architecture: ${{ matrix.platform.python_arch }}
140+
- name: Build free-threaded wheels
141+
uses: PyO3/maturin-action@v1
142+
with:
143+
target: ${{ matrix.platform.target }}
144+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml -i python3.14t
145+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
146+
- name: Upload wheels
147+
uses: actions/upload-artifact@v6
148+
with:
149+
name: wheels-windows-${{ matrix.platform.target }}
150+
path: dist
151+
152+
macos:
153+
runs-on: ${{ matrix.platform.runner }}
154+
strategy:
155+
matrix:
156+
platform:
157+
- runner: macos-15-intel
158+
target: x86_64
159+
- runner: macos-latest
160+
target: aarch64
161+
steps:
162+
- uses: actions/checkout@v6
163+
- uses: actions/setup-python@v6
164+
with:
165+
python-version: 3.8
166+
- name: Build wheels
167+
uses: PyO3/maturin-action@v1
168+
with:
169+
target: ${{ matrix.platform.target }}
170+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml
171+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
172+
- uses: actions/setup-python@v6
173+
with:
174+
python-version: 3.14t
175+
- name: Build free-threaded wheels
176+
uses: PyO3/maturin-action@v1
177+
with:
178+
target: ${{ matrix.platform.target }}
179+
args: --release --out dist --manifest-path kernels-data/bindings/python/Cargo.toml -i python3.14t
180+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
181+
- name: Upload wheels
182+
uses: actions/upload-artifact@v6
183+
with:
184+
name: wheels-macos-${{ matrix.platform.target }}
185+
path: dist
186+
187+
sdist:
188+
runs-on: ubuntu-latest
189+
steps:
190+
- uses: actions/checkout@v6
191+
- name: Build sdist
192+
uses: PyO3/maturin-action@v1
193+
with:
194+
command: sdist
195+
args: --out dist --manifest-path kernels-data/bindings/python/Cargo.toml
196+
- name: Upload sdist
197+
uses: actions/upload-artifact@v6
198+
with:
199+
name: wheels-sdist
200+
path: dist
201+
202+
release:
203+
name: Release
204+
runs-on: ubuntu-latest
205+
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
206+
needs: [linux, musllinux, windows, macos, sdist]
207+
environment:
208+
name: pypi
209+
url: https://pypi.org/p/kernels-data
210+
permissions:
211+
# Use to sign the release artifacts
212+
id-token: write
213+
# Used to upload release artifacts
214+
contents: write
215+
# Used to generate artifact attestation
216+
attestations: write
217+
steps:
218+
- uses: actions/download-artifact@v7
219+
- name: Generate artifact attestation
220+
uses: actions/attest-build-provenance@v3
221+
with:
222+
subject-path: 'wheels-*/*'
223+
- name: Publish to PyPI
224+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
225+
uses: PyO3/maturin-action@v1
226+
with:
227+
command: upload
228+
args: --non-interactive --skip-existing wheels-*/*

.github/workflows/rust.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
( cd kernel-abi-check/kernel-abi-check && cargo fmt --all -- --check )
1717
( cd kernel-abi-check/bindings/python && cargo fmt --all -- --check )
1818
- name: Cargo fmt (kernels-data)
19-
run: ( cd kernels-data && cargo fmt --all -- --check )
19+
run: |
20+
( cd kernels-data && cargo fmt --all -- --check )
21+
( cd kernels-data/bindings/python && cargo fmt --all -- --check )
2022
- name: Cargo fmt (kernel-builder)
2123
run: ( cd kernel-builder && cargo fmt --all -- --check )
2224

@@ -42,6 +44,8 @@ jobs:
4244
( cd kernel-abi-check/kernel-abi-check && cargo clippy -- -D warnings )
4345
( cd kernel-abi-check/bindings/python && cargo clippy -- -D warnings )
4446
- name: Clippy (kernels-data)
45-
run: ( cd kernels-data && cargo clippy -- -D warnings )
47+
run: |
48+
( cd kernels-data && cargo clippy -- -D warnings )
49+
( cd kernels-data/bindings/python && cargo clippy -- -D warnings )
4650
- name: Clippy (kernel-builder)
4751
run: ( cd kernel-builder && cargo clippy -- -D warnings )

.github/workflows/test_python.yaml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19-
build:
20-
name: Run tests
19+
kernel-abi-check:
20+
name: kernel-abi-check bindings
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
@@ -40,3 +40,31 @@ jobs:
4040

4141
- name: Run tests
4242
run: ( cd kernel-abi-check/bindings/python && uv run pytest tests )
43+
44+
kernels-data:
45+
name: kernels-data bindings
46+
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
python-version: ["3.12"]
50+
51+
env:
52+
UV_PYTHON_PREFERENCE: only-managed
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v6
57+
58+
- name: Install uv and set the python version
59+
uses: astral-sh/setup-uv@v7
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
63+
- name: Install the project
64+
run: ( cd kernels-data/bindings/python && uv sync --all-extras --dev)
65+
66+
- name: Run tests
67+
run: ( cd kernels-data/bindings/python && uv run pytest tests )
68+
69+
- name: Check type stubs match runtime
70+
run: ( cd kernels-data/bindings/python && uv run python -m mypy.stubtest kernels_data --allowlist stubtest-allowlist.txt )

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ members = [
44
"kernel-abi-check/bindings/python",
55
"kernel-builder",
66
"kernels-data",
7+
"kernels-data/bindings/python",
78
]
89
resolver = "2"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "kernels-data-python"
3+
version = "0.0.1"
4+
edition = "2024"
5+
description = "Kernels data structures (Python bindings)"
6+
homepage = "https://github.com/huggingface/kernels"
7+
license = "Apache-2.0"
8+
repository = "https://github.com/huggingface/kernels"
9+
10+
[lib]
11+
name = "kernels_data"
12+
crate-type = ["cdylib"]
13+
14+
[dependencies]
15+
pyo3 = { version = "0.26", features = ["abi3", "abi3-py38"] }
16+
17+
[dependencies.kernels-data]
18+
path = "../.."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include Cargo.toml
2+
include pyproject.toml
3+
include ../../../LICENSE
4+
recursive-include src *

0 commit comments

Comments
 (0)