Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions scripts/make/install_pre_commit_hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@

set -euo pipefail

# Install pre-commit hooks and their non-uv-managed dependencies.
# Install pre-commit hooks.
# Idempotent — safe to call from setup_env.sh, make check, or manually.
#
# Requires: an activated venv with pre-commit installed (via uv sync).

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

# Project root (the outermost pyproject.toml ancestor) must be passed as $1.
# setup_env.sh computes it via its repo_root() helper. The internal layout has
# a nested external/pyproject.toml so $REPO_ROOT (above) isn't sufficient on its
# own, and the OSS export tree (.oss-export/coreai-opt/) is itself a project
# root that must NOT install hooks into the parent worktree's .git.
# Project root (outermost pyproject.toml ancestor), computed by setup_env.sh's repo_root().
PROJECT_ROOT="${1:-}"
if [[ -z "$PROJECT_ROOT" ]]; then
echo "Usage: $0 <project-root>" >&2
Expand All @@ -35,30 +28,6 @@ if [[ ! -e "$PROJECT_ROOT/.git" ]]; then
exit 0
fi

# shellcheck source=../utils.sh
source "$REPO_ROOT/scripts/utils.sh"
# shellcheck source=../run_quietly.sh
source "$REPO_ROOT/scripts/run_quietly.sh"

# Install lychee link checker.
# Prefer the OS package manager (brew on macOS, dnf/apt on Linux).
# Fall back to cargo build for distros that don't package lychee (e.g., RHEL).
echo "Installing non-uv-managed pre-commit hook dependencies..."
if ! run_quietly ensure_package "lychee"; then
echo "Package manager install failed. Falling back to cargo install..."
if run_quietly ensure_package "cargo" && run_quietly cargo install lychee --locked; then
# cargo install puts binaries in ~/.cargo/bin, which may not be on PATH.
export PATH="$HOME/.cargo/bin:$PATH"
echo "lychee installed via cargo: $(lychee --version 2>&1 | head -n1)"
fi
fi

if ! command -v lychee &>/dev/null; then
echo "Error: Could not install lychee via package manager or cargo."
echo " Install lychee manually: https://lychee.cli.rs/"
exit 1
fi

# Configure git hooks. Force-install so the shebang points to the current venv.
if [[ "${INSTALL_PRECOMMIT:-true}" == "false" ]]; then
echo "Skipping git hook configuration (INSTALL_PRECOMMIT=$INSTALL_PRECOMMIT)"
Expand Down
2 changes: 1 addition & 1 deletion scripts/make/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ echo "Running: ${SYNC_CMD[*]}"
apply_post_install_pip_args

echo ""
echo "[3/3] Installing hook dependencies and configuring pre-commit hooks..."
echo "[3/3] Configuring pre-commit hooks..."
if [[ "$VENV_PREEXISTED" == "true" ]]; then
echo "Skipped (venv already exists, hooks already configured)"
else
Expand Down
Loading