Lint and format with ruff (#560)

* Switch linting and formatting from flake8+isort+black to ruff+ruff-format

* CI: add pre-commit step
This commit is contained in:
Aarni Koskela 2023-12-16 20:13:43 +02:00 committed by GitHub
parent 0ead3b6d6f
commit 4a36247add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 26 deletions

19
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: CI
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: pre-commit/action@v3.0.0

View File

@ -1,12 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: black
- id: ruff
args:
- --fix
- id: ruff-format
exclude: '.*migrations.*'

View File

@ -28,7 +28,7 @@ class PolymorphicChildModelFilter(admin.SimpleListFilter):
value = None
if value:
# ensure the content type is allowed
for choice_value, _ in self.lookup_choices:
for choice_value, _ in self.lookup_choices: # noqa: F402
if choice_value == value:
return queryset.filter(polymorphic_ctype_id=choice_value)
raise PermissionDenied(

View File

@ -7,10 +7,8 @@ import sys
import warnings
import django
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.manager import ManagerDescriptor
from .managers import PolymorphicManager
from .query import PolymorphicQuerySet

View File

@ -16,7 +16,6 @@ from django.db.utils import DEFAULT_DB_ALIAS
# They form a kind of small framework for easily adding more
# functionality to filters and Q objects.
# Probably a more general queryset enhancement class could be made out of them.
from polymorphic import compat
###################################################################################
# PolymorphicQuerySet support functions

View File

@ -5,17 +5,31 @@ requires = [
"django>=2.1", # for makemessages
]
[tool.isort]
profile = "black"
line_length = 99
[tool.black]
[tool.ruff]
line-length = 99
exclude = '''
/(
\.git
| \.tox
| \.venv
| dist
)/
'''
extend-ignore = [
"E501",
]
select = [
"E",
"F",
"I",
"W",
]
[tool.ruff.per-file-ignores]
"example/**" = [
"F401",
"F403",
"F405",
"F841",
"I",
]
"polymorphic/tests/**" = [
"F401",
"F403",
"F405",
"F841",
"I",
]

View File

@ -2,8 +2,6 @@
import os
import sys
from setuptools import find_packages, setup
# When creating the sdist, make sure the django.mo file also exists:
if "sdist" in sys.argv or "develop" in sys.argv:
os.chdir("polymorphic")