diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fc324c4b..98b48521 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,7 @@ version: 2 updates: - package-ecosystem: "pip" - directory: "/" + directory: "/dev" schedule: interval: "daily" assignees: diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index fcb90c81..6c91ed07 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -11,8 +11,11 @@ env: jobs: validate-models: - name: Validate models.yml + name: CI runs-on: ubuntu-latest + defaults: + run: + working-directory: dev/ steps: - uses: actions/checkout@v4 @@ -23,7 +26,28 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Install requirements - run: pip install -r models_validator/requirements.txt + run: pip install -r requirements.txt + + - name: Check black + if: always() + run: make check-black + + - name: Check isort + if: always() + run: make check-isort + + - name: Check flake8 + if: always() + run: make flake8 + + - name: Check mypy + if: always() + run: make mypy + + - name: Check pyupgrade + if: always() + run: make pyupgrade - name: Validate models.yml - run: python models_validator/validate.py models.yml + if: always() + run: make validate-models diff --git a/dev/Dockerfile b/dev/Dockerfile new file mode 100644 index 00000000..20f1b85d --- /dev/null +++ b/dev/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.10.13-slim-bookworm + +RUN apt-get update && apt-get install --yes make bash-completion + +WORKDIR /app/dev/ + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +STOPSIGNAL SIGKILL +CMD sleep infinity diff --git a/dev/Makefile b/dev/Makefile new file mode 100644 index 00000000..67e35a73 --- /dev/null +++ b/dev/Makefile @@ -0,0 +1,42 @@ +# Commands inside the container + +all: pyupgrade black autoflake isort flake8 mypy + +pyupgrade: + pyupgrade --py310-plus --exit-zero-even-if-changed $$(find . -name '*.py') + +check-pyupgrade: + pyupgrade --py310-plus $$(find . -name '*.py') + +black: + black src/ + +check-black: + black --check --diff src/ + +autoflake: + autoflake src/ + +isort: + isort src/ + +check-isort: + isort --check-only --diff src/ + +flake8: + flake8 src/ + +mypy: + mypy src/ + +validate-models: + python src/validate.py + +# Docker manage commands + +run-dev: + USER_ID=$$(id -u $${USER}) GROUP_ID=$$(id -g $${USER}) docker-compose up -d --build + docker-compose exec models bash --rcfile /etc/bash_completion + +stop-dev: + docker-compose down diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml new file mode 100644 index 00000000..dc885f8f --- /dev/null +++ b/dev/docker-compose.yml @@ -0,0 +1,21 @@ +version: "3" +services: + models: + build: . + user: $USER_ID:$GROUP_ID + volumes: + - ..:/app + depends_on: + - postgres + networks: + - postgres + postgres: + image: postgres:15 + environment: + - POSTGRES_USER=openslides + - POSTGRES_PASSWORD=openslides + - POSTGRES_DB=openslides + networks: + - postgres +networks: + postgres: diff --git a/dev/requirements.txt b/dev/requirements.txt new file mode 100644 index 00000000..5dd8ac34 --- /dev/null +++ b/dev/requirements.txt @@ -0,0 +1,13 @@ +autoflake==2.2.1 +black==24.1.1 +flake8==7.0.0 +isort==5.13.2 +mypy==1.8.0 +pytest==8.0.0 +pyupgrade==3.15.0 +pyyaml==6.0.1 +simplejson==3.19.2 + +# typing +types-PyYAML==6.0.12.12 +types-simplejson==3.19.0.2 diff --git a/dev/setup.cfg b/dev/setup.cfg new file mode 100644 index 00000000..6575421d --- /dev/null +++ b/dev/setup.cfg @@ -0,0 +1,19 @@ +[autoflake] +verbose = true +in-place = true +remove-all-unused-imports = true +ignore-init-module-imports = true +recursive = true + +[isort] +include_trailing_comma = true +multi_line_output = 3 +force_grid_wrap = 0 +use_parentheses = True +line_length = 88 + +[flake8] +extend-ignore = E203,E501 + +[mypy] +disallow_untyped_defs = true diff --git a/models_validator/validate.py b/dev/src/validate.py similarity index 99% rename from models_validator/validate.py rename to dev/src/validate.py index 25858f67..ea3a42ab 100644 --- a/models_validator/validate.py +++ b/dev/src/validate.py @@ -1,5 +1,6 @@ import re import sys +from pathlib import Path from typing import Any, cast import simplejson as json @@ -17,9 +18,7 @@ DECIMAL_REGEX = re.compile(r"^-?(\d|[1-9]\d+)\.\d{6}$") COLOR_REGEX = re.compile(r"^#[0-9a-f]{6}$") -DEFAULT_FILES = [ - "../models.yml", -] +DEFAULT_FILES = [str((Path(__file__).parent / ".." / ".." / "models.yml").resolve())] RELATION_TYPES = ( "relation", diff --git a/models_validator/requirements.txt b/models_validator/requirements.txt deleted file mode 100644 index 128069d0..00000000 --- a/models_validator/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pyyaml==6.0.1 -simplejson==3.19.2 -types-PyYAML==6.0.12.12