Skip to content

Commit 6479ce4

Browse files
committed
Big CI Updates
1 parent 078b91d commit 6479ce4

File tree

6 files changed

+107
-51
lines changed

6 files changed

+107
-51
lines changed

.github/workflows/CI.yml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
1-
# This file is autogenerated by maturin v0.14.15
2-
# To update, run
3-
#
4-
# maturin new test
5-
#
61
on:
72
push:
83
branches:
9-
- main
10-
- master
4+
- development
115
tags:
12-
- '*'
13-
pull_request:
14-
workflow_dispatch:
15-
6+
- '**'
7+
pull_request: {}
8+
169
permissions:
1710
contents: read
1811

1912
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: install rust stable
20+
uses: dtolnay/rust-toolchain@stable
21+
with:
22+
components: rustfmt, clippy
23+
24+
- name: cache rust
25+
uses: Swatinem/rust-cache@v2
26+
27+
- uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.11'
30+
31+
- uses: actions/cache@v3
32+
id: cache-py
33+
name: cache python
34+
with:
35+
path: ${{ env.pythonLocation }}
36+
key: >
37+
py
38+
${{ env.pythonLocation }}
39+
${{ hashFiles('tests/requirements-linting.txt') }}
40+
${{ hashFiles('pyproject.toml') }}
41+
42+
- run: pip install -r tests/requirements-linting.txt
43+
if: steps.cache-py.outputs.cache-hit != 'true'
44+
45+
- run: pip install .
46+
if: steps.cache-py.outputs.cache-hit != 'true'
47+
48+
- run: pip freeze
49+
50+
- run: make lint
51+
2052
linux:
2153
runs-on: ubuntu-latest
2254
strategy:
@@ -115,4 +147,4 @@ jobs:
115147
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
116148
with:
117149
command: upload
118-
args: --skip-existing *
150+
args: --skip-existing *

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ docs/_build/
6969
.vscode/
7070

7171
# Pyenv
72-
.python-version
72+
.python-version
73+
74+
# Ruff
75+
.ruff_cache

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: lint-python
2+
lint-python:
3+
$(ruff) python
4+
$(black) --check --diff python
5+
6+
.PHONY: lint-rust
7+
lint-rust:
8+
cargo fmt --version
9+
cargo fmt --all -- --check
10+
cargo clippy --version
11+
cargo clippy -- -D warnings -W clippy::dbg_macro -W clippy::print_stdout
12+
13+
.PHONY: lint
14+
lint: lint-python lint-rust

README.md

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,47 @@
11

22
# arcade-accelerate
33

4-
An experimental library for accelerating arcade using rust. The module can
5-
be imported and monkey patch arcade replacing functions and types with rust
6-
versions.
4+
An experimental library for accelerating [Arcade](https://github.com/pythonarcade/arcade) using Rust. The module can
5+
be imported and monkey patch Arcade, replacing functions and types with rust versions.
76

87
```py
98
import arcade_accelerate
109
arcade_accelerate.bootstrap()
11-
```
12-
13-
## Build / Setup
1410

15-
* Install maturin
16-
* `pip install maturin`
17-
* (Package crated with 0.14.15)
18-
* Install the arcade version you are comparing with
19-
* Preferably install from source in editable mode
11+
import arcade
12+
```
2013

21-
Install the create as module in the current virtualenv
14+
It is important to run the arcade-accelerate bootstrapping process before importing Arcade, otherwise the monkey-patched versions will not be fully applied.
2215

23-
```sh
24-
# debug
25-
maturin develop
26-
# release
27-
maturin develop --release
28-
```
16+
## Build / Setup
2917

30-
Build python package for release
18+
First create and activate a Python virtual environment, then install maturin:
3119

3220
```bash
33-
# wheel
34-
maturin build -i python --release
35-
# sdist
36-
maturin build -i python --release --sdist
21+
pip install maturin
3722
```
3823

39-
When performance testing always use the release build.
24+
Install the crate as module in the current virtual environment using Maturin. Generally
25+
when working on performance enhancements you will want to use the `--release` flag.
4026

41-
## Info
42-
43-
This project has a python module and a rust module.
27+
```sh
28+
# Debug
29+
maturin develop
4430

45-
* `arcade_accelerate` - python module
46-
* `arcade_accelerate_rust` - rust module
31+
# Release
32+
maturin develop --release
33+
```
4734

48-
The python module just contains some helper functions to bootstrap the
49-
acceleration.
35+
Then you can install [Arcade](https://github.com/pythonarcade/arcade) into the same virtual environment
36+
and run any of it's examples. Optimally testing should be done against the `development` branch of Arcade.
37+
In order to enable `arcade-accelerate` add these two lines anytime before importing `arcade`. It is important that
38+
the bootstrap is done prior to importing Arcade, otherwise the monkey-patched functions/classes will not fully apply.
5039

51-
The `tests` directory contains some performance tests.
40+
```py
41+
import arcade_accelerate
42+
arcade_accelerate.bootstrap()
5243

53-
# Resources
44+
import arcade
45+
```
5446

55-
* [pyo3 user guide](https://pyo3.rs)
56-
* [maturin user guide](https://www.maturin.rs/)
47+
If you would like to run Arcade's test suite with arcade-accelerate enabled, you can do so by setting the `ARCADE_PYTEST_USE_RUST` environment variable before running pytest on Arcade. You just need to ensure that both Arcade and arcade-accelerate are installed in the same environment.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ classifiers = [
1111
"Programming Language :: Python :: Implementation :: PyPy",
1212
]
1313

14+
[project.optional-dependencies]
15+
dev = [
16+
"ruff",
17+
"black",
18+
]
19+
1420
[tool.maturin]
1521
python-source = "python"
1622
features = ["pyo3/extension-module"]

python/arcade_accelerate/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ def bootstrap():
1111
patch_hitboxes()
1212
patch_spritelist_collision()
1313

14-
exclude = ["arcade.hitbox.base", "arcade.math", "arcade.geometry", "arcade.sprite_list.collision"]
14+
exclude = [
15+
"arcade.hitbox.base",
16+
"arcade.math",
17+
"arcade.geometry",
18+
"arcade.sprite_list.collision",
19+
]
1520

1621
pkgs = []
1722
for mod in exclude:
@@ -42,8 +47,13 @@ def patch_hitboxes():
4247

4348

4449
def patch_spritelist_collision():
45-
arcade.sprite_list.collision.check_for_collision_with_list = arcade_accelerate.check_for_collision_with_list
46-
arcade.sprite_list.collision.check_for_collision_with_lists = arcade_accelerate.check_for_collision_with_lists
50+
arcade.sprite_list.collision.check_for_collision_with_list = (
51+
arcade_accelerate.check_for_collision_with_list
52+
)
53+
arcade.sprite_list.collision.check_for_collision_with_lists = (
54+
arcade_accelerate.check_for_collision_with_lists
55+
)
56+
4757

4858
def patch_math():
4959
arcade.math.rotate_point = arcade_accelerate.rotate_point

0 commit comments

Comments
 (0)