Skip to content

Commit

Permalink
Pre-commit: Add Python linter Ruff (celery#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Aug 7, 2024
1 parent fcc4ba7 commit a87c9f6
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ repos:
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.5
hooks: # Format before linting
# - id: ruff-format
- id: ruff

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.4
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject
4 changes: 2 additions & 2 deletions django_celery_beat/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class TaskSelectWidget(Select):

def tasks_as_choices(self):
_ = self._modules
tasks = list(sorted(name for name in self.celery_app.tasks
if not name.startswith('celery.')))
tasks = sorted(name for name in self.celery_app.tasks
if not name.startswith('celery.'))
return (('', ''), ) + tuple(zip(tasks, tasks))

@property
Expand Down
5 changes: 2 additions & 3 deletions django_celery_beat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def make_aware(value):
# then convert to the Django configured timezone.
default_tz = timezone.get_default_timezone()
value = timezone.localtime(value, default_tz)
else:
elif timezone.is_naive(value):
# naive datetimes are assumed to be in local timezone.
if timezone.is_naive(value):
value = timezone.make_aware(value, timezone.get_default_timezone())
value = timezone.make_aware(value, timezone.get_default_timezone())
return value


Expand Down
129 changes: 129 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
[tool.ruff]
target-version = "py38"

lint.select = [
"A", # flake8-builtins
"AIR", # Airflow
"ASYNC", # flake8-async
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"DJ", # flake8-django
"E", # pycodestyle
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"FURB", # refurb
"G", # flake8-logging-format
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"N", # pep8-naming
"NPY", # NumPy-specific rules
"PD", # pandas-vet
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # Pylint
"PT", # flake8-pytest-style
"RSE", # flake8-raise
"S", # flake8-bandit
"SIM", # flake8-simplify
"SLOT", # flake8-slots
"T10", # flake8-debugger
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "B", # flake8-bugbear
# "COM", # flake8-commas
# "CPY", # flake8-copyright
# "D", # pydocstyle
# "DTZ", # flake8-datetimez
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "FBT", # flake8-boolean-trap
# "FIX", # flake8-fixme
# "I", # isort
# "INT", # flake8-gettext
# "PTH", # flake8-use-pathlib
# "PYI", # flake8-pyi
# "Q", # flake8-quotes
# "RET", # flake8-return
# "RUF", # Ruff-specific rules
# "SLF", # flake8-self
# "T20", # flake8-print
# "TD", # flake8-todos
# "TRY", # tryceratops
]
lint.ignore = [
"DJ001",
"DJ006",
"DJ008",
"DJ012",
"N801",
"N802",
"N803",
"N806",
"PIE790",
"PT004",
"PT009",
"PT027",
"UP031",
"UP032",
]
lint.per-file-ignores."*/migrations/*" = [
"C405",
"D",
"E501",
"I",
]
lint.per-file-ignores."django_celery_beat/models.py" = [
"ISC002",
]
lint.per-file-ignores."django_celery_beat/schedulers.py" = [
"PERF203",
"SIM105",
]
lint.per-file-ignores."django_celery_beat/validators.py" = [
"BLE001",
]
lint.per-file-ignores."docker/base/celery.py" = [
"INP001",
]
lint.per-file-ignores."docs/conf.py" = [
"INP001",
]
lint.per-file-ignores."setup.py" = [
"EXE001",
"FURB129",
"SIM115",
]
lint.per-file-ignores."t/*" = [
"S101",
]
lint.per-file-ignores."t/proj/__init__.py" = [
"PGH004",
]
lint.per-file-ignores."t/proj/settings.py" = [
"S105",
]
lint.per-file-ignores."t/unit/conftest.py" = [
"F401",
]
lint.per-file-ignores."t/unit/test_schedulers.py" = [
"C408",
"PERF102",
"PT018",
]
lint.pylint.allow-magic-value-types = [
"float",
"int",
"str",
]
lint.pylint.max-args = 8 # Default: 5
2 changes: 1 addition & 1 deletion t/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add(x, y):
request.instance.app = None


@pytest.fixture
@pytest.fixture()
def patching(monkeypatch):
def _patching(attr):
monkeypatch.setattr(attr, MagicMock())
Expand Down
1 change: 0 additions & 1 deletion t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def test_duplicate_schedules(self):
"day_of_week": "*",
"day_of_month": "*",
"month_of_year": "*",
"day_of_week": "*",
}
schedule = schedules.crontab(hour="4")
self._test_duplicate_schedules(CrontabSchedule, kwargs, schedule)
Expand Down

0 comments on commit a87c9f6

Please sign in to comment.