Skip to content

Commit

Permalink
Lint and format with ruff (#560)
Browse files Browse the repository at this point in the history
* Switch linting and formatting from flake8+isort+black to ruff+ruff-format

* CI: add pre-commit step
  • Loading branch information
akx authored Dec 16, 2023
1 parent 0ead3b6 commit 4a36247
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
17 changes: 10 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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.*'
2 changes: 1 addition & 1 deletion polymorphic/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def queryset(self, request, queryset):
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(
Expand Down
2 changes: 0 additions & 2 deletions polymorphic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
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
Expand Down
1 change: 0 additions & 1 deletion polymorphic/query_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 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
Expand Down
40 changes: 27 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4a36247

Please sign in to comment.