Update install hooks to respect XYZ_BINARY env vars

- All install hooks now respect their respective XYZ_BINARY env vars
  (e.g., WGET_BINARY, CHROME_BINARY, YTDLP_BINARY, etc.)
- Support both absolute paths (/usr/bin/wget2) and binary names (wget2)
- Dynamic bin_name used in Dependency JSONL output
- Updated 11 install hooks to follow the new pattern
- Mark checklist items as complete in TODO_hook_architecture.md
This commit is contained in:
Claude
2025-12-27 10:12:45 +00:00
parent 8c846b7d1c
commit e3ba599812
12 changed files with 339 additions and 85 deletions

View File

@@ -1,26 +1,39 @@
#!/usr/bin/env python3
"""
Validation hook for ripgrep binary.
Install hook for ripgrep binary.
Only runs if SEARCH_BACKEND_ENGINE is set to 'ripgrep'.
Outputs JSONL for InstalledBinary and Machine config updates.
Respects RIPGREP_BINARY env var for custom binary paths.
"""
import os
import sys
import json
from pathlib import Path
def find_ripgrep() -> dict | None:
"""Find ripgrep binary."""
"""Find ripgrep binary, respecting RIPGREP_BINARY env var."""
try:
from abx_pkg import Binary, AptProvider, BrewProvider, EnvProvider
binary = Binary(name='rg', binproviders=[AptProvider(), BrewProvider(), EnvProvider()])
# Check if user has configured a custom binary
configured_binary = os.environ.get('RIPGREP_BINARY', '').strip()
if configured_binary:
if '/' in configured_binary:
bin_name = Path(configured_binary).name
else:
bin_name = configured_binary
else:
bin_name = 'rg'
binary = Binary(name=bin_name, binproviders=[AptProvider(), BrewProvider(), EnvProvider()])
loaded = binary.load()
if loaded and loaded.abspath:
return {
'name': 'rg',
'name': bin_name,
'abspath': str(loaded.abspath),
'version': str(loaded.version) if loaded.version else None,
'sha256': loaded.sha256 if hasattr(loaded, 'sha256') else None,
@@ -33,7 +46,7 @@ def find_ripgrep() -> dict | None:
def main():
"""Validate ripgrep binary and output JSONL."""
"""Find ripgrep binary and output JSONL."""
# Check if ripgrep search backend is enabled
search_backend = os.environ.get('SEARCH_BACKEND_ENGINE', '').lower()
@@ -42,6 +55,15 @@ def main():
# No-op: ripgrep is not the active search backend
sys.exit(0)
# Determine binary name from config
configured_binary = os.environ.get('RIPGREP_BINARY', '').strip()
if configured_binary and '/' in configured_binary:
bin_name = Path(configured_binary).name
elif configured_binary:
bin_name = configured_binary
else:
bin_name = 'rg'
result = find_ripgrep()
if result and result.get('abspath'):
@@ -76,12 +98,12 @@ def main():
# Output Dependency request
print(json.dumps({
'type': 'Dependency',
'bin_name': 'rg',
'bin_name': bin_name,
'bin_providers': 'apt,brew,cargo,env',
}))
# Exit non-zero to indicate binary not found
print(f"ripgrep binary not found", file=sys.stderr)
print(f"{bin_name} binary not found", file=sys.stderr)
sys.exit(1)