⭐⭐⭐⭐⭐

Beyond Hypermodern: Python is easy now

来源: rdrn.me | 日期: 2024-07-19 (更新于 2026)

Python uv Ruff 工具链 教程

背景

四年前,"Hypermodern Python" 系列文章介绍了当时最新的 Python 最佳实践,但需要安装 20+ 包、配置 30+ 项。现在终于简单了!

核心信息:用 uv 替代 pyenv + Poetry,用 Ruff 替代 black + isort + flake8。Python 开发从未如此简单。

现代 Python 工具栈

1. uv - 包管理革命

# 安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# 创建项目
uv init postmodern
cd postmodern
uv sync

2. Ruff - Linting 和 Formatting 合一

uv run ruff format      # 格式化
uv run ruff check --fix # 检查修复

3. Pyright - 类型检查

4. Poe the Poet - 任务运行器

uv 尚未内置任务运行功能,Poe 是很好的替代品:

[tool.poe.tasks]
fmt = "ruff format"
lint = "ruff check --fix"
check = "pyright"
test = "pytest"
all = [{ref="fmt"}, {ref="lint"}, {ref="check"}, {ref="test"}]

版本选择建议

推荐模板

github.com/carderne/postmodern-python - 开箱即用的现代 Python 项目模板

资源