py-quality-setup
Skill52 starsChanged 12 months agoMITView on GitHub
Configure ruff, mypy, and basedpyright for Python 3.13 projects. Use when setting up linters and type checkers in pyproject.toml and pyrightconfig.json.
- Installs packages
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- py-code-healthSkill
- py-complexitySkill
- py-git-hooksSkill
- py-modernizeSkill
- py-refactorSkill
- py-securitySkill
- py-test-qualitySkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 12 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Ensure all tools target Python 3.13 or later
- Distinctive: line 17
Add tools to dev dependencies
- Distinctive: line 33
Must include these sections:
- Distinctive: line 123
Check if dev dependencies exist
- Distinctive: line 124
Verify Python version requirement
- Distinctive: line 127
Add dev dependencies if missing
- Distinctive: line 128
Add/update [tool.ruff] section
- Distinctive: line 129
Add/update [tool.mypy] section
- Distinctive: line 130
Add/update [tool.basedpyright] section
- Very specific: line 131
Create pyrightconfig.json if needed (multi-package projects)
- Very specific: line 166
Write .claude/settings.local.json so all py-* skills can run without permission prompts.
- Very specific: line 210
Merge logic: Read existing file, parse JSON, take union of allow lists, write back.
- Distinctive: line 256
Add overrides for packages without stubs
- Very specific: line 267
Use pyrightconfig.json with extraPaths
- Distinctive: line 271
Start with less strict mypy (strict = false)
- Distinctive: line 273
Use mypy overrides per module
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Quality Tooling Setup
Configure comprehensive linting and type checking for Python 3.13 projects following Engineering Charter standards.
Objectives
- Configure ruff for linting and formatting
- Configure mypy for strict type checking
- Configure basedpyright for additional type analysis
- Ensure all tools target Python 3.13 or later
- Add tools to dev dependencies
Required Tools
Add to [dependency-groups] dev: "ruff", "mypy", "basedpyright", "pytest", "pytest-cov"
- ruff: Fast linter and formatter (Rust-based, replaces black, isort, flake8)
- mypy: Standard Python type checker
- basedpyright: Enhanced Pyright fork with additional type analysis
Required Configuration Files
pyproject.toml (Canonical Reference)
This skill provides the canonical pyproject.toml configuration for all quality tools. Other skills reference this configuration.
Must include these sections:
[project]
requires-python = ">=3.13"
[dependency-groups]
dev = [
"pytest>=8.0",
"pytest-cov>=4.0",
"ruff>=0.8.0",
"mypy>=1.0",
"basedpyright>=1.0",
"pre-commit>=3.0",
# Analysis tools (add as needed for py-* skills):
# "radon", "vulture", "pylint", "bandit", "lizard",
# "mutmut", "wily", "xenon", "pyupgrade", "coverage",
]
[tool.ruff]
line-length = 100 # or 140 for larger projects
target-version = "py313"
src = ["src"] # adjust to your source directory
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
]
ignore = []
[tool.mypy]
python_version = "3.13"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
check_untyped_defs = true
# Add overrides for third-party packages without stubs
# [[tool.mypy.overrides]]
# module = "package_name"
# ignore_missing_imports = true
[tool.basedpyright]
pythonVersion = "3.13"
typeCheckingMode = "standard" # or "recommended" for stricter
reportMissingTypeStubs = false
reportUnknownMemberType = false
reportUnknownArgumentType = false
reportUnknownVariableType = falsepyrightconfig.json (optional, for multi-package projects)
A.When using pyrightconfig.json for multi-package projects, REMOVE the tool.basedpyright section from pyproject.toml
{
"include": ["src"],
"exclude": ["**/node_modules", "**/__pycache__", "**/.*", "venv", ".venv"],
"pythonVersion": "3.13",
"typeCheckingMode": "recommended",
"reportMissingImports": "error",
"reportMissingTypeStubs": false,
"reportUnknownMemberType": false,
"reportUnknownVariableType": false,
"reportUnknownArgumentType": false,
"reportMissingParameterType": true,
"reportUnusedVariable": true,
"reportImplicitStringConcatenation": true,
"reportUnnecessaryTypeIgnoreComment": true
}Setup Workflow
- Check existing configuration
- Read pyproject.toml
- Check if dev dependencies exist
- Verify Python version requirement
- Update or create configuration
- Add dev dependencies if missing
- Add/update [tool.ruff] section
- Add/update [tool.mypy] section
- Add/update [tool.basedpyright] section
- Create pyrightconfig.json if needed (multi-package projects)
- Install tools in venv
# Using uv (recommended): uv sync # Creates venv and installs dev group automatically # Or manually: uv venv source .venv/bin/activate uv sync --group dev # Fallback if uv not available: # python -m venv venv # source venv/bin/activate # pip install -e ".[dev]" - Verify installation
which ruff mypy basedpyright ruff --version mypy --version basedpyright --version - Run initial checks
ruff check . mypy . basedpyright . Configure Claude Code permissions
Write
.claude/settings.local.jsonso all py-* skills can run without permission prompts. If the file already exists, merge new entries into the existingallowlist without removing user entries.{ "permissions": { "allow": [ "Bash(ruff *)", "Bash(mypy *)", "Bash(basedpyright *)", "Bash(pytest *)", "Bash(vulture *)", "Bash(pylint *)", "Bash(radon *)", "Bash(lizard *)", "Bash(wily *)", "Bash(bandit *)", "Bash(mutmut *)", "Bash(pyupgrade *)", "Bash(scc *)", "Bash(pre-commit *)", "Bash(uv *)", "Bash(pip *)", "Bash(python3 *)", "Bash(python *)", "Bash(source *)", "Bash(which *)", "Bash(mkdir *)", "Bash(chmod *)", "Bash(ls *)", "Bash(ln *)", "Bash(git add *)", "Bash(git diff *)", "Bash(git status *)", "Bash(git log *)", "Bash(git ls-files *)", "Bash(git checkout *)", "Bash(git branch *)", "Bash(git commit *)" ], "deny": [] } }Merge logic: Read existing file, parse JSON, take union of
allowlists, write back. Create.claude/directory if needed.Install Stop hook lint gate
Symlink the lint gate script so Claude Code runs the full lint suite (ruff, mypy, basedpyright) on modified files before returning to the user. If any linter reports errors, Claude is blocked from stopping and must fix them first.
mkdir -p ~/.claude/hooks ln -sf ~/.claude/skills/py-git-hooks/lint-gate.py ~/.claude/hooks/lint-gate.pyConfigure the Stop hook in
~/.claude/settings.json(merge into existing hooks if present):{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "python3 ~/.claude/hooks/lint-gate.py" } ] } ] } }- Configure git hooks (if requested)
- Set up pre-commit hook to run linters
- See py-git-hooks skill
Tool-Specific Notes
Ruff
- Fastest Python linter (Rust-based)
- Replaces: black, isort, flake8, and many plugins
- Auto-fix:
ruff check --fix . - Format:
ruff format .
Mypy
- Standard Python type checker
- Strict mode catches most type errors
- Use
# type: ignore[error-code]sparingly - Add overrides for packages without stubs
Basedpyright
- Fork of Pyright with more features
- Catches some errors mypy misses
- More configurable than Pyright
- Works well alongside mypy
Common Adjustments
Monorepo/multi-package:
- Use pyrightconfig.json with extraPaths
- Set namespace_packages = true in mypy
Legacy codebase:
- Start with less strict mypy (strict = false)
- Gradually enable strict checks
- Use mypy overrides per module
Third-party packages without stubs:
[[tool.mypy.overrides]]
module = "package_name"
ignore_missing_imports = trueVerification Checklist
- pyproject.toml has requires-python = ">=3.13"
- dev dependencies include ruff, mypy, basedpyright
- [tool.ruff] configured with target-version = "py313"
- [tool.mypy] configured with python_version = "3.13"
- [tool.basedpyright] configured with pythonVersion = "3.13"
- All tools installed in venv
- ruff check passes (or only expected errors)
- mypy . passes (or only expected errors)
- basedpyright . passes (or only expected errors)
.claude/settings.local.jsonexists with permissions for all quality tools~/.claude/hooks/lint-gate.pysymlinked and Stop hook configured in~/.claude/settings.json
Examples
Example: New project setup
1. Create venv: uv venv && source .venv/bin/activate
2. Create pyproject.toml with [project], [tool.ruff], [tool.mypy], [tool.basedpyright]
3. Install: uv pip install -e ".[dev]"
4. Verify: ruff --version && mypy --version && basedpyright --version
5. Run initial checks: ruff check . && mypy . && basedpyright .
6. Fix issues or add ignores for false positivesExample: Add quality tools to existing project
1. Activate venv: source .venv/bin/activate
2. Update pyproject.toml:
- Add ruff, mypy, basedpyright to [project.optional-dependencies] dev
- Add [tool.ruff], [tool.mypy], [tool.basedpyright] sections
3. Install: uv pip install -e ".[dev]"
4. Run checks: ruff check . (expect many errors initially)
5. Auto-fix: ruff check --fix . && ruff format .
6. Run type checkers: mypy . && basedpyright .
7. Add [[tool.mypy.overrides]] for third-party packages without stubs
8. Iterate until all checks passExample: Legacy codebase gradual adoption
1. Start with minimal ruff rules: select = ["E", "F"]
2. Start mypy non-strict: strict = false
3. Fix errors incrementally, expand rules over time
4. Add per-module mypy overrides for problematic modules
5. Eventually enable strict mode project-wideRelated Skills
- Foundation: This skill is the foundation for all other skills
- Next steps: py-git-hooks (automate enforcement of configured tools)
- See also: py-modernize (for uv migration and syntax upgrades)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

