Skip to content

Latest commit

 

History

History
137 lines (98 loc) · 3.22 KB

File metadata and controls

137 lines (98 loc) · 3.22 KB

Python Guidelines

Tooling

  • Formatter/Linter: Ruff (version pinned in pyproject.toml)
  • Config: pyproject.toml under [tool.ruff]

Ruff Configuration

Line Length

[tool.ruff]
line-length = 120

[tool.ruff.lint.pycodestyle]
max-line-length = 150
  • Target line length: 120 characters
  • Hard limit (pycodestyle): 150 characters

Rule Selection

[tool.ruff.lint]
preview = true
select = ["ALL"]

All rules are enabled with preview mode. Specific categories and rules are then ignored:

Permanently ignored categories:

  • COM812 — trailing comma (conflicts with formatter)
  • CPY — copyright notices (handled manually)
  • D — docstring conventions (pydocstyle)
  • DOC — documentation warnings
  • ISC — implicit string concatenation
  • FBT — boolean trap

Ignored for investigation:

  • PT (pytest style), PGH (pygrep-hooks), ERA (eradicate), SLF001 (private member access), EM (error messages), TRY (tryceratops), TD/FIX (todos), TID (tidy imports), G (logging format), FLY (flynt), RSE (raise), BLE (blind exception), A (builtins shadowing)

Ignored for later reactivation:

  • B904, C408, E402, INP001, N806, PLC0415, PLR0912, PLR6201, PLR6301, PLR1702, PLR0913, RET504

Per-File Ignores

[tool.ruff.lint.per-file-ignores]
"docs/**/*.py" = ["ALL"]
"plugins/**/*.py" = ["ANN201", "ANN202", "ANN204", "ANN401", "F404", "UP001", "UP010"]
"tasks/*.py" = ["T201"]
  • Plugin files skip some annotation and future-import rules (Ansible compatibility)
  • Task files allow print() calls
  • Doc generation skips all rules

Format Configuration

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
  • Double quotes for strings
  • Spaces for indentation (not tabs)
  • Preserve trailing commas

Import Sorting

[tool.ruff.lint.isort]
known-first-party = ["infrahub"]

Complexity

[tool.ruff.lint.mccabe]
max-complexity = 19

Running Linters

# Check formatting and lint (CI-style, no changes)
invoke lint

# Auto-fix formatting and lint issues
invoke format

Or directly:

# Check
ruff format --check --diff .
ruff check --diff .

# Fix
ruff format .
ruff check --fix .

Additional Linters

  • yamllint — YAML formatting (config: .yamllint.yml)
  • ansible-lint — Ansible-specific linting (config: .ansible-lint)
  • markdownlint — Markdown formatting (config: .markdownlint.yml)
  • Vale — Documentation prose style (config: .vale.ini)

Python Version

python = ">=3.10,<3.14"

Target Python 3.10+ but maintain the Ansible __future__ imports and __metaclass__ = type boilerplate for ansible-test sanity compliance.

Type Hints

Use modern type hints (str | None not Optional[str]). The from __future__ import annotations import is present in all files.

Dependencies

Managed via uv:

uv sync                           # Install all deps
uv sync --group dev               # Include dev deps
uv add <package>                  # Add a dependency
uv add --group dev <package>      # Add a dev dependency