mcpField
U
uv-advanced-dependencies

uv-advanced-dependencies

github.com/laurigates开发59302 次安装1 天前更新
代码仓库

关于 uv-advanced-dependencies

面向 uv 项目的高级依赖管理速查技能,供 Python 开发者配置 Git 和路径来源、依赖组、索引、约束及构建依赖。

主要功能

  1. 01Git、URL 和路径依赖
  2. 02可编辑安装
  3. 03依赖组与额外依赖
  4. 04自定义及私有索引
  5. 05版本约束与构建依赖

适用场景

  1. 01从 Git 分支或标签添加库
  2. 02基于本地检出版本开发
  3. 03区分测试与文档依赖
  4. 04从私有索引安装软件包

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/laurigates/claude-plugins --skill uv-advanced-dependencies

安装后在 Claude Code 中输入/uv-advanced-dependencies确认已加载。

附带文件REFERENCE.md

详细介绍

UV 高级依赖

UV 项目高级依赖场景快速参考。

何时使用此技能

在以下情况使用此技能……在以下情况改用针对性更强的同类技能……
将依赖项固定到 git URL、分支或标签,或以可编辑模式安装添加常规 PyPI 依赖项——使用 uv-project-management
配置 [tool.uv.sources]、依赖组、额外依赖或自定义索引在工作区成员之间共享源声明——使用 uv-workspaces
设置私有软件包索引或构建时约束使用 --with 依赖项运行临时脚本——使用 uv-run

此技能适用的情况

  • Git 仓库依赖项
  • 本地路径依赖项
  • 可编辑安装
  • 依赖项约束
  • 自定义软件包索引
  • 依赖组和额外依赖
  • 构建依赖项

快速参考

Git 依赖项
# Add from Git repository
uv add git+https://github.com/psf/requests
uv add git+https://github.com/pallets/flask@main
uv add git+ssh://[email protected]/user/[email protected]

# Specific branch, tag, or commit
uv add git+https://github.com/user/repo@feature-branch
uv add git+https://github.com/user/[email protected]
uv add git+https://github.com/user/repo@abc123
路径依赖项
# Add from local path
uv add --editable ./local-package
uv add ../another-project
uv add /absolute/path/to/package

# Non-editable path
uv add --no-editable ./local-package
依赖组
# Add to named group
uv add --group docs sphinx mkdocs
uv add --group test pytest pytest-cov

# Install specific groups
uv sync --group docs
uv sync --group test --group docs

# Install all groups
uv sync --all-groups
额外依赖(可选依赖项)
# Install package with extras
uv add 'fastapi[all]'
uv add 'sqlalchemy[postgresql,mypy]'

# Define extras in pyproject.toml
[project.optional-dependencies]
dev = ["pytest", "ruff"]
docs = ["mkdocs", "mkdocs-material"]
约束文件
# Apply version constraints
uv pip compile requirements.in --constraint constraints.txt

# constraints.txt example:
# numpy<2.0
# pandas==2.0.3
自定义索引
[tool.uv]
index-url = "https://pypi.org/simple"
extra-index-url = [
    "https://custom.pypi.org/simple",
]

pyproject.toml 中的 Git 依赖项

[project]
dependencies = [
    "my-package",
]

[tool.uv.sources]
my-package = { git = "https://github.com/user/my-package" }

# With branch
my-package = { git = "https://github.com/user/my-package", branch = "main" }

# With tag
my-package = { git = "https://github.com/user/my-package", tag = "v1.0.0" }

# With commit
my-package = { git = "https://github.com/user/my-package", rev = "abc123" }

pyproject.toml 中的路径依赖项

[project]
dependencies = [
    "my-local-package",
]

[tool.uv.sources]
my-local-package = { path = "../my-local-package" }

# Editable (default for paths)
my-local-package = { path = "../my-local-package", editable = true }

# Non-editable
my-local-package = { path = "../my-local-package", editable = false }

依赖组

[dependency-groups]
dev = [
    "pytest>=7.0",
    "pytest-cov>=4.0",
    "ruff>=0.1.0",
]
docs = [
    "mkdocs-material>=9.0",
    "mkdocstrings[python]>=0.24",
]
test = [
    "pytest-asyncio>=0.21",
    "pytest-mock>=3.12",
]

URL 依赖项

# Add from direct URL
uv add https://files.pythonhosted.org/packages/.../requests-2.31.0.tar.gz

# In pyproject.toml
[tool.uv.sources]
my-package = { url = "https://example.com/my-package-1.0.tar.gz" }

私有软件包索引

[tool.uv]
# Primary index
index-url = "https://pypi.org/simple"

# Additional indexes
extra-index-url = [
    "https://${PRIVATE_TOKEN}@private.pypi.org/simple",
]

# Find links
find-links = [
    "https://download.pytorch.org/whl/cu118",
]
# Set token via environment
export PRIVATE_TOKEN="secret"
uv sync

构建依赖项

[build-system]
requires = [
    "setuptools>=68",
    "wheel",
    "Cython>=3.0",
]
build-backend = "setuptools.build_meta"

常见模式

从本地检出版本进行开发
# Clone dependency
git clone https://github.com/user/lib.git ../lib

# Add as editable
cd my-project
uv add --editable ../lib
单体仓库路径依赖项
[tool.uv.sources]
my-core = { path = "packages/core" }
my-utils = { path = "packages/utils" }
混合来源
[project]
dependencies = [
    "fastapi",          # PyPI
    "my-lib",           # Git
    "my-local",         # Path
]

[tool.uv.sources]
my-lib = { git = "https://github.com/user/my-lib" }
my-local = { path = "../my-local" }

解析策略

[tool.uv]
# Highest compatible (default)
resolution = "highest"

# Lowest compatible
resolution = "lowest"

# Lowest direct, highest transitive
resolution = "lowest-direct"

另请参阅

  • uv-project-management - 基本依赖管理
  • uv-workspaces - 工作区成员依赖项
  • python-packaging - 构建系统配置

参考资料

评论

支持 Markdown