Repository navigation
179 lines (168 loc) · 5.16 KB
/
Copy pathpython.yml
File metadata and controls
179 lines (168 loc) · 5.16 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Python
# Builds and tests the Python bindings in python/ (PyO3 + maturin, abi3
# wheels for CPython >= 3.10). Publishing to PyPI is a separate job that only
# runs for a `python-v*` tag when the repository owner has enabled it (see the
# `publish` job); pushes and pull requests never publish.
on:
push:
branches: [main]
tags: ["python-v*"]
paths:
- "python/**"
- "src/**"
- "crates/**"
- "data/**"
- "build.rs"
- "Cargo.toml"
- "Cargo.lock"
- "doc/python.md"
- ".github/workflows/python.yml"
pull_request:
paths:
- "python/**"
- "src/**"
- "crates/**"
- "data/**"
- "build.rs"
- "Cargo.toml"
- "Cargo.lock"
- "doc/python.md"
- ".github/workflows/python.yml"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: python-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
crate:
name: Crate checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
workspaces: python
- name: Check formatting
run: cargo fmt --manifest-path python/Cargo.toml --all -- --check
- name: Check lints
run: cargo clippy --manifest-path python/Cargo.toml --all-targets -- -D warnings
- name: Rust unit tests
run: cargo test --manifest-path python/Cargo.toml
msrv:
name: MSRV (Rust 1.85)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: dtolnay/rust-toolchain@1.85
- name: Check
# Resolve dependencies to versions that support the declared MSRV.
env:
CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS: fallback
run: cargo check --manifest-path python/Cargo.toml
test:
name: pytest (CPython ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ["3.10", "3.13"]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
. -> target
python -> target
- name: Install build and test tools
run: python -m pip install "maturin>=1.9.4,<2" pytest
- name: Build and install the wheel
working-directory: python
run: |
maturin build --release --out dist
python -m pip install dist/*.whl
# The parity tests compare the Python results with the CLI's JSON.
- name: Build the CLI
run: cargo build --locked --release --bin polytool
- name: Run pytest
working-directory: python
env:
POLYTOOL_CLI: ${{ github.workspace }}/target/release/polytool
run: python -m pytest -p no:cacheprovider tests
wheels:
name: Wheel (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build the abi3 wheel
uses: PyO3/maturin-action@v1
with:
working-directory: python
args: --release --out dist
manylinux: auto
- name: Smoke test
shell: bash
run: |
python -m pip install python/dist/*.whl
python -c "import polytool; assert polytool.is_real_rooted([1, 11, 11, 1]); assert polytool.oeis.generate('A008292', 4)[3] == [1, 11, 11, 1]"
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}
path: python/dist/*.whl
sdist:
name: Source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Build the sdist
uses: PyO3/maturin-action@v1
with:
working-directory: python
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: python/dist/*.tar.gz
# Disabled unless the repository owner opts in: it needs the repository
# variable PYPI_PUBLISHING_ENABLED=true, a `pypi` environment with required
# reviewers, and a PyPI trusted publisher for this workflow. It runs only
# for a `python-v*` tag, after every other job has passed.
publish:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/python-v') && vars.PYPI_PUBLISHING_ENABLED == 'true'
needs: [crate, msrv, test, wheels, sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist