From 30b3470a06077ffa073e457e716372e90583a530 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Sun, 17 Oct 2021 16:24:37 +0200 Subject: [PATCH] Better format enforcing (#1391) * Add shared python format-check target * Add .format-check to api lint target * Format api code with makefile format target * Add .format-check to tools lint target * Add .format-check to analyzer lint target * Format analyzer code with makefile format target * Add .format-check to celery lint target * Add .format-check to api_client lint target * Format api_client code with makefile format target * Add .format-check to playout lint target * Run CI linting in parallel * Disable isort in pre-commit --- .github/workflows/test.yml | 18 ++++++++++++------ .pre-commit-config.yaml | 10 +++++----- analyzer/Makefile | 2 +- analyzer/tests/analyzer_pipeline_test.py | 1 + analyzer/tests/analyzer_test.py | 1 + analyzer/tests/cuepoint_analyzer_test.py | 1 + analyzer/tests/filemover_analyzer_test.py | 1 + analyzer/tests/metadata_analyzer_test.py | 1 + analyzer/tests/playability_analyzer_test.py | 1 + analyzer/tests/replaygain_analyzer_test.py | 1 + api/Makefile | 2 +- api/libretimeapi/models/authentication.py | 1 + api/libretimeapi/tests/models/test_schedule.py | 1 + api/libretimeapi/tests/test_models.py | 3 ++- api/libretimeapi/tests/test_permissions.py | 5 +++-- api/libretimeapi/tests/test_views.py | 3 ++- api_client/Makefile | 2 +- api_client/tests/apcurl_test.py | 1 + api_client/tests/requestprovider_test.py | 1 + api_client/tests/utils_test.py | 1 + api_client/tests/version2_test.py | 1 + playout/Makefile | 2 +- tools/Makefile | 2 +- tools/python.mk | 8 +++++++- worker/Makefile | 2 +- 25 files changed, 50 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee4aa98c8..e6470f48c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,6 +106,16 @@ jobs: # into 'test' when the entire matrix succeeds. lint: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + context: + - analyzer + - api + - api_client + - playout + - worker + container: ghcr.io/libretime/libretime-dev:buster defaults: run: @@ -124,12 +134,8 @@ jobs: echo "::add-matcher::.github/annotations/pylint.json" - name: Lint - run: | - make -C api lint - make -C analyzer lint - make -C worker lint - make -C api_client lint - make -C playout lint + run: make lint + working-directory: ${{ matrix.context }} test: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00d8ce5b9..a0d6dff4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,11 +39,11 @@ repos: hooks: - id: black - - repo: https://github.com/pycqa/isort - rev: 5.9.3 - hooks: - - id: isort - args: ["--profile", "black", "--filter-files"] + # - repo: https://github.com/pycqa/isort + # rev: 5.9.3 + # hooks: + # - id: isort + # args: ["--profile", "black", "--filter-files"] - repo: https://github.com/codespell-project/codespell rev: v2.1.0 diff --git a/analyzer/Makefile b/analyzer/Makefile index 976fc9a1f..d5cf8ac1d 100644 --- a/analyzer/Makefile +++ b/analyzer/Makefile @@ -8,7 +8,7 @@ MYPY_ARG := airtime_analyzer tests PYTEST_ARG := --cov=airtime_analyzer tests format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy fixtures: bash tests/fixtures/generate.sh diff --git a/analyzer/tests/analyzer_pipeline_test.py b/analyzer/tests/analyzer_pipeline_test.py index afac630f0..71f8c8837 100644 --- a/analyzer/tests/analyzer_pipeline_test.py +++ b/analyzer/tests/analyzer_pipeline_test.py @@ -4,6 +4,7 @@ import shutil from queue import Queue import pytest + from airtime_analyzer.analyzer_pipeline import AnalyzerPipeline from .conftest import AUDIO_FILENAME, AUDIO_IMPORT_DEST diff --git a/analyzer/tests/analyzer_test.py b/analyzer/tests/analyzer_test.py index e98666a33..4eb32cd35 100644 --- a/analyzer/tests/analyzer_test.py +++ b/analyzer/tests/analyzer_test.py @@ -1,4 +1,5 @@ import pytest + from airtime_analyzer.analyzer import Analyzer diff --git a/analyzer/tests/cuepoint_analyzer_test.py b/analyzer/tests/cuepoint_analyzer_test.py index 8dc8ab007..9541ee509 100644 --- a/analyzer/tests/cuepoint_analyzer_test.py +++ b/analyzer/tests/cuepoint_analyzer_test.py @@ -1,5 +1,6 @@ import distro import pytest + from airtime_analyzer.cuepoint_analyzer import CuePointAnalyzer from .fixtures import FILE_INVALID_DRM, FILES, Fixture diff --git a/analyzer/tests/filemover_analyzer_test.py b/analyzer/tests/filemover_analyzer_test.py index c50b2b798..36e97120c 100644 --- a/analyzer/tests/filemover_analyzer_test.py +++ b/analyzer/tests/filemover_analyzer_test.py @@ -5,6 +5,7 @@ import time from unittest import mock import pytest + from airtime_analyzer.filemover_analyzer import FileMoverAnalyzer from .conftest import AUDIO_FILENAME diff --git a/analyzer/tests/metadata_analyzer_test.py b/analyzer/tests/metadata_analyzer_test.py index 646625086..047de2511 100644 --- a/analyzer/tests/metadata_analyzer_test.py +++ b/analyzer/tests/metadata_analyzer_test.py @@ -3,6 +3,7 @@ from unittest import mock import mutagen import pytest + from airtime_analyzer.metadata_analyzer import MetadataAnalyzer from .fixtures import FILE_INVALID_DRM, FILE_INVALID_TXT, FILES_TAGGED, FixtureMeta diff --git a/analyzer/tests/playability_analyzer_test.py b/analyzer/tests/playability_analyzer_test.py index f498987d6..7c5074e4e 100644 --- a/analyzer/tests/playability_analyzer_test.py +++ b/analyzer/tests/playability_analyzer_test.py @@ -1,5 +1,6 @@ import distro import pytest + from airtime_analyzer.playability_analyzer import ( PlayabilityAnalyzer, UnplayableFileError, diff --git a/analyzer/tests/replaygain_analyzer_test.py b/analyzer/tests/replaygain_analyzer_test.py index 670033882..d0709f965 100644 --- a/analyzer/tests/replaygain_analyzer_test.py +++ b/analyzer/tests/replaygain_analyzer_test.py @@ -1,4 +1,5 @@ import pytest + from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer from .fixtures import FILE_INVALID_DRM, FILES, Fixture diff --git a/api/Makefile b/api/Makefile index bedb6b4fc..d83524aa7 100644 --- a/api/Makefile +++ b/api/Makefile @@ -7,5 +7,5 @@ PYLINT_ARG := libretimeapi MYPY_ARG := libretimeapi format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy clean: .clean diff --git a/api/libretimeapi/models/authentication.py b/api/libretimeapi/models/authentication.py index 0e5aa8e9c..7ba769a68 100644 --- a/api/libretimeapi/models/authentication.py +++ b/api/libretimeapi/models/authentication.py @@ -4,6 +4,7 @@ from django.contrib import auth from django.contrib.auth.models import AbstractBaseUser, Permission from django.core.exceptions import PermissionDenied from django.db import models + from libretimeapi.managers import UserManager from libretimeapi.permission_constants import GROUPS diff --git a/api/libretimeapi/tests/models/test_schedule.py b/api/libretimeapi/tests/models/test_schedule.py index 9392a723f..868870277 100644 --- a/api/libretimeapi/tests/models/test_schedule.py +++ b/api/libretimeapi/tests/models/test_schedule.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta from django.test import TestCase + from libretimeapi.models import Schedule, ShowInstance diff --git a/api/libretimeapi/tests/test_models.py b/api/libretimeapi/tests/test_models.py index b29e2a058..cb30ef03a 100644 --- a/api/libretimeapi/tests/test_models.py +++ b/api/libretimeapi/tests/test_models.py @@ -1,9 +1,10 @@ from django.apps import apps from django.contrib.auth.models import Group +from rest_framework.test import APITestCase + from libretimeapi.models import User from libretimeapi.models.user_constants import DJ, GUEST from libretimeapi.permission_constants import GROUPS -from rest_framework.test import APITestCase class TestUserManager(APITestCase): diff --git a/api/libretimeapi/tests/test_permissions.py b/api/libretimeapi/tests/test_permissions.py index 20fd14d5c..a6dfaef4b 100644 --- a/api/libretimeapi/tests/test_permissions.py +++ b/api/libretimeapi/tests/test_permissions.py @@ -3,6 +3,9 @@ import os from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser +from model_bakery import baker +from rest_framework.test import APIRequestFactory, APITestCase + from libretimeapi.models.user_constants import ADMIN, DJ, GUEST, PROGRAM_MANAGER from libretimeapi.permission_constants import ( DJ_PERMISSIONS, @@ -10,8 +13,6 @@ from libretimeapi.permission_constants import ( PROGRAM_MANAGER_PERMISSIONS, ) from libretimeapi.permissions import IsSystemTokenOrUser -from model_bakery import baker -from rest_framework.test import APIRequestFactory, APITestCase class TestIsSystemTokenOrUser(APITestCase): diff --git a/api/libretimeapi/tests/test_views.py b/api/libretimeapi/tests/test_views.py index 6ae6b322f..1eb0f741e 100644 --- a/api/libretimeapi/tests/test_views.py +++ b/api/libretimeapi/tests/test_views.py @@ -4,10 +4,11 @@ from datetime import datetime, timedelta, timezone from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.utils import dateparse -from libretimeapi.views import FileViewSet from model_bakery import baker from rest_framework.test import APIRequestFactory, APITestCase +from libretimeapi.views import FileViewSet + class TestFileViewSet(APITestCase): @classmethod diff --git a/api_client/Makefile b/api_client/Makefile index 9970aa22b..fcb8986c6 100644 --- a/api_client/Makefile +++ b/api_client/Makefile @@ -8,6 +8,6 @@ MYPY_ARG := api_clients tests PYTEST_ARG := --cov=api_clients tests format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy test: .pytest clean: .clean diff --git a/api_client/tests/apcurl_test.py b/api_client/tests/apcurl_test.py index e3fb2adc7..900f1dbe8 100644 --- a/api_client/tests/apcurl_test.py +++ b/api_client/tests/apcurl_test.py @@ -1,4 +1,5 @@ import pytest + from api_clients.utils import ApcUrl, IncompleteUrl, UrlBadParam diff --git a/api_client/tests/requestprovider_test.py b/api_client/tests/requestprovider_test.py index e4df26c28..8ed6475fa 100644 --- a/api_client/tests/requestprovider_test.py +++ b/api_client/tests/requestprovider_test.py @@ -1,4 +1,5 @@ import pytest + from api_clients.utils import RequestProvider from api_clients.version1 import api_config diff --git a/api_client/tests/utils_test.py b/api_client/tests/utils_test.py index ab0845f55..15143e26e 100644 --- a/api_client/tests/utils_test.py +++ b/api_client/tests/utils_test.py @@ -2,6 +2,7 @@ import datetime from configparser import ConfigParser import pytest + from api_clients import utils diff --git a/api_client/tests/version2_test.py b/api_client/tests/version2_test.py index f822a7f4e..4496d4e2c 100644 --- a/api_client/tests/version2_test.py +++ b/api_client/tests/version2_test.py @@ -1,4 +1,5 @@ import pytest + from api_clients.utils import RequestProvider from api_clients.version2 import AirtimeApiClient, api_config diff --git a/playout/Makefile b/playout/Makefile index 921892b45..bba0b1d5f 100644 --- a/playout/Makefile +++ b/playout/Makefile @@ -7,5 +7,5 @@ PYLINT_ARG := liquidsoap pypo MYPY_ARG := liquidsoap pypo format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy clean: .clean diff --git a/tools/Makefile b/tools/Makefile index dd674fb08..30a3814e3 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -8,6 +8,6 @@ MYPY_ARG = . PYTEST_ARG = . format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy test: .pytest clean: .clean diff --git a/tools/python.mk b/tools/python.mk index ffc5a9a7f..f372b7961 100644 --- a/tools/python.mk +++ b/tools/python.mk @@ -32,7 +32,13 @@ install: venv .format: $(VENV) source $(VENV)/bin/activate black . - isort --profile black . + isort . --profile black + +.PHONY: .format-check +.format-check: $(VENV) + source $(VENV)/bin/activate + black . --check + isort . --profile black --check .PHONY: .pylint .pylint: $(VENV) diff --git a/worker/Makefile b/worker/Makefile index 0f5125864..c160bb7e2 100644 --- a/worker/Makefile +++ b/worker/Makefile @@ -7,5 +7,5 @@ PYLINT_ARG := airtime-celery MYPY_ARG := airtime-celery format: .format -lint: .pylint .mypy +lint: .format-check .pylint .mypy clean: .clean