-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
116 lines (95 loc) · 3.06 KB
/
Makefile
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
# Optional target to test/benchmark.
TARGET ?=
TARPAULIN_INSTALLED := $(shell command -v cargo-tarpaulin > /dev/null && echo 1 || echo 0)
.ONESHELL:
.PHONY: venv setup install install-release build-extension-debug build-extension-release watch-extension watch-extension-release pcc test test-rust test-python bench pybench doc dist clean check-clean-git check-tarpaulin test-rust-cov
.SILENT:
# Create a fresh virtual environment with the latest pip.
venv:
rm -rf .venv
python -m venv .venv
source .venv/bin/activate
pip install -U pip
# Setup the active virtual environment for development.
setup:
pip install -e .[test]
pre-commit install
cargo install --force cargo-watch
cargo install --force cargo-run-script
# Build the latest changes in the rust bindings and install it to the active environment.
install:
pip install -e .
# Build the latest changes in the rust bindings in release mode and install it to the active environment.
install-release:
pip install .
# Build only the Rust Python extension (in debug mode)
build-extension-debug:
python setup.py build_rust --inplace --debug
# Build only the Rust Python extension (in release mode)
build-extension-release:
python setup.py build_rust --inplace --release
# Watches changes in the rust bindings and updates the python extension in place.
watch-extension:
cargo watch -x 'run-script build-python-extension' -w src -w Cargo.toml
# Watches changes in the rust bindings in release mode and updates the python extension in place.
watch-extension-release:
cargo watch -x 'run-script build-python-extension-release' -w src -w Cargo.toml
# Run pre-commit checks.
pcc:
pre-commit run --all-files
test: test-python test-rust
# Run rust tests.
test-rust:
cargo test "$(TARGET)"
# Run python tests.
test-python: build-extension-debug
pytest -svv tests -k "$(TARGET)" \
--cov=outlines_core \
--cov-report=term-missing:skip-covered
# Check if tarpaulin needs to be installed first.
check-tarpaulin:
ifeq ($(TARPAULIN_INSTALLED), 0)
@echo "cargo-tarpaulin is not found, installing..."
cargo install cargo-tarpaulin
else
@echo "cargo-tarpaulin is already installed"
endif
# Run rust tests with coverage report.
test-rust-cov: check-tarpaulin
RUSTFLAGS="-C instrument-coverage" cargo tarpaulin \
--out=Lcov \
--output-dir=rust-coverage \
--engine=llvm \
--exclude-files=src/python_bindings/* \
--no-dead-code \
--workspace \
--verbose
# Run rust benchmarks.
bench:
ifeq ($(TARGET),)
cargo bench
else
cargo bench -- $(TARGET)
endif
# Run python benchmarks.
pybench: check-clean-git
ifeq ($(TARGET),)
asv run --config benchmarks/asv.conf.json
else
asv run --config benchmarks/asv.conf.json -b "$(TARGET)"
endif
# Build the documentation of the rust crate and open it.
doc:
cargo doc --document-private-items --open
# Create wheels for distribution.
dist:
pip install build
python -m build
# Clean build and distribution files.
clean:
cargo clean
rm -rf dist
# Make sure that git diff is clean.
check-clean-git:
git diff-index --quiet HEAD \
|| (echo "Unable to perform the action due to uncommited local changes." && exit 1)