From 686cef828374bb7c8d3164144126a732afc1dac6 Mon Sep 17 00:00:00 2001 From: Henrik Stranneheim Date: Wed, 6 Mar 2024 09:46:43 +0100 Subject: [PATCH] feat(black) (#79) ### Added - Added Black actions - Add pre-commit, black,isort and ruff --- .github/workflows/black.yml | 21 +++++++++++++++++++++ .github/workflows/merge_master_ci.yml | 12 ++++++------ .github/workflows/pull_request_ci.yml | 16 ++++++++-------- .github/workflows/release_ci.yml | 8 ++++---- .pre-commit-config.yaml | 16 ++++++++++++++++ genotype_api/api/app.py | 1 + genotype_api/api/endpoints/analyses.py | 1 + genotype_api/api/endpoints/plates.py | 1 + genotype_api/api/endpoints/snps.py | 1 + genotype_api/constants.py | 1 + genotype_api/database.py | 1 + requirements-dev.txt | 7 ++++--- requirements.txt | 2 -- 13 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/black.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..c49d2e7 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,21 @@ +name: Black + +on: [pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Check out git repository + uses: actions/checkout@v4.1.1 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Set up Black + uses: psf/black@stable + with: + options: ". --check --line-length 100" + version: "~=24.1.0" diff --git a/.github/workflows/merge_master_ci.yml b/.github/workflows/merge_master_ci.yml index 867b5ca..bfdc806 100644 --- a/.github/workflows/merge_master_ci.yml +++ b/.github/workflows/merge_master_ci.yml @@ -23,7 +23,7 @@ jobs: name: Create staging image steps: - name: Check out git repository - uses: actions/checkout@v2 + uses: actions/checkout@v4.1.1 - name: Extract branch name and remove illegal chars id: get_branch_name @@ -31,18 +31,18 @@ jobs: run: echo "##[set-output name=branch;]$(echo "$(tr "/" "-" <<<${GITHUB_REF#refs/heads/})")" - name: Login to Docker Hub - uses: docker/login-action@v1 + uses: docker/login-action@v3.0.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3.1.0 - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.1.0 with: context: ./ file: ./Dockerfile @@ -54,12 +54,12 @@ jobs: name: Test and coveralls steps: - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5.0.0 with: python-version: "3.10" - name: Check out genotype-api - uses: actions/checkout@v2 + uses: actions/checkout@v4.1.1 with: repository: "Clinical-Genomics/genotype-api" diff --git a/.github/workflows/pull_request_ci.yml b/.github/workflows/pull_request_ci.yml index 7b98fb0..3aad712 100644 --- a/.github/workflows/pull_request_ci.yml +++ b/.github/workflows/pull_request_ci.yml @@ -9,8 +9,8 @@ jobs: runs-on: ubuntu-latest name: Black steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4.1.1 + - uses: actions/setup-python@v5.0.0 - uses: psf/black@stable with: black_args: ". --check --line-length 100" @@ -20,7 +20,7 @@ jobs: name: Create staging docker image steps: - name: Check out git repository - uses: actions/checkout@v2 + uses: actions/checkout@v4.1.1 - name: Extract branch name and remove illegal chars id: get_branch_name @@ -28,18 +28,18 @@ jobs: run: echo "##[set-output name=branch;]$(echo "$(tr "/" "-" <<<${GITHUB_REF#refs/heads/})")" - name: Login to Docker Hub - uses: docker/login-action@v1 + uses: docker/login-action@v3.0.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3.1.0 - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.1.0 with: context: ./ file: ./Dockerfile @@ -51,12 +51,12 @@ jobs: name: Test and coveralls steps: - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5.0.0 with: python-version: "3.10" - name: Check out genotype-api - uses: actions/checkout@v2 + uses: actions/checkout@v4.1.1 with: repository: "Clinical-Genomics/genotype-api" diff --git a/.github/workflows/release_ci.yml b/.github/workflows/release_ci.yml index 8f74478..6a2dfcf 100644 --- a/.github/workflows/release_ci.yml +++ b/.github/workflows/release_ci.yml @@ -12,7 +12,7 @@ jobs: name: Push production docker image to dockerhub steps: - name: Check out git repository - uses: actions/checkout@v2 + uses: actions/checkout@v4.1.1 - name: Extract branch name and remove illegal chars id: get_branch_name @@ -20,18 +20,18 @@ jobs: run: echo "##[set-output name=branch;]$(echo "$(tr "/" "-" <<<${GITHUB_REF#refs/heads/})")" - name: Login to Docker Hub - uses: docker/login-action@v1 + uses: docker/login-action@v3.0.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3.1.0 - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.1.0 with: context: ./ file: ./Dockerfile diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e860672 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: + - repo: https://github.com/psf/black + rev: 24.1.0 + hooks: + - id: black + args: [--line-length=100] + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.7 + hooks: + - id: ruff + diff --git a/genotype_api/api/app.py b/genotype_api/api/app.py index b97f48d..e547a7f 100644 --- a/genotype_api/api/app.py +++ b/genotype_api/api/app.py @@ -2,6 +2,7 @@ Main functions for the genotype api """ + from fastapi import FastAPI, status, Request from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware diff --git a/genotype_api/api/endpoints/analyses.py b/genotype_api/api/endpoints/analyses.py index acad268..93193b5 100644 --- a/genotype_api/api/endpoints/analyses.py +++ b/genotype_api/api/endpoints/analyses.py @@ -1,4 +1,5 @@ """Routes for analysis""" + from pathlib import Path from typing import List diff --git a/genotype_api/api/endpoints/plates.py b/genotype_api/api/endpoints/plates.py index b75f19c..4cd695a 100644 --- a/genotype_api/api/endpoints/plates.py +++ b/genotype_api/api/endpoints/plates.py @@ -1,4 +1,5 @@ """Routes for plates""" + from datetime import datetime from io import BytesIO from pathlib import Path diff --git a/genotype_api/api/endpoints/snps.py b/genotype_api/api/endpoints/snps.py index 988945c..ffb654a 100644 --- a/genotype_api/api/endpoints/snps.py +++ b/genotype_api/api/endpoints/snps.py @@ -1,4 +1,5 @@ """Routes for the snps""" + from genotype_api.models import SNP, User from typing import List diff --git a/genotype_api/constants.py b/genotype_api/constants.py index b79fbac..7a8431c 100644 --- a/genotype_api/constants.py +++ b/genotype_api/constants.py @@ -1,4 +1,5 @@ """Constants used over the package""" + from enum import Enum from pydantic import BaseModel diff --git a/genotype_api/database.py b/genotype_api/database.py index 82bd656..c082e69 100644 --- a/genotype_api/database.py +++ b/genotype_api/database.py @@ -1,4 +1,5 @@ """Hold the database information""" + from sqlmodel import Session, SQLModel, create_engine from genotype_api.config import settings diff --git a/requirements-dev.txt b/requirements-dev.txt index 467952e..8c2cca8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ -pytest>=5.2 -pytest-cov +bump2version coveralls +pre-commit pylint -bump2version \ No newline at end of file +pytest-cov +pytest>=5.2< \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3e66597..c32a2ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,3 @@ - -# server stuff SQLAlchemy==1.4.30 aiofiles bcrypt