-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (154 loc) · 10 KB
/
Makefile
File metadata and controls
201 lines (154 loc) · 10 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# (C) Copyright 2026- ECMWF and individual contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
# Top-level Makefile dispatching builds and tests for all languages.
# Run `make help` to see available targets.
.PHONY: help all check test lint fmt docs clean \
rust-check rust-test rust-lint rust-fmt rust-clippy \
python-build python-dist python-dist-extras python-test python-lint python-fmt \
earthkit-install earthkit-test earthkit-lint \
cpp-build cpp-test \
wasm-test docs-build \
ts-install ts-build ts-test ts-typecheck \
remote-parity-rust-build remote-parity-ts-install remote-parity-fixtures \
remote-parity-build remote-parity remote-parity-clean
# ── Defaults ──────────────────────────────────────────────────────────────
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
all: check test lint ## Run all checks, tests, and lints
# ── Rust ──────────────────────────────────────────────────────────────────
rust-check: ## Check Rust workspace compiles
cargo check --workspace
rust-test: ## Run all Rust tests
cargo test --workspace
rust-clippy: ## Run clippy on Rust workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo clippy -p tensogram --all-targets --features "remote,async" -- -D warnings
rust-fmt: ## Check Rust formatting
cargo fmt --check
rust-lint: rust-clippy rust-fmt ## Run all Rust lints (clippy + fmt)
# ── Python ────────────────────────────────────────────────────────────────
PYTHON ?= uv run python
RUFF ?= uv run --with ruff ruff
# `--no-project` keeps `uv run` from discovering python/bindings/pyproject.toml
# and trying to install `tensogram` (incl. its `[all]` extras) before maturin
# even starts. Without it, every minor-version release fails at wheel build
# time because the new sibling extras (tensogram-xarray / tensogram-zarr at
# the new minor) don't exist on PyPI yet — the publish flow itself is what
# uploads them. maturin still reads pyproject.toml directly for the build.
MATURIN ?= uv run --no-project --with maturin maturin
RUFF_CFG ?= python/bindings/pyproject.toml
# Space-separated --interpreter flags passed to maturin build; defaults to
# auto-discovery. Override in CI: MATURIN_INTERP_ARGS="--interpreter /path/to/py"
MATURIN_INTERP_ARGS ?= --find-interpreter
# Optional maturin --compatibility target (e.g. manylinux_2_28).
# Passed as --compatibility <value> when non-empty.
MATURIN_COMPAT ?=
MATURIN_COMPAT_ARG = $(if $(MATURIN_COMPAT),--compatibility $(MATURIN_COMPAT))
python-build: ## Build Python bindings via maturin (dev install into .venv)
if [ ! -d .venv ] ; then uv venv ; fi
cd python/bindings && $(MATURIN) develop --release --uv
uv pip install ./python/tensogram-xarray
uv pip install ./python/tensogram-zarr
python-dist: ## Build tensogram distributable wheels for the current platform
if [ ! -d .venv ] ; then uv venv ; fi
cd python/bindings && $(MATURIN) build --release --out dist $(MATURIN_INTERP_ARGS) $(MATURIN_COMPAT_ARG)
python-dist-extras: ## Build distributable wheels for pure-Python extra packages
uv build python/tensogram-xarray --out-dir dist/extras
uv build python/tensogram-zarr --out-dir dist/extras
uv build python/tensogram-anemoi --out-dir dist/extras
python-test: python-build ## Run all Python tests
# TODO pip installs should come from workspace-level pyproject
uv pip install pytest pytest-asyncio numpy
$(PYTHON) -m pytest python/tests/ -v
$(PYTHON) -m pytest python/tensogram-xarray/tests/ -v
$(PYTHON) -m pytest python/tensogram-zarr/tests/ -v
python-lint: ## Run ruff check on Python code
$(RUFF) check --config $(RUFF_CFG) python/tests/ python/tensogram-xarray/ python/tensogram-zarr/
python-fmt: ## Check Python formatting
$(RUFF) format --check --config $(RUFF_CFG) python/tests/ python/tensogram-xarray/ python/tensogram-zarr/
# ── earthkit-data integration ────────────────────────────────────────────
earthkit-install: ## Install the earthkit-data integration package (editable, with dev extras)
if [ ! -d .venv ] ; then uv venv ; fi
uv pip install earthkit-data earthkit-utils
uv pip install -e python/tensogram-xarray/
uv pip install -e "python/tensogram-earthkit/[dev]"
earthkit-test: earthkit-install ## Run tensogram-earthkit tests
$(PYTHON) -m pytest python/tensogram-earthkit/tests/ -v
earthkit-lint: ## Run ruff on the tensogram-earthkit package
$(RUFF) check python/tensogram-earthkit/
$(RUFF) format --check python/tensogram-earthkit/
# ── C++ ───────────────────────────────────────────────────────────────────
cpp-build: ## Build C++ tests via CMake
cmake -S cpp -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
cpp-test: cpp-build ## Run C++ tests
cd build && ctest --output-on-failure
# ── WASM ──────────────────────────────────────────────────────────────────
wasm-test: ## Run WASM tests
wasm-pack test --node rust/tensogram-wasm
# ── TypeScript ────────────────────────────────────────────────────────────
ts-install: ## Install TypeScript wrapper dependencies
cd typescript && npm ci || npm install --no-audit --no-fund
ts-build: ts-install ## Build the TypeScript wrapper (wasm-pack + tsc)
cd typescript && npm run build
ts-test: ts-build ## Run TypeScript wrapper tests (vitest)
cd typescript && npm test
ts-typecheck: ts-build ## Strict typecheck source + tests
cd typescript && npx tsc --noEmit -p tsconfig.test.json
# ── Docs ──────────────────────────────────────────────────────────────────
docs-build: ## Build mdbook documentation
mdbook build docs/
# ── Remote parity harness ─────────────────────────────────────────────────
#
# Cross-language HTTP parity test infra under `tests/remote-parity/`.
# Drives Rust `TensogramFile::open_remote` and TS `TensogramFile.fromUrl`
# against a Python mock server and diffs the request sequences. Not
# folded into `make test` because it needs the TS WASM build, an extra
# `npm install`, and a Rust release binary built outside the main
# workspace.
_PARITY_DIR = tests/remote-parity
_PARITY_RUST_MANIFEST = $(_PARITY_DIR)/drivers/rust_driver/Cargo.toml
_PARITY_DRIVERS_DIR = $(_PARITY_DIR)/drivers
# The Rust driver is its own cargo project (empty `[workspace]`) so it
# must be built explicitly — `cargo build --workspace` won't see it.
remote-parity-rust-build: ## Build the parity-harness Rust driver (isolated cargo project)
cargo build --release --manifest-path $(_PARITY_RUST_MANIFEST)
remote-parity-ts-install: ts-build ## Install parity-harness TS driver deps (uses npm ci)
cd $(_PARITY_DRIVERS_DIR) && npm ci || npm install --no-audit --no-fund
# Fixtures are committed binary artefacts — regenerating produces
# different bytes (encoder stamps fresh timestamp + UUID). The pytest
# suite computes expected offsets live from the fixture, so it
# survives intentional regenerations. Run only on intentional changes.
remote-parity-fixtures: python-build ## (Re)generate .tgm fixtures — commit the diff after review
$(PYTHON) $(_PARITY_DIR)/tools/gen_fixtures.py
remote-parity-build: remote-parity-rust-build remote-parity-ts-install python-build ## Build every parity-harness driver
@echo "parity harness drivers ready"
remote-parity: remote-parity-build ## Run the full parity harness (rebuilds drivers + pytest)
uv pip install pytest numpy
$(PYTHON) -m pytest $(_PARITY_DIR)/ -v
remote-parity-clean: ## Remove parity-harness build artefacts (keeps fixtures)
rm -rf $(_PARITY_DIR)/drivers/rust_driver/target/
rm -rf $(_PARITY_DRIVERS_DIR)/node_modules/
find $(_PARITY_DIR) -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
# ── Aggregates ────────────────────────────────────────────────────────────
check: rust-check ## Check all builds
test: rust-test python-test ts-test ## Run all tests
lint: rust-lint python-lint python-fmt ts-typecheck ## Run all lints
fmt: rust-fmt python-fmt ## Check all formatting
# ── Cleanup ───────────────────────────────────────────────────────────────
clean: remote-parity-clean ## Remove build artifacts (delegates parity-harness cleanup to remote-parity-clean)
cargo clean
rm -rf build/
rm -rf .venv/
rm -rf docs/book/
rm -rf python/bindings/target/
find python/bindings/python -name '*.so' -o -name '*.pyd' | xargs rm -f 2>/dev/null || true
rm -rf typescript/dist/ typescript/wasm/ typescript/node_modules/
rm -rf examples/typescript/node_modules/
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true