From 4a3ed9e5a497c2d6796abdd6f3e3ba79266a0097 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Wed, 16 Jul 2025 13:51:14 -0700 Subject: [PATCH] Replace isort, black with ruff for faster linting, formatting --- .pre-commit-config.yaml | 17 +++++++---------- pyproject.toml | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3a2ae44..fbf5de8b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,12 @@ repos: -- repo: https://github.com/psf/black - rev: 23.1.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.12.3 hooks: - - id: black + - id: ruff-check + args: [ --fix ] + files: \.py$ + - id: ruff-format + files: \.py$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 @@ -16,13 +20,6 @@ repos: - id: check-toml - id: check-yaml -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort (python) - args: ["--profile", "black", "--filter-files"] - - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.0.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 6491dc06..d8bccb93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,7 +122,7 @@ dev = [ "freezegun >= 1.2.0", "factory-boy >= 3.2.1", "mypy >= 1.0.1", - "black >= 23.1.0", + "ruff >= 0.12.0", "pre-commit >= 3.0.4", "gitpython ~= 3.1.43", "datasets", @@ -149,11 +149,31 @@ non_interactive = true show_error_codes = true warn_unused_ignores = false -[tool.black] +[tool.ruff] line-length = 120 -[tool.isort] -profile = "black" +[tool.ruff.lint] +select = ["E", "F", "I"] # Enable error, warning, and import checks +ignore = [ + "E501", # Ignore line length + "F405", # Ignore name not defined (e.g., from imports) + "E402", # Ignore module level import not at top of file +] +unfixable = ["F841"] # Don't auto-remove unused variables +exclude = [ "tests/*.py" ] +[tool.ruff.lint.per-file-ignores] +"src/khoj/main.py" = [ + "I001", # Ignore Import order + "I002", # Ignore Import not at top of file + "E402", # Ignore module level import not at top of file +] + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" + +[tool.ruff.lint.isort] +known-first-party = ["khoj"] [tool.pytest.ini_options] addopts = "--strict-markers"