Skip to content

Commit

Permalink
🐛 (project) pipenv workaround for github workfow and upgrade pipenv
Browse files Browse the repository at this point in the history
- pipenv 2024.4.0 has issues with write mode (pipenv install -de .) in github workflow. Fixed by removing edit mode
- upgrade pipenv version from 2024.0.1 to 2024.2.0 in dev environment
  • Loading branch information
ssorin committed Nov 8, 2024
1 parent fd71e34 commit 0513996
Show file tree
Hide file tree
Showing 16 changed files with 762 additions and 73 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 -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 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 "$@"
23 changes: 23 additions & 0 deletions src/dashboard/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default_language_version:
python: python3.12
fail_fast: true
repos:
- repo: local
hooks:
- id: ruff
name: ruff
language: system
files: "src/dashboard/|src/tests"
exclude: "migrations"
types: [python]
entry: pipenv
args: ["run", "ruff", "check"]

- id: mypy
name: mypy
language: system
files: "src/dashboard/|src/tests"
exclude: "migrations"
types: [python]
entry: pipenv
args: ["run", "mypy"]
1 change: 1 addition & 0 deletions src/dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to
### Added

- bootstrap dashboard project
- add linters (black, ruff and mypy), pytest and github workflow

[unreleased]: https://github.com/MTES-MCT/qualicharge/compare/main...bootstrap-dashboard-project

11 changes: 10 additions & 1 deletion src/dashboard/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ verify_ssl = true
name = "pypi"

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

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

[requires]
python_version = "3.12"
Loading

0 comments on commit 0513996

Please sign in to comment.