diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89011bf0f5..d25d3641a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,15 +36,17 @@ jobs: if: (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.release_pr && github.ref == 'refs/heads/release-please--branches--main') || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: true - name: Install dependencies - run: rye sync --all-features + run: ./scripts/ci-bootstrap - name: Run lints run: ./scripts/lint @@ -61,26 +63,26 @@ jobs: with: persist-credentials: false - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: true - name: Install dependencies - run: rye sync --all-features + run: ./scripts/ci-bootstrap - name: Run build - run: rye build + run: uv build - name: Validate Python version metadata - run: rye run python scripts/utils/validate-python-version-wheel.py + run: .venv/bin/python scripts/utils/validate-python-version-wheel.py - name: Validate Bedrock wheel - run: rye run python scripts/utils/validate-bedrock-wheel.py + run: .venv/bin/python scripts/utils/validate-bedrock-wheel.py - name: Validate HTTPX2 wheel on Python 3.10 - run: rye run python scripts/utils/validate-httpx2-wheel.py + run: .venv/bin/python scripts/utils/validate-httpx2-wheel.py - name: Set up Python 3.9 for resolver rejection uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 @@ -154,6 +156,8 @@ jobs: python-version: ["3.10", "3.14"] steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} id: setup-python @@ -161,19 +165,18 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: false - name: Select Python ${{ matrix.python-version }} run: | - rye toolchain register "${{ steps.setup-python.outputs.python-path }}" - rye pin --relaxed --no-update-requires-python "${{ matrix.python-version }}" + echo 'UV_PYTHON=${{ steps.setup-python.outputs.python-path }}' >> "$GITHUB_ENV" - name: Bootstrap - run: ./scripts/bootstrap + run: ./scripts/ci-bootstrap - name: Run tests run: ./scripts/test @@ -185,6 +188,8 @@ jobs: if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.release_pr && github.ref == 'refs/heads/release-please--branches--main') || github.event.pull_request.head.repo.fork steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false - name: Set up Python 3.14 id: setup-python @@ -192,17 +197,15 @@ jobs: with: python-version: '3.14' - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: false - name: Install HTTPX2 test dependencies run: | - rye toolchain register "${{ steps.setup-python.outputs.python-path }}" - rye pin --relaxed --no-update-requires-python 3.14 - rye sync --all-features + UV_PYTHON="${{ steps.setup-python.outputs.python-path }}" ./scripts/ci-bootstrap - name: Run tests with HTTPX and HTTPX2 installed env: @@ -219,28 +222,30 @@ jobs: name: examples environment: ci runs-on: ${{ startsWith(github.repository, 'stainless-sdks/') && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.repository == 'openai/openai-python' && (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') + if: github.repository == 'openai/openai-python' && github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: true - name: Install dependencies run: | - rye sync --all-features + ./scripts/ci-bootstrap - env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} run: | - rye run python examples/demo.py + .venv/bin/python examples/demo.py - env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} run: | - rye run python examples/async_demo.py + .venv/bin/python examples/async_demo.py python-policy: timeout-minutes: 5 @@ -289,24 +294,23 @@ jobs: python-version: ${{ matrix.python-version }} allow-prereleases: ${{ matrix.experimental }} - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: false - name: Select Python ${{ matrix.python-version }} run: | - rye toolchain register "${{ steps.setup-python.outputs.python-path }}" - rye pin --relaxed --no-update-requires-python "${{ matrix.python-version }}" + echo 'UV_PYTHON=${{ steps.setup-python.outputs.python-path }}' >> "$GITHUB_ENV" - name: Install dependencies - run: rye sync --all-features + run: ./scripts/ci-bootstrap - name: Smoke-test the supported runtime run: | - rye run python -c 'import openai; from openai import AsyncOpenAI, OpenAI' - rye run pytest -o addopts= --quiet \ + .venv/bin/python -c 'import openai; from openai import AsyncOpenAI, OpenAI' + .venv/bin/pytest -o addopts= --quiet \ tests/test_client.py \ tests/test_streaming.py \ tests/lib/test_pydantic.py diff --git a/.github/workflows/detect-breaking-changes.yml b/.github/workflows/detect-breaking-changes.yml index db660c03cf..e4d332ba65 100644 --- a/.github/workflows/detect-breaking-changes.yml +++ b/.github/workflows/detect-breaking-changes.yml @@ -39,65 +39,21 @@ jobs: with: # Ensure we can check out the pull request base in the script below. fetch-depth: ${{ env.FETCH_DEPTH }} + persist-credentials: false - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 + - name: Set up uv + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: - version: '0.44.0' + version: '0.12.5' enable-cache: true - name: Install dependencies run: | - rye sync --all-features + ./scripts/ci-bootstrap - name: Detect removed symbols run: | - rye run python scripts/detect-breaking-changes.py "$BASE_SHA" + .venv/bin/python scripts/detect-breaking-changes.py "$BASE_SHA" - name: Detect breaking changes run: | test -f ./scripts/detect-breaking-changes || { echo "Missing scripts/detect-breaking-changes"; exit 1; } ./scripts/detect-breaking-changes "$BASE_SHA" - - agents_sdk: - runs-on: 'ubuntu-latest' - name: Detect Agents SDK regressions - if: github.repository == 'openai/openai-python' && (github.event_name == 'pull_request' || (inputs.release_pr && github.ref == 'refs/heads/release-please--branches--main')) - steps: - # Setup this sdk - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - with: - path: openai-python - - - name: Set up Rye - uses: eifinger/setup-rye@c694239a43768373e87d0103d7f547027a23f3c8 - with: - version: '0.44.0' - enable-cache: true - working-directory: openai-python - - - name: Install dependencies - working-directory: openai-python - run: | - rye sync --all-features - - # Setup the agents lib - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - with: - repository: openai/openai-agents-python - path: openai-agents-python - - - name: Setup uv - uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 - with: - enable-cache: true - - - name: Link to local SDK - working-directory: openai-agents-python - run: uv add ../openai-python - - - name: Install dependencies - working-directory: openai-agents-python - run: make sync - - - name: Run integration type checks - working-directory: openai-agents-python - run: make mypy diff --git a/noxfile.py b/noxfile.py index 53bca7ff2a..13f6347b7a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,9 +1,15 @@ +from pathlib import Path + import nox @nox.session(reuse_venv=True, name="test-pydantic-v1") def test_pydantic_v1(session: nox.Session) -> None: - session.install("-r", "requirements-dev.lock") + # The CI bridge resolves a runtime-specific lock outside the source distribution. + requirements = Path(".venv/requirements-dev.lock") + if not requirements.is_file(): + requirements = Path("requirements-dev.lock") + session.install("-r", str(requirements)) session.install("pydantic<2") session.run("pytest", "--showlocals", "--ignore=tests/functional", *session.posargs) diff --git a/scripts/ci-bootstrap b/scripts/ci-bootstrap new file mode 100755 index 0000000000..9021d2eab8 --- /dev/null +++ b/scripts/ci-bootstrap @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." + +# Bridge the old Rye baseline until the main-to-next toolchain sync. +uv venv --allow-existing --python "${UV_PYTHON:-$(cat .python-version)}" .venv + +# Rye re-resolved this non-universal lock after selecting each matrix runtime. +# Expose its dev dependency array as a uv group without changing project metadata. +requirements_dir=$(mktemp -d) +trap 'rm -rf "$requirements_dir"' EXIT +{ + printf '[dependency-groups]\n' + sed -n '/^dev-dependencies = \[/,/^]/p' pyproject.toml | sed '1s/dev-dependencies/dev/' +} > "$requirements_dir/pyproject.toml" +# Preserve the reviewed root lock and keep the CI-only lock out of distributions. +cp requirements-dev.lock .venv/requirements-dev.lock +# Require compatible wheels: older NumPy metadata omits its Python upper bound. +uv pip compile pyproject.toml --all-extras --only-binary=:all: \ + --group "$requirements_dir/pyproject.toml:dev" \ + --python .venv/bin/python --output-file .venv/requirements-dev.lock +printf '\n-e .\n' >> .venv/requirements-dev.lock +uv pip sync --python .venv/bin/python .venv/requirements-dev.lock diff --git a/scripts/lint b/scripts/lint index 275a2bf1a1..3ecc450a22 100755 --- a/scripts/lint +++ b/scripts/lint @@ -6,11 +6,13 @@ cd "$(dirname "$0")/.." if [ "$1" = "--fix" ]; then echo "==> Running lints with --fix" - rye run fix:ruff + .venv/bin/ruff check --fix . else echo "==> Running lints" - rye run lint + .venv/bin/ruff check . + PATH="$PWD/.venv/bin:$PATH" ./scripts/run-pyright + .venv/bin/mypy . fi echo "==> Making sure it imports" -rye run python -c 'import openai' +.venv/bin/python -c 'import openai' diff --git a/scripts/test b/scripts/test index daff369239..342485f8ae 100755 --- a/scripts/test +++ b/scripts/test @@ -59,7 +59,7 @@ if [ "${OPENAI_TEST_HTTP_CLIENT:-httpx}" = "httpx2" ]; then fi echo "==> Running tests" -rye run pytest "$@" +.venv/bin/pytest "$@" echo "==> Running Pydantic v1 tests" -rye run nox -s test-pydantic-v1 -- "$@" +.venv/bin/nox -s test-pydantic-v1 -- "$@"