Skip to content

Instantly share code, notes, and snippets.

@froi
Last active January 15, 2024 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froi/6cb6b17091807c526a22159e8bd9eec8 to your computer and use it in GitHub Desktop.
Save froi/6cb6b17091807c526a22159e8bd9eec8 to your computer and use it in GitHub Desktop.
Base Makefile for Python projects
.DEFAULT_GOAL := help
mypy: ## Run the MyPy type checker
@poetry run mypy src
ruff: ## Lint project using Ruff
@poetry run ruff check .
lint: mypy ruff
format: ## Format project using Ruff --fix
@poetry run ruff check --fix .
test: ## Runs pytest
poetry run pytest -v -s $(PWD)/tests
lint-and-test: lint test ## Runs both lint and test targerts
run: ## Runs application with Docker compose
@docker-compose -f dev/build/docker-compose.yaml up postgres app
run-detached: ## Runs application with Docker compose in detached mode
@docker-compose -f dev/docker-compose.yaml up -d postgres app
run-ls: ## List running Docker compose projects
@docker-compose -f dev/build/docker-compose.yaml ls
run-ps: ## List Docker compose containers
@docker-compose -f dev/build/docker-compose.yaml ps
stop: ## Stops tenant_registry Docker compose service
@docker-compose -f dev/build/docker-compose.yaml stop app
stop-all: ## Stops tenant_registry and postgres Docker compose service
@docker-compose -f dev/build/docker-compose.yaml stop postgres app
down: ## Stop and remove Docker compose containers and networks
@docker-compose -f dev/build/docker-compose.yaml down
build: ## Build Docker compose services images
@docker-compose -f dev/build/docker-compose.yaml build --parallel
compose-format: ## Run format targets inside the dev container
@docker-compose -f dev/build/docker-compose.yaml up --build --force-recreate format
compose-lint: ## Run lint targets inside the dev container
@docker-compose -f dev/build/docker-compose.yaml up --build --force-recreate lint
compose-test: ## Run test targets inside the dev container
@docker-compose -f dev/build/docker-compose.yaml up --build --force-recreate test
compose-shell: ## Start an interactive shell in the dev env container.
@docker-compose -f dev/build/docker-compose.yaml run --rm lint-and-test /bin/bash
deps-install: ## Installs dependencies but not the root package
@poetry install --no-root
deps-update: ## Updates dependencies using poetry update
@poetry update
deps-lock: ## Creates or updates poetry lock file
@poetry lock
deps-sync: ## Syncs dependencies with lock file
@poetry install --sync
clean: ## Cleans projects of files generated by tests, coverage, venvs, and other tools
@find . -type d -name __pycache__ -exec rm -r {} \+ 2>/dev/null; true
@find . -type d -name .pytest_cache -exec rm -r {} \+ 2>/dev/null; true
@find . -type d -name .mypy_cache -exec rm -r {} \+ 2>/dev/null; true
@find . -type f -name *.py,cover -exec rm -r {} \+ 2>/dev/null; true
@find . -type f -name coverage.xml -exec rm -r {} \+ 2>/dev/null; true
@find . -type f -name .coverage -exec rm -r {} \+ 2>/dev/null; true
@find . -type f -name .cov -exec rm -r {} \+ 2>/dev/null; true
@find . -type d -name cov_html -exec rm -r {} \+ 2>/dev/null; true
@find . -type f -name .DS_Store -exec rm -r {} \+ 2>/dev/null; true
@find . -type d -name .spec -exec rm -r {} \+ 2>/dev/null; true
@find . -type d -name .venv -exec rm -r {} \+ 2>/dev/null; true
help: ## Show this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment