Skip to content

Commit

Permalink
👷 (dashboard) add linter
Browse files Browse the repository at this point in the history
- add dev dependencies (black, ruff, mypy, django-stubs, pre-commit)
- add lint and test commands to Makefile
- configure ruff, mypy and pre-commit
- reformat code with ruff ans black
- add a GitHub Actions workflow for CI/CD
- regenerate Pipfile.lock
- move manage.py from src/dashboard/apps to src/dashboard/
- remove ignore rule from pyproject.toml: tool.ruff.lint
- remove mypy.ini and update src/dashboard/pyproject.toml
- install and configure pytest and pytest-django
- update changelog
  • Loading branch information
ssorin committed Nov 8, 2024
1 parent 5902bdd commit 2b432c7
Show file tree
Hide file tree
Showing 20 changed files with 1,375 additions and 663 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: dashboard CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-dashboard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Pipenv
run: pipx install pipenv
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pipenv"
cache-dependency-path: "src/dashboard/Pipfile.lock"
- name: Install dependencies
run: |
cd src/dashboard
pipenv install -de .
lint-dashboard:
needs: build-dashboard
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/dashboard
steps:
- uses: actions/checkout@v4
- name: Install pipenv
run: pipx install pipenv
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pipenv"
cache-dependency-path: "src/dashboard/Pipfile.lock"
- name: Lint with Black
run: pipenv run black apps tests
- name: Lint with Ruff
run: pipenv run ruff check apps tests
- name: Lint with MyPy
run: pipenv run mypy apps tests
61 changes: 50 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
SHELL := /bin/bash

# -- Docker
COMPOSE = bin/compose
COMPOSE_UP = $(COMPOSE) up -d
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
COMPOSE_RUN_API = $(COMPOSE_RUN) api
COMPOSE_RUN_API_PIPENV = $(COMPOSE_RUN_API) pipenv run
COMPOSE_RUN_CLIENT = $(COMPOSE_RUN) client
COMPOSE_RUN_PREFECT_PIPENV = $(COMPOSE_RUN) prefect pipenv run
COMPOSE = bin/compose
COMPOSE_UP = $(COMPOSE) up -d
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
COMPOSE_RUN_API = $(COMPOSE_RUN) api
COMPOSE_RUN_API_PIPENV = $(COMPOSE_RUN_API) pipenv run
COMPOSE_RUN_CLIENT = $(COMPOSE_RUN) client
COMPOSE_RUN_PREFECT_PIPENV = $(COMPOSE_RUN) prefect pipenv run
COMPOSE_RUN_DASHBOARD_PIPENV = $(COMPOSE_RUN) dashboard pipenv run

# -- Tools
CURL = $(COMPOSE_RUN) curl
Expand Down Expand Up @@ -128,6 +129,10 @@ run-prefect: ## run the prefect service
$(COMPOSE_UP) prefect-worker
.PHONY: run-prefect

run-dashboard: ## run the dashboard service
$(COMPOSE_UP) dashboard
.PHONY: run-dashboard

status: ## an alias for "docker compose ps"
@$(COMPOSE) ps
.PHONY: status
Expand Down Expand Up @@ -325,7 +330,8 @@ lint: ## lint all sources
lint: \
lint-api \
lint-client \
lint-prefect
lint-prefect \
lint-dashboard
.PHONY: lint

lint-api: ## lint api python sources
Expand All @@ -335,20 +341,27 @@ lint-api: \
lint-api-mypy
.PHONY: lint-api

lint-client: ## lint api python sources
lint-client: ## lint client python sources
lint-client: \
lint-client-black \
lint-client-ruff \
lint-client-mypy
.PHONY: lint-client

lint-prefect: ## lint api python sources
lint-prefect: ## lint prefect python sources
lint-prefect: \
lint-prefect-black \
lint-prefect-ruff \
lint-prefect-mypy
.PHONY: lint-prefect

lint-dashboard: ## lint dashboard python sources
lint-dashboard: \
lint-dashboard-black \
lint-dashboard-ruff \
lint-dashboard-mypy
.PHONY: lint-dashboard

lint-api-black: ## lint api python sources with black
@echo 'lint:black started…'
@$(COMPOSE_RUN_API_PIPENV) black qualicharge tests
Expand Down Expand Up @@ -409,11 +422,32 @@ lint-prefect-mypy: ## lint prefect python sources with mypy
@$(COMPOSE_RUN_PREFECT_PIPENV) mypy indicators tests
.PHONY: lint-prefect-mypy

lint-dashboard-black: ## lint dashboard python sources with black
@echo 'lint:black dashboard started…'
@$(COMPOSE_RUN_DASHBOARD_PIPENV) black apps tests
.PHONY: lint-dashboard-black

lint-dashboard-ruff: ## lint dashboard python sources with ruff
@echo 'lint:ruff dashboard started…'
@$(COMPOSE_RUN_DASHBOARD_PIPENV) ruff check apps tests
.PHONY: lint-dashboard-ruff

lint-dashboard-ruff-fix: ## lint and fix dashboard python sources with ruff
@echo 'lint:ruff-fix dashboard started…'
@$(COMPOSE_RUN_DASHBOARD_PIPENV) ruff check --fix apps tests
.PHONY: lint-dashboard-ruff-fix

lint-dashboard-mypy: ## lint dashboard python sources with mypy
@echo 'lint:mypy dashboard started…'
@$(COMPOSE_RUN_DASHBOARD_PIPENV) mypy apps tests
.PHONY: lint-dashboard-mypy

test: ## run all services tests
test: \
test-api \
test-client \
test-prefect
test-prefect \
test-dashboard
.PHONY: test

test-api: ## run API tests
Expand All @@ -428,6 +462,11 @@ test-prefect: ## run prefect tests
SERVICE=prefect-test bin/pytest
.PHONY: test-prefect

test-dashboard: ## run dashboard tests
@echo "Run dashboard tests…"
SERVICE=dashboard bin/pytest
.PHONY: test-dashboard

# -- Misc
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
2 changes: 1 addition & 1 deletion bin/manage
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ DOCKER_USER=${DOCKER_USER} \
DOCKER_GID=${DOCKER_GID} \
docker compose run -it \
dashboard \
pipenv run python apps/manage.py "$@"
pipenv run python manage.py "$@"
Loading

0 comments on commit 2b432c7

Please sign in to comment.