new api service and logic implemented
This commit is contained in:
154
scripts/dev.sh
Executable file
154
scripts/dev.sh
Executable file
@@ -0,0 +1,154 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Colors for pretty output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Error handling
|
||||
set -e
|
||||
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
|
||||
trap 'echo -e "${RED}\"${last_command}\" command failed with exit code $?.${NC}"' EXIT
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if a command exists
|
||||
check_command() {
|
||||
if ! command -v "$1" &> /dev/null; then
|
||||
echo -e "${YELLOW}$1 not found${NC}"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check system requirements
|
||||
check_requirements() {
|
||||
log "Checking system requirements..."
|
||||
|
||||
# Check Python version
|
||||
if ! check_command python3; then
|
||||
log "${RED}Python 3 is required but not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Docker Compose is installed
|
||||
if ! check_command docker-compose; then
|
||||
log "${YELLOW}Warning: Docker Compose not found. You'll need it later for running the application${NC}"
|
||||
fi
|
||||
|
||||
log "${GREEN}System requirements check completed${NC}"
|
||||
}
|
||||
|
||||
# Check if poetry is installed
|
||||
check_poetry() {
|
||||
if ! command -v poetry &> /dev/null; then
|
||||
log "${YELLOW}Poetry not found. Installing...${NC}"
|
||||
curl -sSL https://install.python-poetry.org | python3 -
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup development environment
|
||||
setup_dev() {
|
||||
log "Setting up development environment..."
|
||||
check_requirements
|
||||
check_poetry
|
||||
poetry install
|
||||
log "${GREEN}Development environment setup complete!${NC}"
|
||||
}
|
||||
|
||||
# Format code
|
||||
format_code() {
|
||||
log "Formatting code..."
|
||||
poetry run black Services/
|
||||
poetry run isort Services/
|
||||
}
|
||||
|
||||
# Run type checking
|
||||
check_types() {
|
||||
log "Running type checks..."
|
||||
poetry run mypy Services/
|
||||
}
|
||||
|
||||
# Run linting
|
||||
lint_code() {
|
||||
log "Running linter..."
|
||||
poetry run flake8 Services/
|
||||
}
|
||||
|
||||
# Run all checks
|
||||
check_all() {
|
||||
format_code
|
||||
lint_code
|
||||
check_types
|
||||
}
|
||||
|
||||
# Clean up pyc files and cache
|
||||
clean() {
|
||||
log "Cleaning up python cache files..."
|
||||
find . -type f -name "*.pyc" -delete
|
||||
find . -type d -name "__pycache__" -delete
|
||||
find . -type d -name ".pytest_cache" -delete
|
||||
find . -type d -name ".mypy_cache" -delete
|
||||
}
|
||||
|
||||
# Update dependencies
|
||||
update_deps() {
|
||||
log "Updating dependencies..."
|
||||
poetry update
|
||||
}
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
echo -e "${GREEN}Available commands:${NC}"
|
||||
echo "setup - Setup development environment"
|
||||
echo "check-req - Check system requirements"
|
||||
echo "format - Format code with black and isort"
|
||||
echo "lint - Run flake8 linter"
|
||||
echo "types - Run mypy type checker"
|
||||
echo "check - Run all checks (format, lint, types)"
|
||||
echo "clean - Clean up cache files"
|
||||
echo "update - Update dependencies"
|
||||
}
|
||||
|
||||
# Main command handler
|
||||
case "$1" in
|
||||
"setup")
|
||||
setup_dev
|
||||
;;
|
||||
"check-req")
|
||||
check_requirements
|
||||
;;
|
||||
"format")
|
||||
format_code
|
||||
;;
|
||||
"lint")
|
||||
lint_code
|
||||
;;
|
||||
"types")
|
||||
check_types
|
||||
;;
|
||||
"check")
|
||||
check_all
|
||||
;;
|
||||
"clean")
|
||||
clean
|
||||
;;
|
||||
"update")
|
||||
update_deps
|
||||
;;
|
||||
"help"|"")
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unknown command: $1${NC}"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Remove error handling trap
|
||||
trap - EXIT
|
||||
Reference in New Issue
Block a user