Skip to content

Instantly share code, notes, and snippets.

@asears
Last active March 31, 2024 18:59
Show Gist options
  • Save asears/9c6d82f4f4d01a49f4a173b47b2799aa to your computer and use it in GitHub Desktop.
Save asears/9c6d82f4f4d01a49f4a173b47b2799aa to your computer and use it in GitHub Desktop.
Ruff Checking

Ruff

Installation

pip install uv
uv pip install ruff

Checks

ruff check .
ruff check --select F401 --select F403 --quiet
ruff check --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"
ruff check --select ALL --ignore F401
ruff check --select F,E,W,S,RUFF,C90,I,N,D,UP,YTT,ANN,ASYNC,TRIO,BLE,FBT,B,A,COM,CPY,C4,DTZ,T10,DJ,EM,EXE,FA,ISC,ICN,G,INP,PIE,T20,PYI,PT,Q,RSE,RET,SLF,SLOT,SIM,TID,TCH,INT,ARG,PTH,TD,FIX,ERA,PD,PGH,PL,C,R,TRY,FLY,NPY,AIR,PERF,FURB,LOG

Ignore

ruff check path/to/file.py --add-noqa

Bandit

ruff check --select S
# ruff: noqa
# ruff: noqa: F841

Formats

ruff format .
# isort: skip_file
# isort: on
# isort: off
# isort: skip
# isort: split

pyproject.toml

[project]
requires-python = ">=3.11"
# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".ipynb_checkpoints",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pyenv",
    ".pytest_cache",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.8
target-version = "py38"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
[tool.ruff.lint]
fixable = ["ALL"]
unfixable = ["F401"]
[tool.ruff]
builtins = ["_"]

exclude = [".venv"]

# Allow lines to be as long as 120.
line-length = 120

# Enable preview features.
preview = true
[tool.ruff]
namespace-packages = ["airflow/providers"]
[tool.ruff]
# Group violations by containing file.
# "full" | "concise" | "grouped" | "json" | "junit" | "github" | "gitlab" | "pylint" | "azure"
output-format = "grouped"
[tool.ruff]
# Allow imports relative to the "src" and "test" directories.
src = ["src", "test"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment