Skip to content

Commit

Permalink
ci: use ruff for linting (closes #16) (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
axieum authored Aug 15, 2023
1 parent 7f2904a commit 0e5f011
Show file tree
Hide file tree
Showing 11 changed files with 897 additions and 933 deletions.
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ __pycache__/
# poetry
dist/

# ruff
.ruff_cache/

# mypy
.mypy_cache/

Expand Down
50 changes: 5 additions & 45 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,23 @@ repos:
- id: check-toml
- id: check-yaml
args: [ --unsafe ]
- id: check-docstring-first
- id: debug-statements

- repo: https://github.com/python-poetry/poetry
rev: 1.5.0
hooks:
- id: poetry-check

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
hooks:
- id: python-check-mock-methods
- id: python-use-type-annotations
- id: python-check-blanket-noqa

- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
additional_dependencies: &flake8_deps
- flake8-annotations==2.9.0
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10.0
- flake8-pie==0.16.0
- flake8-simplify==0.19.3
- flake8-type-checking==2.2.0
- flake8-use-fstring==1.4
- pep8-naming==0.13.1

- repo: https://github.com/asottile/pyupgrade
rev: v3.8.0
hooks:
- id: pyupgrade
args: [ --py38-plus ]

- repo: https://github.com/hadialqattan/pycln
rev: v2.1.5
hooks:
- id: pycln
args: [ --all ]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: *flake8_deps

- repo: https://github.com/pre-commit/pre-commit
rev: v3.3.3
hooks:
Expand Down
1 change: 1 addition & 0 deletions example/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

from celery.utils.log import get_task_logger

from example.celery import app

if TYPE_CHECKING:
Expand Down
1 change: 1 addition & 0 deletions example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

from django.http import JsonResponse

from example import tasks

if TYPE_CHECKING:
Expand Down
1,699 changes: 842 additions & 857 deletions poetry.lock

Large diffs are not rendered by default.

51 changes: 38 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,25 @@ include = [{ path = "tests", format = "sdist" }]
[tool.poetry.dependencies]
python = "^3.8"
django = "^3.0 | ^4.0"
celery = {version = "^5.3.0", optional = true}
celery = {version = "^5.3.1", optional = true}

[tool.poetry.extras]
celery = ["celery"]

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.0.1"
black = "^23.7.0"
pre-commit = "^3.3.3"
ruff = "^0.0.284"

[tool.poetry.group.test.dependencies]
pytest = "^7.2.0"
pytest-asyncio = "^0.21.0"
pytest = "^7.4.0"
pytest-asyncio = "^0.21.1"
pytest-celery = "^0.0.0"
pytest-cov = "^4.0.0"
pytest-cov = "^4.1.0"
pytest-django = "^4.5.2"
pytest-mock = "^3.11.1"
pytest-xdist = "^3.1.0"
syrupy = "^3.0.5"
pytest-xdist = "^3.3.1"
syrupy = "^3.0.6"

[tool.poetry.group.typing.dependencies]
mypy = ">=0.990"
Expand All @@ -65,16 +67,39 @@ mkdocs-git-revision-date-localized-plugin = "^1.1.0"
mkdocs-material = "^9.0.9"
mkdocs-minify-plugin = "^0.6.2"

[tool.ruff]
src = ["src", "tests"]
target-version = "py38"
line-length = 120
select = [
"F", # pyflakes
"E", # pycodestyle
"W", # pycodestyle
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"ANN", # flake8-annotations
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"DJ", # flake8-django
"PIE", # flake8-pie
"PT", # flake8-pytest-style
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"RUF", # ruff-specific rules
]
ignore = [
"ANN101", # Missing type annotation for {name} in method
"ANN102", # Missing type annotation for {name} in classmethod
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {name}
"E501", # Line too long
"PT013", # Found incorrect import of pytest, use simple `import pytest` instead
]

[tool.black]
target-version = ["py38"]
line-length = 120

[tool.isort]
py_version = 38
profile = "black"
src_paths = ["src", "tests"]
combine_as_imports = true

[tool.mypy]
files = ["src", "tests"]
strict = true
Expand Down
4 changes: 2 additions & 2 deletions src/django_user_trace/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def ready(self) -> None:
"""Sets up the django-user-trace app."""

# Register signals
from . import signals # noqa: F401 # isort: split
from . import signals # noqa: F401 # isort: skip

# Load settings
from . import conf # noqa: F401 # isort: split
from . import conf # noqa: F401 # isort: skip
4 changes: 2 additions & 2 deletions tests/feature/contrib/celery/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def celery_enable_logging() -> bool:


@pytest.fixture(autouse=True)
def install_django_user_trace_celery_app(settings: SettingsWrapper) -> None:
def _install_django_user_trace_celery_app(settings: SettingsWrapper) -> None:
"""Installs the `django_user_trace.contrib.celery` app to Django settings."""

settings.INSTALLED_APPS = settings.INSTALLED_APPS + ["django_user_trace.contrib.celery"]
settings.INSTALLED_APPS = [*settings.INSTALLED_APPS, "django_user_trace.contrib.celery"]
4 changes: 2 additions & 2 deletions tests/unit/contrib/celery/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.fixture(autouse=True)
def install_django_user_trace_celery_app(settings: SettingsWrapper) -> None:
def _install_django_user_trace_celery_app(settings: SettingsWrapper) -> None:
"""Installs the `django_user_trace.contrib.celery` app to Django settings."""

settings.INSTALLED_APPS = settings.INSTALLED_APPS + ["django_user_trace.contrib.celery"]
settings.INSTALLED_APPS = [*settings.INSTALLED_APPS, "django_user_trace.contrib.celery"]
2 changes: 1 addition & 1 deletion tests/unit/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_invalid_user_attr_import_string(settings: SettingsWrapper) -> None:


@pytest.mark.parametrize(
"type_name, value",
("type_name", "value"),
[
("<class 'bool'>", False),
("<class 'float'>", 3.14),
Expand Down

0 comments on commit 0e5f011

Please sign in to comment.