Skip to content

Commit 4a36247

Browse files
authored
Lint and format with ruff (#560)
* Switch linting and formatting from flake8+isort+black to ruff+ruff-format * CI: add pre-commit step
1 parent 0ead3b6 commit 4a36247

File tree

7 files changed

+57
-26
lines changed

7 files changed

+57
-26
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches:
10+
- master
11+
jobs:
12+
Lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.11"
19+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.5.0
44
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
7-
- id: trailing-whitespace
8-
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 23.11.0
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.1.6
1010
hooks:
11-
- id: black
11+
- id: ruff
12+
args:
13+
- --fix
14+
- id: ruff-format
1215
exclude: '.*migrations.*'

polymorphic/admin/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def queryset(self, request, queryset):
2828
value = None
2929
if value:
3030
# ensure the content type is allowed
31-
for choice_value, _ in self.lookup_choices:
31+
for choice_value, _ in self.lookup_choices: # noqa: F402
3232
if choice_value == value:
3333
return queryset.filter(polymorphic_ctype_id=choice_value)
3434
raise PermissionDenied(

polymorphic/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import warnings
88

99
import django
10-
from django.core.exceptions import ImproperlyConfigured
1110
from django.db import models
1211
from django.db.models.base import ModelBase
13-
from django.db.models.manager import ManagerDescriptor
1412

1513
from .managers import PolymorphicManager
1614
from .query import PolymorphicQuerySet

polymorphic/query_translate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# They form a kind of small framework for easily adding more
1717
# functionality to filters and Q objects.
1818
# Probably a more general queryset enhancement class could be made out of them.
19-
from polymorphic import compat
2019

2120
###################################################################################
2221
# PolymorphicQuerySet support functions

pyproject.toml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,31 @@ requires = [
55
"django>=2.1", # for makemessages
66
]
77

8-
[tool.isort]
9-
profile = "black"
10-
line_length = 99
11-
12-
[tool.black]
8+
[tool.ruff]
139
line-length = 99
14-
exclude = '''
15-
/(
16-
\.git
17-
| \.tox
18-
| \.venv
19-
| dist
20-
)/
21-
'''
10+
11+
extend-ignore = [
12+
"E501",
13+
]
14+
select = [
15+
"E",
16+
"F",
17+
"I",
18+
"W",
19+
]
20+
21+
[tool.ruff.per-file-ignores]
22+
"example/**" = [
23+
"F401",
24+
"F403",
25+
"F405",
26+
"F841",
27+
"I",
28+
]
29+
"polymorphic/tests/**" = [
30+
"F401",
31+
"F403",
32+
"F405",
33+
"F841",
34+
"I",
35+
]

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os
33
import sys
44

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

0 commit comments

Comments
 (0)