|
| 1 | +.PHONY: compile-deps setup clean-pyc clean-test clean-venv clean test mypy lint format check clean-example dev-env refresh-containers rebuild-images build-image push-image |
| 2 | + |
| 3 | +# Module name - will be updated by init script |
| 4 | +MODULE_NAME := mcp_filesystem |
| 5 | + |
| 6 | +# Development Setup |
| 7 | +################# |
| 8 | +compile-deps: # Compile dependencies from pyproject.toml |
| 9 | + uv pip compile pyproject.toml -o requirements.txt |
| 10 | + uv pip compile pyproject.toml --extra dev -o requirements-dev.txt |
| 11 | + |
| 12 | +PYTHON_VERSION ?= 3.12 |
| 13 | + |
| 14 | +ensure-uv: # Install uv if not present |
| 15 | + @which uv > /dev/null || (curl -LsSf https://astral.sh/uv/install.sh | sh) |
| 16 | + |
| 17 | +setup: ensure-uv compile-deps ensure-scripts # Install dependencies |
| 18 | + UV_PYTHON_VERSION=$(PYTHON_VERSION) uv venv |
| 19 | + UV_PYTHON_VERSION=$(PYTHON_VERSION) uv pip sync requirements.txt requirements-dev.txt |
| 20 | + $(MAKE) install-hooks |
| 21 | + |
| 22 | +install-hooks: # Install pre-commit hooks if in a git repo with hooks configured |
| 23 | + @if [ -d .git ] && [ -f .pre-commit-config.yaml ]; then \ |
| 24 | + echo "Installing pre-commit hooks..."; \ |
| 25 | + uv run pre-commit install; \ |
| 26 | + fi |
| 27 | + |
| 28 | +ensure-scripts: # Ensure scripts directory exists and files are executable |
| 29 | + mkdir -p scripts |
| 30 | + chmod +x scripts/*.py |
| 31 | + |
| 32 | +# Cleaning |
| 33 | +######### |
| 34 | +clean-pyc: # Remove Python compilation artifacts |
| 35 | + find . -name '*.pyc' -exec rm -f {} + |
| 36 | + find . -name '*.pyo' -exec rm -f {} + |
| 37 | + find . -name '*~' -exec rm -f {} + |
| 38 | + find . -name '__pycache__' -exec rm -fr {} + |
| 39 | + |
| 40 | +clean-test: # Remove test and coverage artifacts |
| 41 | + rm -f .coverage |
| 42 | + rm -f .coverage.* |
| 43 | + |
| 44 | +clean-venv: # Remove virtual environment |
| 45 | + rm -rf .venv |
| 46 | + |
| 47 | +clean: clean-pyc clean-test clean-venv |
| 48 | + |
| 49 | +# Testing and Quality Checks |
| 50 | +######################### |
| 51 | +test: setup # Run pytest with coverage |
| 52 | + uv run -m pytest tests --cov=$(MODULE_NAME) --cov-report=term-missing |
| 53 | + |
| 54 | +mypy: setup # Run type checking |
| 55 | + uv run -m mypy $(MODULE_NAME) |
| 56 | + |
| 57 | +lint: setup # Run ruff linter with auto-fix |
| 58 | + uv run -m ruff check --fix $(MODULE_NAME) |
| 59 | + |
| 60 | +format: setup # Run ruff formatter |
| 61 | + uv run -m ruff format $(MODULE_NAME) |
| 62 | + |
| 63 | +check: setup lint format test mypy # Run all quality checks |
| 64 | + |
| 65 | +# Project Management |
| 66 | +################## |
| 67 | +clean-example: # Remove example code (use this to start your own project) |
| 68 | + rm -rf src/example.py tests/test_example.py |
| 69 | + touch src/__init__.py tests/__init__.py |
| 70 | + |
| 71 | +init: setup # Initialize a new project |
| 72 | + uv run python scripts/init_project.py |
| 73 | + |
| 74 | +# Docker |
| 75 | +######## |
| 76 | +IMAGE_NAME = container-registry.io/python-collab-template |
| 77 | +IMAGE_TAG = latest |
| 78 | + |
| 79 | +dev-env: refresh-containers |
| 80 | + @echo "Spinning up a dev environment ." |
| 81 | + @docker compose -f docker/docker-compose.yml down |
| 82 | + @docker compose -f docker/docker-compose.yml up -d dev |
| 83 | + @docker exec -ti composed_dev /bin/bash |
| 84 | + |
| 85 | +refresh-containers: |
| 86 | + @echo "Rebuilding containers..." |
| 87 | + @docker compose -f docker/docker-compose.yml build |
| 88 | + |
| 89 | +rebuild-images: |
| 90 | + @echo "Rebuilding images with the --no-cache flag..." |
| 91 | + @docker compose -f docker/docker-compose.yml build --no-cache |
| 92 | + |
| 93 | +build-image: |
| 94 | + @echo Building dev image and tagging as ${IMAGE_NAME}:${IMAGE_TAG} |
| 95 | + @docker compose -f docker/docker-compose.yml down |
| 96 | + @docker compose -f docker/docker-compose.yml up -d dev |
| 97 | + @docker tag dev ${IMAGE_NAME}:${IMAGE_TAG} |
| 98 | + |
| 99 | +push-image: build-image |
| 100 | + @echo Pushing image to container registry |
| 101 | + @docker push ${IMAGE_NAME}:${IMAGE_TAG} |
0 commit comments