Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ cython_debug/
# PyCharm
.idea/

# VS Code
.vscode/

#OSX
.DS_Store

Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
language: python
pass_filenames: false
additional_dependencies:
- "codespell[toml]>=2.4"
- tomli

- id: typecheck
Expand Down
53 changes: 28 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ VENV_NAME:=.venv
REQS_PROD:=requirements.txt
DOCKER_DEV_SERVICE:=dev
DOCKER_CI_TEST_SERVICE:=test
DOCKER_ISOLATED_SERVICE:=isolated

GCP_PROJECT:=world-fishing-827
GCP_DOCKER_VOLUME:=gcp

sources = python_app_template

PYTHON:=python
PIP:=${PYTHON} -m pip

# ---------------------
# DOCKER
# ---------------------
Expand All @@ -18,13 +22,12 @@ sources = python_app_template
docker-build:
docker compose build

.PHONY: docker-volume ## Creates the docker volume for GCP.
.PHONY: docker-volume ## Creates the docker volume for GCP.
docker-volume:
docker volume create --name ${GCP_DOCKER_VOLUME}

.PHONY: docker-gcp ## gcp: Authenticates to google cloud and configure the project.
docker-gcp:
make docker-volume
docker-gcp: docker-volume
docker compose run gcloud auth application-default login
docker compose run gcloud config set project ${GCP_PROJECT}
docker compose run gcloud auth application-default set-quota-project ${GCP_PROJECT}
Expand All @@ -34,17 +37,17 @@ docker-ci-test:
docker compose run --rm ${DOCKER_CI_TEST_SERVICE}

.PHONY: docker-shell ## Enters to docker container shell.
docker-shell:
docker-shell: docker-volume
docker compose run --rm -it ${DOCKER_DEV_SERVICE}

.PHONY: reqs ## Compiles requirements.txt with pip-tools.
reqs:
docker compose run --rm ${DOCKER_DEV_SERVICE} -c \
docker compose run --rm ${DOCKER_ISOLATED_SERVICE} -c \
'pip-compile -o ${REQS_PROD} -v'

.PHONY: reqs-upgrade ## Upgrades requirements.txt with pip-tools.
reqs-upgrade:
docker compose run --rm ${DOCKER_DEV_SERVICE} -c \
docker compose run --rm ${DOCKER_ISOLATED_SERVICE} -c \
'pip-compile -o ${REQS_PROD} -U -v'

# ---------------------
Expand All @@ -53,60 +56,60 @@ reqs-upgrade:

.PHONY: venv ## Creates virtual environment.
venv:
python -m venv ${VENV_NAME}
${PYTHON} -m venv ${VENV_NAME}

.PHONY: upgrade-pip ## Upgrades pip.
upgrade-pip:
python -m pip install pip==25.2
${PIP} install pip==25.2

.PHONY: install-test ## Install and only test dependencies.
install-test: upgrade-pip
python -m pip install -r requirements-test.txt
${PIP} install -r requirements-test.txt

.PHONY: install ## Install the package in editable mode & all dependencies for local development.
install: upgrade-pip
python -m pip install -e .[lint,dev,build,test]
${PIP} install -e .[lint,dev,build,test]

.PHONY: test ## Run all unit tests exporting coverage.xml report.
test:
python -m pytest -m "not integration" --cov-report term --cov-report=xml --cov=$(sources)
${PYTHON} -m pytest -m "not integration" --cov-report term --cov-report=xml --cov=$(sources)

# ---------------------
# QUALITY CHECKS
# ---------------------

.PHONY: hooks ## Install and pre-commit hooks.
hooks:
python -m pre_commit install --install-hooks
python -m pre_commit install --hook-type commit-msg
${PYTHON} -m pre_commit install --install-hooks
${PYTHON} -m pre_commit install --hook-type commit-msg

.PHONY: format ## Auto-format python source files according with PEP8.
format:
python -m black $(sources)
python -m ruff check --fix $(sources)
python -m ruff format $(sources)
${PYTHON} -m black $(sources)
${PYTHON} -m ruff check --fix $(sources)
${PYTHON} -m ruff format $(sources)

.PHONY: lint ## Lint python source files.
lint:
python -m ruff check $(sources)
python -m ruff format --check $(sources)
python -m black $(sources) --check --diff
${PYTHON} -m ruff check $(sources)
${PYTHON} -m ruff format --check $(sources)
${PYTHON} -m black $(sources) --check --diff

.PHONY: codespell ## Use Codespell to do spell checking.
codespell:
python -m codespell_lib
${PYTHON} -m codespell

.PHONY: typecheck ## Perform type-checking.
typecheck:
python -m mypy
${PYTHON} -m mypy

.PHONY: audit ## Use pip-audit to scan for known vulnerabilities.
audit:
python -m pip_audit .
${PYTHON} -m pip_audit .

.PHONY: pre-commit ## Run all pre-commit hooks.
pre-commit:
python -m pre_commit run --all-files
${PYTHON} -m pre_commit run --all-files

.PHONY: all ## Run the standard set of checks performed in CI.
all: lint codespell typecheck audit test
Expand All @@ -118,7 +121,7 @@ all: lint codespell typecheck audit test

.PHONY: build ## Build a source distribution and a wheel distribution.
build: all clean
python -m build
${PYTHON} -m build

.PHONY: publish ## Publish the distribution to PyPI.
publish: build
Expand Down Expand Up @@ -157,4 +160,4 @@ clean:
help:
@grep -E \
'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ services:
context: .
target: test
entrypoint: 'pytest -v'

isolated:
# Minimal dev container without GCP credentials.
# Used for tasks that don't need external dependencies (e.g., compiling requirements).
build:
context: .
target: dev
platform: linux/amd64
volumes:
- '.:/opt/project'
entrypoint: /bin/bash

volumes:
gcp:
external: true
Loading