modern-python-toolchain
Skill0 starsChanged 2 months agoMITView on GitHub
用 uv + ruff + pyright 搭建现代 Python 项目:初始化、依赖管理、环境配置、lint 与格式化。当用户要新建 Python 项目、配置 uv、设置 lint/format 时使用。 Modern Python project setup with uv, ruff, and pyright. Use when initializing a new Python project, configuring the Python environment, setting up linting/formatting, or when a project needs uv (the fast Python package manager). Trigger on: 'set up Python', 'new Python project', 'configure uv', 'install uv', 'ruff', 'pyright', 'Python linting', 'Python formatting', or when a task requires Python and no pyproject.toml exists yet.
- Pipes a download into a shell
- Installs packages
In this repository45 other files it gives its agents.
- 3d-creationSkill
- 60fps-animationSkill
- aihotSkill
- arxivSkill
- awesome-design-mdSkill
- buildSkill
- canvas-designSkill
- cavemanSkill
- cli-anything-hubSkill
- data-analyticsSkill
- defineSkill
- design-blueprintSkill
- diagnoseSkill
- dsh-plugin-developmentSkill
- feishu-cliSkill
- find-skillsSkill
- flow-canvasSkill
- frontend-designSkill
- fun-code-reverseSkill
- github-cliSkill
- github-trending-cnSkill
- handoffSkill
- latex-compileSkill
- learn-everythingSkill
- metaSkill
- multi-search-engineSkill
- myagents-routerSkill
- office-docsSkill
- perplexitySkill
- planSkill
- product-designSkill
- research-paper-writingSkill
- reverse-proxySkill
- reverse-skill-routerSkill
- reviewSkill
- salesSkill
- shipSkill
- skill-auditSkill
- skill-createSkill
- super-researchSkill
- teachSkill
- verifySkill
- videoSkill
- visualizerSkill
- web-search-exaSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
After installation, restart your shell or run source $HOME/.local/bin/env (the installer prints the exact command).
- Very specific: line 93
If the project does not use src layout, just run uv run main.py.
- Very specific: line 105
Always use ruff for Python linting and formatting.
- Very specific: line 119
Do not enable the full E category or other formatter-conflicting rules (E1xx, E501, W191, Q, COM).
- Distinctive: line 123
After modifying Python code, run both:
- Very specific: line 130
Use --diff to preview changes without applying.
- Distinctive: line 159
Use modern Python 3.12+ syntax:
- Distinctive: line 172
Always annotate function parameters.
- Distinctive: line 182
Use the modern class-based API:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Modern Python Toolchain
A guide for setting up Python projects with modern, fast tooling: uv (package/project manager), ruff (linter/formatter), and pyright (type checker).
Installing uv
uv is an extremely fast Python package and project manager. It replaces pip, pip-tools, pipx, pyenv, virtualenv, poetry, etc.
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Homebrew (macOS)
brew install uvAfter installation, restart your shell or run source $HOME/.local/bin/env (the installer prints the exact command).
For detailed information: https://docs.astral.sh/uv/
uv basics
Python version
Pin a single Python minor version. The recommended default is 3.12 (broadest ecosystem support — PyTorch, CUDA images, downstream libraries). Python 3.14 is the latest stable; prefer it for new projects unless you depend on packages that haven't added 3.14 support yet.
# pyproject.toml
requires-python = "==3.12.*"Install Python via uv (no system Python needed):
uv python install 3.12Creating a new project
uv init # Create new project with pyproject.toml
uv init -p 3.12 # Specify Python versionCommon commands
uv add requests # Add dependency
uv add --dev ruff "pyright[nodejs]" # Add dev dependencies
uv remove requests # Remove dependency
uv sync # Install from lockfile
uv run COMMAND # Run command in project environment
uv run script.py # Run a script
uv run python -c "..." # Run Python one-liner
uvx TOOL ARGS # Run a tool without installing itRules
- Never use
pipin uv projects — alwaysuv addfor packages. - Never run
python script.pydirectly — alwaysuv run script.pyto ensure the correct environment. For one-liners useuv run python -c "...". - Don't manually manage environments with
python -m venvorsource .venv/bin/activate— uv handles this automatically. uvxruns tools from PyPI by package name without installing them permanently.
Project types
For library projects (uv init --lib) or packaged apps (uv init --package), uv_build is used as the default build backend automatically:
[build-system]
# auto-generated by uv init; version bound tracks your installed uv (here: 0.11.28)
requires = ["uv_build>=0.11.28,<0.12.0"]
build-backend = "uv_build"For application projects with an entry point:
[project.scripts]
myapp = "myapp.__main__:main"If the project does not use src layout, just run uv run main.py.
ruff
Ruff is an extremely fast Python linter and code formatter. It replaces Flake8, isort, Black, pyupgrade, autoflake, and more.
For detailed information: https://docs.astral.sh/ruff/
When to use
Always use ruff for Python linting and formatting. Prefer uv run ruff when ruff is a dev dependency; otherwise fall back to uvx ruff.
Configuration
Add to pyproject.toml:
[tool.ruff.lint]
extend-select = [
"UP", # pyupgrade
"I", # isort
]Do not enable the full E category or other formatter-conflicting rules (E1xx, E501, W191, Q, COM); ruff format owns layout.
Post-edit workflow
After modifying Python code, run both:
uv run ruff check --fix path/to/changed_file.py
uv run ruff format path/to/changed_file.pyUse --diff to preview changes without applying.
pyright
Pyright is a fast type checker for Python. Only use it when the project lists it as a dev dependency or explicitly uses type checking.
Install with the nodejs extra so Node.js is bundled automatically (no system node required):
uv add --dev "pyright[nodejs]"Run type checking:
uv run pyright path/to/changed_file.py # check specific files
uv run pyright src/ # check all codeUsually only check the files you modified. For broad changes (base classes, shared types), check the full tree.
Coding style
Type annotations
Use modern Python 3.12+ syntax:
# Good — builtin generics, union syntax
def fetch(url: str, timeout: float = 30.0) -> list[dict[str, str | None]]:
...
# Bad — legacy typing imports
from typing import List, Dict, Optional
def fetch(url: str, timeout: float = 30.0) -> List[Dict[str, Optional[str]]]:
...Always annotate function parameters. Local variables can rely on inference unless the type is ambiguous:
items: list[tuple[str, int]] = [] # annotate — empty literal
config: dict[str, Any] = {} # annotate — empty literal
result = some_api() # inference is finepydantic v2
Use the modern class-based API:
model_config = ConfigDict(...)at class body level, notclass Config.RootModelwithroot: SomeTypefor single-root schemas.
typer (CLI)
Recommended for CLI entry points over argparse:
import typer
from typing import Annotated
cli = typer.Typer(add_completion=False)
@cli.command()
def main(name: Annotated[str, typer.Argument(help="Your name")]) -> None:
typer.echo(f"Hello {name}")
if __name__ == "__main__":
cli()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.

