Skip to content

Commit d89e8fc

Browse files
raphaelstyclaude
andcommitted
Add pre-commit hook and bump version to 0.1.2
- Add pre-commit hook that runs all CI checks (fmt, clippy, test, doc, bench) - Add scripts/install-hooks.sh for easy hook installation - Add `make install-hooks` target - Fix formatting in examples/basic.rs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1e1eeda commit d89e8fc

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastkmeans-rs"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
description = "A fast and efficient k-means clustering implementation in Rust, compatible with ndarray"
66
license = "Apache-2.0"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build test lint fmt check clean bench doc example
1+
.PHONY: all build test lint fmt check clean bench doc example install-hooks
22

33
all: fmt lint test
44

@@ -64,3 +64,7 @@ example:
6464
# Run all CI checks locally
6565
ci: fmt-check clippy test doc bench-check
6666
@echo "All CI checks passed!"
67+
68+
# Install git hooks
69+
install-hooks:
70+
./scripts/install-hooks.sh

examples/basic.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ fn main() {
1515
let n_features = 2;
1616
let n_clusters = 3;
1717

18-
println!("Generating {} samples with {} features...", n_samples, n_features);
18+
println!(
19+
"Generating {} samples with {} features...",
20+
n_samples, n_features
21+
);
1922

2023
// Create clustered data by generating points around 3 centers
2124
let mut data = Array2::<f32>::zeros((n_samples, n_features));
@@ -77,7 +80,12 @@ fn main() {
7780

7881
println!("Cluster distribution:");
7982
for (i, count) in cluster_counts.iter().enumerate() {
80-
println!(" Cluster {}: {} samples ({:.1}%)", i, count, (*count as f64 / n_samples as f64) * 100.0);
83+
println!(
84+
" Cluster {}: {} samples ({:.1}%)",
85+
i,
86+
count,
87+
(*count as f64 / n_samples as f64) * 100.0
88+
);
8189
}
8290
println!();
8391

scripts/install-hooks.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
#
3+
# Install git hooks for the repository
4+
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9+
HOOKS_DIR="$REPO_ROOT/.git/hooks"
10+
11+
echo "Installing git hooks..."
12+
13+
# Install pre-commit hook
14+
cp "$SCRIPT_DIR/pre-commit" "$HOOKS_DIR/pre-commit"
15+
chmod +x "$HOOKS_DIR/pre-commit"
16+
17+
echo "Git hooks installed successfully!"

scripts/pre-commit

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
#
3+
# Pre-commit hook that runs the same checks as CI
4+
# To skip this hook, use: git commit --no-verify
5+
6+
set -e
7+
8+
echo "Running pre-commit checks..."
9+
10+
# Check formatting
11+
echo "Checking formatting..."
12+
cargo fmt --all -- --check
13+
14+
# Run clippy
15+
echo "Running clippy..."
16+
cargo clippy --all-targets --all-features -- -D warnings
17+
18+
# Run tests
19+
echo "Running tests..."
20+
cargo test
21+
22+
# Build documentation (with warnings as errors)
23+
echo "Building documentation..."
24+
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
25+
26+
# Compile benchmarks (without running)
27+
echo "Checking benchmarks compile..."
28+
cargo bench --no-run
29+
30+
echo "All pre-commit checks passed!"

0 commit comments

Comments
 (0)