From ebd6bd2fc08696029fcbd8ea882aa302efa03b3b Mon Sep 17 00:00:00 2001 From: Jan Pieter Waagmeester Date: Tue, 17 Oct 2023 11:53:44 +0200 Subject: [PATCH 1/3] Run pre-commit in ci, add isort/flake8/pyupgrade --- .github/workflows/ci.yml | 21 ++------------------- .pre-commit-config.yaml | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f11eb74b..bcd3f522 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,29 +1,12 @@ name: CI on: [push, pull_request] jobs: - black: + pre-commit: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v4.7.1 - uses: actions/checkout@v4 - - run: python -m pip install --upgrade black - - run: black --check . - - flake8: - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v4.7.1 - - uses: actions/checkout@v4 - - run: python -m pip install flake8 - - run: flake8 - - isort: - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v4.7.1 - - uses: actions/checkout@v4 - - run: python -m pip install -r requirements/common.pip isort==5.6.4 - - run: isort --diff --check django_tables2 test + - run: pre-commit run --show-diff-on-failure --all-files tests: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c120986d..365f7777 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,23 @@ repos: -- repo: https://github.com/psf/black + - repo: https://github.com/psf/black rev: 23.1.0 hooks: - - id: black - language_version: python3.11 + - id: black + language_version: python3.11 + + - repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade + args: [--py38-plus] + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + From d847f91acd883add58debbba5b2ab703230cb9d3 Mon Sep 17 00:00:00 2001 From: Jan Pieter Waagmeester Date: Tue, 17 Oct 2023 11:54:21 +0200 Subject: [PATCH 2/3] apply isort suggestions --- .github/workflows/ci.yml | 1 + example/urls.py | 11 +++++------ tests/test_config.py | 1 + tests/test_models.py | 2 +- tests/test_views.py | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcd3f522..fdf4027b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ jobs: steps: - uses: actions/setup-python@v4.7.1 - uses: actions/checkout@v4 + - run: pip install pre-commit - run: pre-commit run --show-diff-on-failure --all-files tests: diff --git a/example/urls.py b/example/urls.py index 7d09574b..9847317c 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,20 +1,19 @@ -from django.conf import settings -from django.contrib import admin -from django.urls import include, path -from django.views import static - from app.views import ( ClassBased, FilteredPersonListView, MultipleTables, - template_example, checkbox, country_detail, index, multiple, person_detail, + template_example, tutorial, ) +from django.conf import settings +from django.contrib import admin +from django.urls import include, path +from django.views import static urlpatterns = [ path("", index), diff --git a/tests/test_config.py b/tests/test_config.py index 923f8381..5e7b8a4c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,5 @@ from unittest.mock import MagicMock, Mock + from django.core.paginator import EmptyPage, PageNotAnInteger from django.test import SimpleTestCase, TestCase diff --git a/tests/test_models.py b/tests/test_models.py index 22687026..d670c1be 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,5 @@ from collections import defaultdict +from unittest import mock from django.contrib.contenttypes.models import ContentType from django.db import models @@ -6,7 +7,6 @@ from django.template import Context, Template from django.test import TestCase from django.utils.translation import override as translation_override -from unittest import mock import django_tables2 as tables diff --git a/tests/test_views.py b/tests/test_views.py index 9012bbb8..85de7e8c 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,5 +1,6 @@ from math import ceil from typing import Optional + import django_filters as filters from django.core.exceptions import ImproperlyConfigured from django.test import TestCase From cb43843bc964a590cf46faeb7d5d1c7c7283ed2f Mon Sep 17 00:00:00 2001 From: Jan Pieter Waagmeester Date: Tue, 17 Oct 2023 11:57:57 +0200 Subject: [PATCH 3/3] Use py311 --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdf4027b..79d07c6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,9 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/setup-python@v4.7.1 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" - uses: actions/checkout@v4 - run: pip install pre-commit - run: pre-commit run --show-diff-on-failure --all-files