AgentSkillsCN

python-pip-ci

为使用 pip 的 Python 项目生成 GitHub Actions 工作流。当您需要生成依赖安装基于虚拟环境的 CI 工作流时,可选用此功能。

SKILL.md
--- frontmatter
name: python-pip-ci
description: >
  GitHub Actions workflow steps for Python projects using pip.
  Use this skill when generating CI workflows that need pip-based
  dependency installation with virtual environment.

Python CI with pip

GitHub Actions Steps

Setup and Install

yaml
- uses: actions/checkout@v4

- name: Set up Python
  uses: actions/setup-python@v5
  with:
    python-version: "{PYTHON_VERSION}"

- name: Create venv and install dependencies
  run: |
    python -m venv .venv
    source .venv/bin/activate
    pip install --upgrade pip
    pip install {DEPENDENCIES}

Running Commands

After setup, activate the venv before running commands:

yaml
- name: Run command
  run: |
    source .venv/bin/activate
    {COMMAND}

Variables

VariableDescriptionDefault
{PYTHON_VERSION}Python version3.12
{DEPENDENCIES}Space-separated packages-
{COMMAND}Command to run-

Best Practices

  • Always upgrade pip first (pip install --upgrade pip)
  • Use python -m venv .venv for consistent venv location
  • Each step needs source .venv/bin/activate (state doesn't persist between steps)
  • For caching, add cache: 'pip' to setup-python (requires requirements.txt)