一个使用 uv 管理的现代 Python 项目模板
cursor-dirs/ ├── src/ │ └── cursor_dirs/ # 项目源代码 │ ├── __init__.py │ └── main.py ├── tests/ # 测试代码 │ ├── __init__.py │ └── test_main.py ├── pyproject.toml # 项目配置和依赖 ├── uv.lock # 锁定依赖版本 ├── README.md # 项目说明 └── .gitignore # Git 忽略文件
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.sh | iex"
# 或者使用 pip
pip install uv
首次克隆项目后:
# 克隆项目
git clone <project-url>
cd cursor-dirs
# 安装所有依赖(包括开发依赖)
uv sync --group dev
# 运行项目
uv run python -m cursor_dirs.main
日常开发:
# 安装项目依赖(自动使用镜像源配置)
uv sync
# 添加新依赖
uv add requests
# 运行主程序
uv run python -m cursor_dirs.main
# 或者使用项目脚本
uv run cursor-dirs
⚠️ 注意:请使用 uv sync/uv add 而不是 uv pip install,这样才能享受项目配置的镜像源加速!
# 运行测试
uv run pytest
# 代码格式化
uv run black src/ tests/
# 代码检查
uv run ruff check src/ tests/
# 类型检查
uv run mypy src/
# 一键格式化和检查
uv run ruff check --fix src/ tests/ && uv run black src/ tests/
# 添加运行时依赖
uv add requests pandas
# 添加开发依赖
uv add --group dev pytest black
# 添加特定版本
uv add "django>=4.0,<5.0"
# 移除运行时依赖
uv remove requests
# 移除开发依赖
uv remove --group dev pytest
# 更新所有依赖
uv sync --upgrade
# 更新特定包
uv add requests@latest
项目已预配置中国镜像源以加速包下载:
配置位置:pyproject.toml 中的 [tool.uv] 部分
| 操作 | 命令 |
|---|---|
| 初始化项目 | uv init |
| 安装依赖 | uv sync |
| 添加包 | uv add <package> |
| 移除包 | uv remove <package> |
| 运行脚本 | uv run <script> |
| 运行测试 | uv run pytest |
| 查看依赖树 | uv tree |
| 更新lockfile | uv lock |
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)本项目使用 MIT 许可证 - 查看 LICENSE 文件了解详情
Happy Coding! 🐍✨