Skip to content

Commit

Permalink
chore(dev): add maturin import hook (#191)
Browse files Browse the repository at this point in the history
* chore(dev): add maturin import hook

* update just and justfiles

* fix justfile
  • Loading branch information
jeertmans authored Dec 18, 2024
1 parent 5b9879a commit 2ce29b9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 47 deletions.
10 changes: 5 additions & 5 deletions docs/justfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Default command (list all commands)
default:
@just --list
@just --list

# Clean build artifacts
clean: clean-autosummary
rm -rf build
rm -rf build

# Clean autosummary build artifacts.
clean-autosummary:
rm -f source/reference/_autosummary/*.rst
rm -f source/reference/_autosummary/*.rst

# Build docs
build builder="html" *OPTIONS="-W --keep-going":
uv run sphinx-build -M {{builder}} source build {{OPTIONS}}
uv run --extra docs sphinx-build -M {{ builder }} source build {{ OPTIONS }}

# Build docs in "draft" mode
draft *ARGS:
NB_OFF="1" just build {{ARGS}}
NB_OFF="1" just build {{ ARGS }}

# Check links
linkcheck *ARGS: (draft "linkcheck" ARGS)
Expand Down
5 changes: 2 additions & 3 deletions docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ To run build this package locally, you need:

- [Rust](https://www.rust-lang.org/) stable toolchain;
- any modern C compiler;
- [just](https://github.com/casey/just) to easily run commands listed in `justfile`s;
- [Maturin](https://www.maturin.rs/) for building Python bindings from Rust code;
- and [uv](https://docs.astral.sh/uv/) to manage this project.
- [just>=1.38.0](https://github.com/casey/just) to easily run commands listed in `justfile`s;
- and [uv>= 0.4.25](https://docs.astral.sh/uv/) to manage this project.

This project contains `justfile`s with recipes[^2] for most common
use cases, so feel free to use them instead of the commands listed below/
Expand Down
94 changes: 55 additions & 39 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,91 +1,107 @@
# This doesn't do anything, but is a placeholder for a future feature
# see: https://github.com/casey/just/issues/2290
# set min-just-version := '1.38.0'

# Default command (list all commands)
default:
@just --list
@just --list

# Benchmark code
[group: 'test']
[group('test')]
bench: bench-python bench-rust

# Benchmark Python code
[group: 'python']
[group: 'test']
[group('python')]
[group('test')]
bench-python *ARGS:
uv run pytest -n0 --benchmark-enable --benchmark-only {{ARGS}}
uv run --extra tests pytest -n0 --benchmark-enable --benchmark-only {{ ARGS }}

# Benchmark Rust code
[group: 'rust']
[group: 'test']
[group('rust')]
[group('test')]
bench-rust *ARGS:
cargo bench {{ARGS}}
cargo bench {{ ARGS }}

# Build Python package(s)
[group: 'dev']
[group('dev')]
build *ARGS:
uv build {{ARGS}}
uv build {{ ARGS }}

# Bump packages version
[group: 'dev']
[group('dev')]
bump +ARGS="patch":
uv run bump-my-version {{ARGS}}
uv run bump-my-version {{ ARGS }}

# Check the code can compile
[group: 'rust']
[group: 'test']
[group('rust')]
[group('test')]
check:
cargo check
cargo check

# Clean build artifacts
[group: 'dev']
[group('dev')]
clean:
cargo clean
rm -rf dist
cargo clean
rm -rf dist

# Force reloading CUDA after suspend, see: https://github.com/ami-iit/jaxsim/issues/50#issuecomment-2022483137
[group: 'dev']
[group('dev')]
cuda-reload:
sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm
sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm

# List JAX's devices
[group: 'python']
[group: 'test']
[group('python')]
[group('test')]
devices:
uv run python -c "import jax;print(jax.devices())"
uv run python -c "import jax;print(jax.devices())"

# Install marutin import hook to automatically build differt_core
[group('dev')]
[working-directory('differt-core')]
hook-install:
uv run python -m maturin_import_hook site install --detect-uv

# Uninstall marutin import hook
[group('dev')]
[working-directory('differt-core')]
hook-uninstall:
uv run python -m maturin_import_hook site uninstall

# Build and install Python packages
[group: 'dev']
[group('dev')]
install *ARGS:
uv sync {{ARGS}}
uv sync {{ ARGS }}

# Build and install Python package(s) using 'profiling' profile
[group: 'dev']
[group('dev')]
install-profiling *ARGS:
uv sync --config-settings=build-args='--profile profiling' --reinstall-package differt_core {{ARGS}}
uv sync --config-settings=build-args='--profile profiling' --reinstall-package differt_core {{ ARGS }}

# Run code linters and formatters
[group: 'dev']
[group('dev')]
lint:
uv run pre-commit run --all-files
uv run pre-commit run --all-files

alias fmt := lint

# Test code
[group: 'test']
[group('test')]
test: test-python test-rust

# Test Python code
[group: 'python']
[group: 'test']
[group('python')]
[group('test')]
test-python *ARGS:
uv run pytest {{ARGS}}
uv run --extra tests pytest {{ ARGS }}

# Test Rust code
[group: 'rust']
[group: 'test']
[group('rust')]
[group('test')]
test-rust *ARGS:
cargo test {{ARGS}}
cargo test {{ ARGS }}

# Run jupyter-lab with a server that supports reconnecting to running sessions
[group: 'dev']
[group('dev')]
remote-jupyter *ARGS:
jupyverse --set kernels.require_yjs=true --set jupyterlab.server_side_execution=true --set auth.mode=noauth {{ARGS}}
uv run --extra remote-jupyter jupyverse --set kernels.require_yjs=true --set jupyterlab.server_side_execution=true --set auth.mode=noauth {{ ARGS }}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ convention = "google"
dev-dependencies = [
"differt_dev[docs,tests]",
"bump-my-version>=0.20.3",
"maturin-import-hook>=0.2.0",
"pre-commit>=3.5.0",
]

Expand Down
Loading

0 comments on commit 2ce29b9

Please sign in to comment.