Skip to content
Open
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
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
54 changes: 28 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ GCP_DOCKER_VOLUME:=gcp

sources = python_app_template

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

# ---------------------
# DOCKER
# ---------------------
Expand All @@ -18,32 +21,31 @@ 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}

.PHONY: docker-ci-test ## Runs tests using prod image, exporting coverage.xml report.
docker-ci-test:
docker-ci-test: docker-volume
Copy link
Collaborator

@tomaslink tomaslink Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this should be here. The idea of this command is to execute the unit tests in isolation against the installed package in a docker container. This is used in the CI/CD. Why would you need the volume with authentication information?

I would say the same for reqs and reqs-upgrade.

It could be useful in docker-shell if you didn't run docker-gcp before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these pre-reqs because reqs and reqs upgrade would fail without creating the volume first. But you're right that we should't really need a volume with credentials to do these things.

Perhaps the real fix is adding a separate dev service in the docker compose that doesn't need GCP? Or just remove the mount from the dev service if nothing else needs it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efcaguab Oh I see. Yes, I think the correct solution is to add a separate service for the requirements:

  req:
    build:
      context: .
      target: dev
    volumes:
      - ".:/opt/project"
    entrypoint: /bin/bash

I think we need a dev service with the volume because some people use the docker container to develop (I don't...).

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:
reqs: docker-volume
docker compose run --rm ${DOCKER_DEV_SERVICE} -c \
'pip-compile -o ${REQS_PROD} -v'

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

Expand All @@ -53,60 +55,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_lib

.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 +120,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 +159,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}'
Loading