diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc89b0d3cf9a35abc7464f42aed5f40d0b3234ec..1fab6fd6f2ebc219ded4083ebac46335fea65f29 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,10 @@ +stages: + - test + - deploy + +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + lint-openapi: image: name: redocly/cli @@ -36,6 +43,20 @@ test-frontend: - cypress/screenshots expire_in: 1 week +test-python: + image: python:latest + stage: test + cache: + paths: + - .cache/pip + before_script: + - pip install pipenv + - pipenv requirements --dev > requirements.txt + - pip install -r requirements.txt + script: + - black --check $CI_PROJECT_DIR + - mypy . + # This snippet is copied and modified from the GitLab Documentation (as of 2021-01-10, the contents of the script seem to have changed by now) # * Title of the documentation page: "Building a Docker image with kaniko" # * Author: (c) 2011-present GitLab B.V. diff --git a/README.md b/README.md index 6717fb317f49e2e8316f240c8f180409ae16833f..bfbb32bcfa11c060b7c868d59ff592ef01458164 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,17 @@ Please run `alembic upgrade head` after pulling changes from the repository. --- +## Compliance + +### Formatting + +We use [black](https://github.com/psf/black) as formatting tool. +Use `black .` to run the formatter. + +### Static Type Checking + +Run `mypy .` to let [mypy](https://www.mypy-lang.org/) validate the Python types. + ## How to move around in this repo ## `/portal/`: Main Application diff --git a/portal/__init__.py b/portal/__init__.py index 642054e1eae3ce4ca477b4d960c33113987b6bb5..99937d5f6c96730cb3a75a2f8c00ab45734ba5c5 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -9,7 +9,7 @@ from flask_sqlalchemy import SQLAlchemy from .db_config import get_database_uri, get_uri_for_sqlite -db = SQLAlchemy() +db: SQLAlchemy = SQLAlchemy() from .model import * diff --git a/portal/model/FlaskConfigEntry.py b/portal/model/FlaskConfigEntry.py index 378aed8320af2ee381777e3eb8bcbee363bd60b1..96a53ba54d5fdb7c316181c91ee27d3ba8fe9e40 100644 --- a/portal/model/FlaskConfigEntry.py +++ b/portal/model/FlaskConfigEntry.py @@ -1,9 +1,12 @@ from flask import Flask +from typing import Any from portal import db +BaseModel: Any = db.Model -class FlaskConfigEntry(db.Model): + +class FlaskConfigEntry(BaseModel): """ A configuration entry for Flask (a key-value pair) as persisted in a database """ diff --git a/portal/model/Retrievable.py b/portal/model/Retrievable.py index 1b7c6495c41b7e1aace3d3628fa627b34ae3b56a..4608b14500c4d77b4907203b28c2ff2a0e028bb8 100644 --- a/portal/model/Retrievable.py +++ b/portal/model/Retrievable.py @@ -1,12 +1,15 @@ from abc import abstractmethod from typing import Any, List, Optional, Self +from sqlalchemy import Column from flask import g from portal import db +BaseModel: Any = db.Model -class Retrievable(db.Model): + +class Retrievable(BaseModel): """ A type whose instances can be retrieved from the database. @@ -17,7 +20,7 @@ class Retrievable(db.Model): __abstract__ = True @classmethod - def get_canonical_order_column(cls) -> Optional[db.Column]: + def get_canonical_order_column(cls) -> Optional[Column]: """ Return the colum by which instances of this type should be canonically ordered when retrieving them all from the database.