Ruff and Black Pre-commit Pipeline Setup Prompt
Stand up a pre-commit configuration that runs Ruff (lint + import sort) and Black formatting on staged Python files locally and in CI, with a non-conflicting tool ordering
- Target user
- Python team leads enforcing consistent style and lint gates across contributors
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python tooling engineer who specializes in pre-commit, Ruff, and Black configuration. I will provide: - My Python version and whether the repo already has a `pyproject.toml` - Any existing lint rules or line-length I must preserve - Whether contributors run hooks locally only, in CI only, or both Your job: 1. **Author `.pre-commit-config.yaml`** — pin specific revs for `ruff-pre-commit` (the `ruff` and `ruff-format` hooks) and decide whether to use Black directly or Ruff's formatter. 2. **Avoid format/lint conflicts** — order hooks so the formatter runs and Ruff's lint rules do not fight Black (disable overlapping rules like E501 handling) and explain the choice. 3. **Centralize config in pyproject** — put `[tool.ruff]`, `[tool.ruff.lint]`, and `[tool.black]` (or `[tool.ruff.format]`) settings in `pyproject.toml` with matching line length. 4. **Make hooks auto-fix safely** — enable `--fix` for Ruff but explain that fixed files must be re-staged, and configure the hook to fail when it changes files. 5. **Wire CI** — give a `pre-commit run --all-files` CI step that fails the build on any diff or violation. 6. **Bootstrap contributors** — provide the `pre-commit install` commands and a one-time `--all-files` cleanup run note. Output as: a complete `.pre-commit-config.yaml`, the relevant `pyproject.toml` sections, and the CI snippet. Warn explicitly about running Black and a second formatter that disagree on style, causing an infinite reformat loop.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Ruff and Pre-Commit Lint and Format Setup Prompt
Stand up a fast, opinionated Python lint and format pipeline using Ruff (linter + formatter) wired into pre-commit and CI — replacing the flake8/isort/black stack with one tool and a clean pyproject.toml config.
-
Python pip-audit Dependency Vulnerability Scan Prompt
Stand up an automated pip-audit vulnerability scan for a Python automation repo, triage findings against actual usage, propose minimal-risk version bumps, and wire it into CI with a sane fail policy.
-
Python CSV Data-Quality Validator Prompt
Build a Python CLI that validates and cleans CSV/tabular data against declarative quality rules — types, ranges, required fields, uniqueness, referential checks — and emits a structured report of every violation
-
Python Environment Config Drift Detector Prompt
Build a Python tool that compares configuration or environment-variable sets across environments (dev/staging/prod) and reports missing, extra, and mismatched keys while masking secret values
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.