modern-python-toolchain
它能做什么
这项技能为 Python 项目设置现代化的工具。适合开始新 Python 项目、或希望整理混乱环境的开发者。
适用场景
- ✓当你开始一个新的 Python 项目,并希望使用快速、标准工具的时候。
- ✓当你想为 Python 代码设置代码检查和格式化的时候。
- ✓当你需要为 Python 软件包安装或配置 uv 的时候。
技能链接
https://github.com/XiaomiMiMo/MiMo-Code/blob/main/packages/cli/src/skill/builtin/.bundle/modern-python-toolchain/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我想为一个新的 Python 项目设置快速的软件包管理、代码检查和类型检查。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会安装 uv,固定一个 Python 版本,并添加 ruff 和 pyright,其设置与项目相匹配。然后它会使用这些工具管理软件包并检查代码。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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 uv
After 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.12
Creating a new project
uv init # Create new project with pyproject.toml
uv init -p 3.12 # Specify Python version
Common 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 it
Rules
- 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.py
Use --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 code
Usually 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, tim
常见问题
它建议使用哪个 Python 版本?
这项技能建议固定一个 Python 次版本号,并以 3.12 作为通用的默认版本。
uv 能替代 pip 吗?
这项技能说明,在项目工作中,uv 可以替代 pip、virtualenv 和 poetry 等工具。
ruff 和 pyright 各自做什么?
Ruff 负责检查和格式化代码,pyright 负责检查类型。
详情
作者的原始描述
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.
repo: XiaomiMiMo/MiMo-Code
热度
- GitHub 星标
- 14k
- 排名
- #11334
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
effect
14k帮你的智能体通过查看源代码和文档来回答关于 Effect TypeScript 框架的问题,而不是依赖记忆。
arxiv
14k帮你的智能体在 arXiv 上搜索、阅读、引用和跟踪学术论文,包括摘要、BibTeX 引用、PDF 下载和引用关系。
claude-code
14k帮你的智能体把编程任务交给 Claude Code 命令行工具,可以是一次性运行、交互式会话或后台任务。
codex
14k帮你的智能体在没有聊天窗口的情况下运行 OpenAI Codex 命令行工具,用于编程任务、脚本和自动化流程。