Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 (dashboard) add linter #216

Merged
merged 1 commit into from
Nov 13, 2024
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
92 changes: 92 additions & 0 deletions .github/workflows/dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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 -d

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 dashboard apps tests
- name: Lint with Ruff
run: pipenv run ruff check dashboard apps tests
- name: Lint with MyPy
run: pipenv run mypy dashboard apps tests
env:
DASHBOARD_DATABASE_URL: psql://qualicharge:pass@postgresql:5432/qualicharge-dashboard
DASHBOARD_SECRET_KEY: the_secret_key

test-dashboard:
needs: build-dashboard
runs-on: ubuntu-latest
services:
postgresql:
image: postgres:14
env:
POSTGRES_DB: test-qualicharge-dashboard
POSTGRES_USER: qualicharge
POSTGRES_PASSWORD: pass
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
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: Test with pytest
run: pipenv run pytest
env:
# fake data in settings.py for mypy checking (due to django environ usage)
DASHBOARD_DB_NAME: test-qualicharge-dashboard
DASHBOARD_DATABASE_URL: psql://qualicharge:pass@localhost:5432/test-qualicharge-dashboard
DASHBOARD_SECRET_KEY: the_secret_key
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
jmaupetit marked this conversation as resolved.
Show resolved Hide resolved
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
jmaupetit marked this conversation as resolved.
Show resolved Hide resolved
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 dashboard 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 dashboard 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 dashboard 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 dashboard 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 "$@"
2 changes: 1 addition & 1 deletion src/dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COPY --chown="${PIPENV_USER_NAME}:${PIPENV_GROUP_NAME}" . /app
WORKDIR /app
USER ${PIPENV_USER_NAME}:${PIPENV_GROUP_NAME}
RUN pipenv install -d && \
pipenv install -e .
pipenv install -v -e .

# -- Run --
CMD pipenv run honcho -f Procfile.dev start
16 changes: 12 additions & 4 deletions src/dashboard/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ verify_ssl = true
name = "pypi"

[packages]
django = "5.1.2"
psycopg = {extras = ["pool", "binary"], version = "==3.2.3"}
django-environ = "0.11.2"
whitenoise = "6.8.2"
Django = "==5.1.3"
django-environ = "==0.11.2"
gunicorn = "==23.0.0"
psycopg = {extras = ["pool", "binary"], version = "==3.2.3"}
whitenoise = "==6.8.2"

[dev-packages]
black = "==24.10.0"
django-stubs = {extras = ["compatible-mypy"], version = "==5.1.1"}
honcho = "==2.0.0"
mypy = "==1.13.0"
pytest = "==8.3.3"
pytest-cov = "==6.0.0"
pytest-django = "==4.9.0"
pytest-httpx = "==0.33.0"
ruff = "==0.7.2"

[requires]
python_version = "3.12"
Loading
Loading