| 1 |
#!/bin/bash |
| 2 |
# Fenrir Validation Setup Script |
| 3 |
# |
| 4 |
# Sets up the validation tools and pre-commit hooks for Fenrir development. |
| 5 |
# Run this once after cloning the repository. |
| 6 |
|
| 7 |
set -e |
| 8 |
|
| 9 |
# Colors for output |
| 10 |
GREEN='\033[0;32m' |
| 11 |
YELLOW='\033[1;33m' |
| 12 |
RED='\033[0;31m' |
| 13 |
NC='\033[0m' # No Color |
| 14 |
|
| 15 |
echo -e "${GREEN}Fenrir Development Environment Setup${NC}" |
| 16 |
echo "======================================" |
| 17 |
|
| 18 |
# Check we're in the right directory |
| 19 |
if [ ! -f "CLAUDE.md" ] || [ ! -d "src/fenrirscreenreader" ]; then |
| 20 |
echo -e "${RED}Error: Must be run from Fenrir project root directory${NC}" |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
|
| 24 |
# Make validation scripts executable |
| 25 |
echo -e "\n${YELLOW}1. Making validation scripts executable...${NC}" |
| 26 |
chmod +x tools/validate_syntax.py |
| 27 |
chmod +x tools/validate_pep8.py |
| 28 |
chmod +x tools/validate_release.py |
| 29 |
chmod +x tools/cleanup_cache.py |
| 30 |
chmod +x tools/pre-commit-hook |
| 31 |
chmod +x tools/install_validation_hook.sh |
| 32 |
chmod +x tools/pre-commit-composite |
| 33 |
echo -e "${GREEN}✓ Scripts are now executable${NC}" |
| 34 |
|
| 35 |
# Install pre-commit hook |
| 36 |
echo -e "\n${YELLOW}2. Installing composite pre-commit hook...${NC}" |
| 37 |
echo -e "${YELLOW}This preserves existing version management functionality.${NC}" |
| 38 |
|
| 39 |
# Use the safe installation script |
| 40 |
if ./tools/install_validation_hook.sh; then |
| 41 |
echo -e "${GREEN}✓ Composite pre-commit hook installed${NC}" |
| 42 |
else |
| 43 |
echo -e "${RED}⚠ Hook installation encountered issues${NC}" |
| 44 |
echo " You can install manually with: ./tools/install_validation_hook.sh" |
| 45 |
fi |
| 46 |
|
| 47 |
# Test validation tools |
| 48 |
echo -e "\n${YELLOW}3. Testing validation tools...${NC}" |
| 49 |
|
| 50 |
# Test syntax validator |
| 51 |
if python3 tools/validate_syntax.py --check-only >/dev/null 2>&1; then |
| 52 |
echo -e "${GREEN}✓ Syntax validator working${NC}" |
| 53 |
else |
| 54 |
echo -e "${RED}⚠ Syntax validator found issues${NC}" |
| 55 |
echo " Run: python3 tools/validate_syntax.py --fix" |
| 56 |
fi |
| 57 |
|
| 58 |
# Test pre-commit hook |
| 59 |
if ./tools/pre-commit-hook >/dev/null 2>&1; then |
| 60 |
echo -e "${GREEN}✓ Pre-commit hook working${NC}" |
| 61 |
else |
| 62 |
echo -e "${RED}⚠ Pre-commit hook found issues${NC}" |
| 63 |
echo " This is normal if there are uncommitted changes" |
| 64 |
fi |
| 65 |
|
| 66 |
# Verify dependencies for full validation |
| 67 |
echo -e "\n${YELLOW}4. Checking validation dependencies...${NC}" |
| 68 |
missing_deps=() |
| 69 |
|
| 70 |
if ! command -v python3 >/dev/null 2>&1; then |
| 71 |
missing_deps+=("python3") |
| 72 |
fi |
| 73 |
|
| 74 |
if ! python3 -c "import ast" >/dev/null 2>&1; then |
| 75 |
missing_deps+=("python3-ast") |
| 76 |
fi |
| 77 |
|
| 78 |
if [ ${#missing_deps[@]} -eq 0 ]; then |
| 79 |
echo -e "${GREEN}✓ All validation dependencies available${NC}" |
| 80 |
else |
| 81 |
echo -e "${RED}Missing dependencies: ${missing_deps[*]}${NC}" |
| 82 |
fi |
| 83 |
|
| 84 |
# Final instructions |
| 85 |
echo -e "\n${GREEN}Setup complete!${NC}" |
| 86 |
echo "" |
| 87 |
echo "Development workflow:" |
| 88 |
echo " 1. Make your changes" |
| 89 |
echo " 2. python3 tools/validate_syntax.py --fix" |
| 90 |
echo " 3. python3 tools/validate_release.py --quick" |
| 91 |
echo " 4. git add . && git commit (pre-commit hook runs automatically)" |
| 92 |
echo "" |
| 93 |
echo "Before releases:" |
| 94 |
echo " python3 tools/validate_release.py" |
| 95 |
echo " cat RELEASE_CHECKLIST.md" |
| 96 |
echo "" |
| 97 |
echo -e "${YELLOW}Tip: The pre-commit hook will now run automatically on every commit${NC}" |
| 98 |
echo -e "${YELLOW} and prevent syntax errors from being committed.${NC}" |