Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pre-commit in ci, add isort,flake8,pyupgrade #932

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
name: CI
on: [push, pull_request]
jobs:
black:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v4
- run: python -m pip install --upgrade black
- run: black --check .

flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v4
- run: python -m pip install flake8
- run: flake8

isort:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- 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: pip install pre-commit
- run: pre-commit run --show-diff-on-failure --all-files

tests:
runs-on: ubuntu-latest
Expand Down
23 changes: 20 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 5 additions & 6 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import MagicMock, Mock

from django.core.paginator import EmptyPage, PageNotAnInteger
from django.test import SimpleTestCase, TestCase

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from collections import defaultdict
from unittest import mock

from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.functions import Length
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

Expand Down
1 change: 1 addition & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down