SuperAPI AI 工具集

migrate-to-uv

部署与运维

查看项目

更新于 10-16 09:15

技能介绍

用途

migrate-to-uv 用于将 Keboola 组件(基于 Docker、部署到 ECR)从 requirements.txt + pip 的依赖管理方式迁移到 pyproject.toml + uv 构建系统,并引入 ruff 进行代码检查。迁移后依赖通过 uv.lock 实现确定性锁定,构建过程可复现。

主要能力

  • 创建 pyproject.toml,使用 uv add 从 requirements.txt 填充依赖,自动将固定版本转换为 >= 范围并更新 uv.lock。
  • 将测试专用依赖(如 pytest、mock、freezegun、responses)从主依赖移入 dev 组。
  • 删除旧文件:requirements.txt、.flake8/flake8.cfg、旧构建脚本、docs/imgs/、部分 component_config 文件等。
  • 更新 .gitignore,添加 *.egg-info/、.venv/、.DS_Store、/data 等条目。
  • 将 Dockerfile 改造为多阶段构建(base/test/production):base 仅安装生产依赖,test 阶段额外安装 dev 依赖并在构建时运行 ruff check,production 阶段运行组件。
  • 更新 scripts/build_n_test.sh、tests/init.py 和 .github/workflows/push.yml,采用与多阶段 Dockerfile 匹配的多作业流水线。
  • 运行 ruff format 和 ruff check --fix 建立代码检查基线。
  • 与 canonical 模板(component-defaults)对齐,修复结构性差异并创建缺失文件(如 .pre-commit-config.yaml)。

使用方式

技能要求执行者自行使用可用工具完成所有步骤,不得委托或调用其他 agent(Phase 6 的 component-developer:component-defaults 除外)。步骤按提交划分:

  • Step 0:读取当前状态(cat requirements.txt、grep Dockerfile 中的 FROM python:、cat push.yml)。
  • Commit 1:创建 pyproject.toml(requires-python = "~=3.13.0",target-version = "py313",dependencies 先留空),用 uv add -r requirements.txt 填充依赖,将测试依赖移入 dev 组,删除旧文件,填充 component_config 的 URL,更新 .gitignore,提交。
  • Commit 2:更新 Dockerfile 为多阶段构建,更新 scripts/build_n_test.sh、tests/init.py、.github/workflows/push.yml,运行 uv sync --all-groups 校验锁文件,提交。
  • Commit 3:运行 ruff format . 和 ruff check --fix .,如有变更则提交。
  • Phase 6:通过 Task 工具加载 component-developer:component-defaults 返回的 canonical 模板,对比 Dockerfile、push.yml、build_n_test.sh、docker-compose.yml、.pre-commit-config.yaml,修复结构差异,保留组件特定内容,创建缺失文件,提交。
  • 验证:docker build --target test 并运行测试;可选构建 production 镜像。

适用场景

适用于需要将 Keboola Python 组件迁移到 uv 构建系统的开发者,尤其是希望获得确定性依赖、统一代码检查、多阶段 Docker 构建和标准化 CI 流水线的场景。

限制

  • 技能明确要求不得委托给其他 agent(component-builder、develop-component 等),仅 Phase 6 可使用 component-developer:component-defaults。
  • 必须完成所有步骤,文件不存在时静默跳过。
  • 依赖 Python 3.13(requires-python = "~=3.13.0",target-version = "py313")。
  • 需要 Docker、uv、ruff、git 等工具环境。
  • 关于收费、价格、平台支持范围等具体信息,资料中暂未提供。