Skip to content

Commit 18e6863

Browse files
committed
Port example from peotry to tox to simplify dependency management
1 parent 8b7ce5c commit 18e6863

File tree

6 files changed

+60
-53
lines changed

6 files changed

+60
-53
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
toolchain: stable
1818
profile: minimal
1919
components: rustfmt, clippy
20+
default: true
2021
- uses: Swatinem/rust-cache@v1
2122
continue-on-error: true
2223
- env:
@@ -41,7 +42,7 @@ jobs:
4142
{ os: "windows-latest", python-architecture: "x86", rust-target: "i686-pc-windows-msvc" },
4243
]
4344
include:
44-
# PyPy and NumPy on macOS and Windows is too slow and brittle
45+
# NumPy does not provide pre-built wheels for PyPy on macOS and Windows
4546
- python-version: pypy-3.7
4647
platform: { os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" }
4748
- python-version: pypy-3.8
@@ -60,30 +61,36 @@ jobs:
6061
profile: minimal
6162
target: ${{ matrix.platform.rust-target }}
6263
default: true
63-
- name: Enable Cargo resolver v2 to avoid PyO3 features missing in PyPy
64-
run: echo 'resolver = "2"' >> Cargo.toml
64+
- name: Install toml
65+
run: pip install toml
66+
- name: Edit Cargo.toml and enable new resolver
67+
run: |
68+
import toml
69+
cargo_toml = toml.load("Cargo.toml")
70+
cargo_toml["workspace"]["resolver"] = "2"
71+
with open("Cargo.toml", "w") as f:
72+
toml.dump(cargo_toml, f)
73+
shell: python
6574
- name: Build without default features
6675
run: cargo build --no-default-features
6776
- name: Build with default features
6877
run: cargo build
69-
- name: Run cargo test
78+
- name: Test
7079
run: |
7180
pip install numpy
7281
cargo test
7382
# Not on PyPy, because no embedding API
7483
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
75-
- name: Install poetry
76-
run: pip install poetry
7784
- name: Test example
7885
run: |
79-
poetry install
80-
poetry run maturin develop
81-
poetry run pytest
86+
pip install tox
87+
tox
8288
working-directory: examples/simple-extension
8389
env:
8490
CARGO_TERM_VERBOSE: true
8591
CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }}
8692
RUST_BACKTRACE: 1
93+
TOX_TESTENV_PASSENV: CARGO_BUILD_TARGET
8794

8895
check-msrv:
8996
runs-on: ubuntu-latest
@@ -93,18 +100,18 @@ jobs:
93100
uses: actions/setup-python@v2
94101
with:
95102
python-version: 3.8
96-
- name: Install MSRV Rust
103+
- name: Install Rust
97104
uses: actions-rs/toolchain@v1
98105
with:
99-
profile: minimal
100106
toolchain: 1.48.0
107+
profile: minimal
101108
default: true
102109
- uses: Swatinem/rust-cache@v1
103110
with:
104111
working-directory: examples/simple-extension
105112
continue-on-error: true
106-
- name: Install toml and poetry
107-
run: pip install toml poetry
113+
- name: Install toml
114+
run: pip install toml
108115
- name: Edit Cargo.toml and detach from workspace
109116
run: |
110117
import toml
@@ -116,16 +123,24 @@ jobs:
116123
toml.dump(cargo_toml, f)
117124
working-directory: examples/simple-extension
118125
shell: python
119-
- name: Use ndarray 0.13.1
126+
- name: Generate lockfile
127+
run: cargo generate-lockfile
128+
working-directory: examples/simple-extension
129+
- name: Unify dependencies on ndarray to 0.13.1
120130
run: |
121-
cargo generate-lockfile
122-
cargo update -p $(cargo pkgid -p ndarray 2>&1 >/dev/null | grep 0.15 | sed -e 's/^[ \t]*//') --precise 0.13.1
131+
import toml
132+
import subprocess
133+
cargo_lock = toml.load("Cargo.lock")
134+
for pkg in cargo_lock["package"]:
135+
if pkg["name"] == "ndarray" and pkg["version"] != "0.13.1":
136+
pkg_id = pkg["name"] + ":" + pkg["version"]
137+
subprocess.run(["cargo", "update", "--package", pkg_id, "--precise", "0.13.1"], check=True)
123138
working-directory: examples/simple-extension
139+
shell: python
124140
- name: Test example
125141
run: |
126-
poetry install
127-
poetry run maturin develop
128-
poetry run pytest
142+
pip install tox
143+
tox
129144
working-directory: examples/simple-extension
130145

131146
linalg-example:
@@ -143,13 +158,12 @@ jobs:
143158
uses: actions-rs/toolchain@v1
144159
with:
145160
toolchain: stable
161+
profile: minimal
162+
default: true
146163
- uses: Swatinem/rust-cache@v1
147164
continue-on-error: true
148-
- name: Install poetry
149-
run: pip install poetry
150165
- name: Test example
151166
run: |
152-
poetry install
153-
poetry run maturin develop
154-
poetry run pytest
167+
pip install tox
168+
tox
155169
working-directory: examples/linalg

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ build/
1515
*.egg-info/
1616
**/dist/
1717
__pycache__
18-
poetry.lock

examples/linalg/pyproject.toml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
[build-system]
22
build-backend = "maturin"
33
requires = ["maturin>=0.12,<0.13"]
4-
5-
[tool.poetry]
6-
name = "numpy-linalg-example"
7-
version = "0.1.0"
8-
description = "rust-numpy example with ndarray-linalg"
9-
authors = ["Yuji Kanagawa <[email protected]>"]
10-
11-
[tool.poetry.dependencies]
12-
numpy = ">=1.18"
13-
python = ">=3.7,<3.11"
14-
15-
[tool.poetry.dev-dependencies]
16-
maturin = ">=0.12,<0.13"
17-
pytest = "^6.1"

examples/linalg/tox.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tox]
2+
skipsdist = True
3+
4+
[testenv]
5+
deps =
6+
pip
7+
numpy
8+
pytest
9+
commands =
10+
pip install .
11+
pytest {posargs}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
[build-system]
22
build-backend = "maturin"
33
requires = ["maturin>=0.12,<0.13"]
4-
5-
[tool.poetry]
6-
name = "numpy-example"
7-
version = "0.1.0"
8-
description = "A minimum example of rust-numpy"
9-
authors = ["Toshiki Teramura <[email protected]>", "Yuji Kanagawa <[email protected]>"]
10-
11-
[tool.poetry.dependencies]
12-
numpy = ">=1.18"
13-
python = ">=3.7,<3.11"
14-
15-
[tool.poetry.dev-dependencies]
16-
maturin = ">=0.12,<0.13"
17-
pytest = "^6.1"

examples/simple-extension/tox.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tox]
2+
skipsdist = True
3+
4+
[testenv]
5+
deps =
6+
pip
7+
numpy
8+
pytest
9+
commands =
10+
python -m pip install .
11+
pytest {posargs}

0 commit comments

Comments
 (0)