Repository navigation
136 lines (130 loc) · 4.56 KB
/
Copy pathpython.yml
File metadata and controls
136 lines (130 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# The Python package (bindings/python): built as the wheel people install, and tested from it, on Linux, macOS and Windows with the oldest
# and the newest Python it supports. The tests run the tiny golden models, threads, errors, the client against a fake host and (with the
# program built here) against the real `grayling` program with its fake brain, and download() against a local server.
#
name: python
on:
push:
branches: [main]
paths:
- bindings/python/**
- crates/**
- Cargo.toml
- Cargo.lock
- .github/workflows/python.yml
pull_request:
paths:
- bindings/python/**
- crates/**
- Cargo.toml
- Cargo.lock
- .github/workflows/python.yml
workflow_dispatch:
concurrency:
group: python-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
test:
name: test ${{ matrix.os }} python ${{ matrix.python }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-15, windows-2025]
python: ["3.9", "3.13"]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
bindings/python
key: python-${{ matrix.python }}
- name: The program (the client's tests start it, with its fake brain)
shell: bash
run: cargo build -p grayling-host
- name: Build the wheel
shell: bash
working-directory: bindings/python
run: |
set -eu
python -m pip install --upgrade pip
python -m pip install "maturin>=1.9,<2" pytest
maturin build --release --locked --out dist
ls -la dist
- name: Install the wheel, away from the sources
shell: bash
working-directory: bindings/python
run: |
set -eu
python -m pip install --no-index --find-links dist grayling
python -c "import grayling; print(grayling.__version__, grayling.find_program())"
python -m grayling --version
- name: Test
shell: bash
working-directory: bindings/python
env:
GRAYLING_TEST_PROGRAM: ${{ github.workspace }}/target/debug/grayling${{ runner.os == 'Windows' && '.exe' || '' }}
run: python -m pytest -p no:cacheprovider
- name: What the wheel weighs
shell: bash
working-directory: bindings/python
run: |
python - <<'PY'
import glob, os, zipfile
for w in glob.glob("dist/*.whl"):
z = zipfile.ZipFile(w)
print(os.path.basename(w), os.path.getsize(w), "bytes;", {i.filename: i.file_size for i in z.infolist() if i.filename.endswith((".so", ".pyd"))})
PY
checks:
name: lints, types, source package
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: Swatinem/rust-cache@v2
with:
workspaces: bindings/python
key: python-checks
- name: Rust
working-directory: bindings/python
run: |
set -eu
cargo fmt --check
cargo clippy --locked --all-targets -- -D warnings
- name: No network code in the wheel
working-directory: bindings/python
run: |
set -eu
if cargo tree --locked -e normal --prefix none | grep -E '^(ureq|rustls|ring|openssl|native-tls|hyper|reqwest|webpki)'; then
echo "::error::the extension has network code"; exit 1
fi
echo "no TLS, no HTTP client"
- name: Types
working-directory: bindings/python
run: |
set -eu
python -m pip install mypy typing_extensions
python -m mypy --strict python/grayling
- name: The source package builds, and installs where there is a Rust toolchain
run: |
set -eu
python -m pip install "maturin>=1.9,<2"
(cd bindings/python && maturin sdist --out ../../sdist)
ls -la sdist
python -m venv from-sdist
from-sdist/bin/python -m pip install sdist/grayling-*.tar.gz
from-sdist/bin/python -m grayling --version
from-sdist/bin/python -c "from grayling import Engine; e = Engine.load('crates/grayling/tests/golden/tiny', threads=1, word_conf='greedy'); print(e.suggest(text='the qu'))"