From 84236a07e9d1c8a36000dfed9f63aef28cc39a4f Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Tue, 6 Feb 2024 14:28:19 +1000 Subject: [PATCH 1/2] Add make command to check formatting Ensure that both isort and black are run, and that both output a diff showing what formatting changes are required. If either command fails, fail the make command. --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c98443dd..16bfebd6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: install test typecheck unittest dev fmt generate clean update-proto coverage +.PHONY: install test typecheck unittest dev fmt fmt-check generate clean update-proto coverage PYTHON := python @@ -14,6 +14,11 @@ fmt: $(PYTHON) -m isort . $(PYTHON) -m black . +fmt-check: + @$(PYTHON) -m isort . --check --diff; isort_status=$$?; \ + $(PYTHON) -m black . --check --diff; black_status=$$?; \ + exit $$((isort_status + black_status)) + typecheck: $(PYTHON) -m mypy src tests From ff3f0598026d846b24331c2f08e528509f1816f7 Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Tue, 6 Feb 2024 14:29:29 +1000 Subject: [PATCH 2/2] Check formatting as part of CI --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55ea8455..75c6b53f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,3 +20,18 @@ jobs: cache: 'pip' - run: make dev - run: make test + + format: + runs-on: ubuntu-latest + strategy: + matrix: + python: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + cache: 'pip' + - run: make dev + - run: make fmt-check