ploughshares/install-codechecks.sh

67 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
#
# install-codechecks.sh
# Installs required tools for code quality checks and security scanning
#
set -e # Exit immediately if a command exits with non-zero status
echo "=== Installing Code Quality and Security Tools ==="
echo "These tools are REQUIRED for maintaining code quality and security standards."
# Check if pip is installed
if ! command -v pip3 &> /dev/null; then
echo "Error: pip3 is not installed. Please install Python and pip first."
exit 1
fi
echo "Installing flake8 (code style checker)..."
pip3 install flake8
echo "Installing safety (dependency vulnerability scanner)..."
pip3 install safety
echo "Installing bandit (security issue scanner)..."
pip3 install bandit
echo "Installing pytest (testing framework)..."
pip3 install pytest
# Create a local configuration for flake8
echo "Creating flake8 configuration..."
cat > .flake8 << EOF
[flake8]
max-line-length = 100
exclude = .git,__pycache__,build,dist
ignore = E203,W503
EOF
# Create a local configuration for bandit
echo "Creating bandit configuration..."
cat > .banditrc << EOF
[bandit]
exclude: /tests,/venv,/.venv
EOF
echo "Setting up Git hooks..."
# Ensure the Git hooks directory exists
mkdir -p .git/hooks
# Make sure the pre-commit hook is executable
if [ -f .git/hooks/pre-commit ]; then
chmod +x .git/hooks/pre-commit
fi
echo ""
echo "=== Installation Complete ==="
echo ""
echo "IMPORTANT: These tools are required for maintaining code quality and security."
echo "Run the following commands to check your code:"
echo " - flake8 . # Check code style"
echo " - safety check -r docker/ploughshares/requirements.txt # Check for vulnerable dependencies"
echo " - bandit -r docker/ploughshares/ # Check for security issues"
echo " - python3 -m pytest tests/ # Run all tests"
echo ""
echo "Pre-commit hooks are installed to run tests automatically before commits."
echo ""
echo "Happy coding!"