diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index b0efdb502..1a360229a 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -219,6 +219,9 @@ jobs: - name: Build and verify distributions run: ./bin/build_dists + - name: Install each wheel in an isolated venv + run: ./bin/check_isolated_wheels + - name: Verify wheel contents run: | ERRORS=0 diff --git a/bin/check_isolated_wheels b/bin/check_isolated_wheels new file mode 100755 index 000000000..a7545c0e5 --- /dev/null +++ b/bin/check_isolated_wheels @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# Install each built genkit wheel into its own fresh venv and smoke-test it. +# +# The workspace venv holds every package's dependencies (genkit-django pulls in +# asgiref, for example), which hides a package that forgets to declare one. +# Run after build_dists. Usage: bin/check_isolated_wheels [dist_dir] + +set -euo pipefail + +TOP_DIR=$(git rev-parse --show-toplevel) +DIST_DIR=$(cd "${1:-${TOP_DIR}/dist}" && pwd) +PYTHON_VERSION=${PYTHON_VERSION:-3.12} +WORK_DIR=$(mktemp -d) +trap 'rm -rf "${WORK_DIR}"' EXIT + +core_wheels=("${DIST_DIR}"/genkit-[0-9]*.whl) +if [[ ! -e "${core_wheels[0]}" ]]; then + echo "Error: no genkit core wheel in ${DIST_DIR}" >&2 + exit 1 +fi + +# Package-specific smoke beyond `import `. Must not touch the network. +smoke_script() { + case "$1" in + genkit_flask) + # Flask runs async views only with asgiref (flask[async]). + cat <<'PY' +from flask import Flask +from genkit import Genkit +from genkit_flask import genkit_flask_handler + +ai = Genkit() +app = Flask(__name__) + + +@app.post('/greet') +@genkit_flask_handler(ai) +@ai.flow() +async def greet(name: str) -> str: + return f'Hello {name}' + + +resp = app.test_client().post('/greet', json={'data': 'Ada'}) +assert resp.status_code == 200, (resp.status_code, resp.get_data(as_text=True)[:500]) +PY + ;; + genkit_anthropic) + # genkit-anthropic forwards these kwargs to messages.create(). + cat <<'PY' +import inspect + +from anthropic.resources.messages import AsyncMessages +from genkit_anthropic import AnthropicConfig + +missing = AnthropicConfig.CREATE_KWARGS - inspect.signature(AsyncMessages.create).parameters.keys() +assert not missing, f'installed anthropic SDK no longer accepts {sorted(missing)}' +PY + ;; + *) + echo "import $1" + ;; + esac +} + +failed=() +for wheel in "${DIST_DIR}"/genkit*.whl; do + module=$(basename "${wheel}" | cut -d- -f1) + venv="${WORK_DIR}/${module}" + echo "==> ${module}" + uv venv --quiet --python "${PYTHON_VERSION}" "${venv}" + # Pass the local core wheel explicitly so it wins over the same version on PyPI. + if ! uv pip install --quiet --python "${venv}/bin/python" --find-links "${DIST_DIR}" \ + "${wheel}" "${core_wheels[0]}"; then + failed+=("${module} (install)") + continue + fi + if ! smoke_script "${module}" | "${venv}/bin/python" -W error::RuntimeWarning -; then + failed+=("${module} (smoke)") + fi +done + +if ((${#failed[@]})); then + echo "Isolated wheel check failed:" >&2 + printf ' - %s\n' "${failed[@]}" >&2 + exit 1 +fi +echo "All wheels install and import in isolation." diff --git a/packages/genkit-anthropic/pyproject.toml b/packages/genkit-anthropic/pyproject.toml index 451b30a2b..e2fbe7149 100644 --- a/packages/genkit-anthropic/pyproject.toml +++ b/packages/genkit-anthropic/pyproject.toml @@ -43,7 +43,7 @@ classifiers = [ "Typing :: Typed", "License :: OSI Approved :: Apache Software License", ] -dependencies = ["genkit>=0.13.0,<2", "anthropic>=0.96.0"] +dependencies = ["genkit>=0.13.0,<2", "anthropic>=0.96.0,<1"] description = "Claude on Genkit" keywords = [ "genkit", diff --git a/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py new file mode 100644 index 000000000..3636ba861 --- /dev/null +++ b/packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py @@ -0,0 +1,54 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +"""What the plugin assumes about the installed ``anthropic`` SDK. + +anthropic 1.0 dropped ``temperature``/``top_p``/``top_k`` from +``messages.create()`` and moved to httpx2. These tests fail if the declared +``anthropic`` range admits such a release before the plugin is adapted. +""" + +import inspect +import re +from collections.abc import Callable +from importlib.metadata import requires + +import httpx +import pytest +from anthropic import DefaultAsyncHttpxClient +from anthropic.resources.beta.messages import AsyncMessages as AsyncBetaMessages +from anthropic.resources.messages import AsyncMessages +from genkit_anthropic import AnthropicConfig +from packaging.requirements import Requirement + + +@pytest.mark.parametrize('create', [AsyncMessages.create, AsyncBetaMessages.create], ids=['messages', 'beta']) +def test_sdk_create_accepts_every_forwarded_kwarg(create: Callable[..., object]) -> None: + """Every ``CREATE_KWARGS`` key is a named parameter of ``create()``.""" + missing = sorted(AnthropicConfig.CREATE_KWARGS - inspect.signature(create).parameters.keys()) + assert not missing, f'{create.__module__}.create() no longer accepts {missing}' + + +def test_sdk_transport_is_httpx() -> None: + """The ``except httpx.*`` handlers in ``_models.py`` only fire on an httpx transport.""" + assert issubclass(DefaultAsyncHttpxClient, httpx.AsyncClient) + + +def test_declared_anthropic_range_excludes_1x() -> None: + """``genkit-anthropic`` caps ``anthropic`` below 1.0 until it supports 1.x.""" + reqs = [Requirement(r) for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)] + assert len(reqs) == 1, reqs + assert '1.0.0' not in reqs[0].specifier, reqs[0] diff --git a/packages/genkit-flask/pyproject.toml b/packages/genkit-flask/pyproject.toml index ea949f69f..2ac13ff24 100644 --- a/packages/genkit-flask/pyproject.toml +++ b/packages/genkit-flask/pyproject.toml @@ -47,7 +47,7 @@ classifiers = [ dependencies = [ "genkit>=0.13.0,<2", "pydantic>=2.11", - "flask>=3.1.3", + "flask[async]>=3.1.3", ] description = "Hang a Genkit flow on the Flask app you already have" keywords = [ diff --git a/packages/genkit-flask/tests/flask_dependency_test.py b/packages/genkit-flask/tests/flask_dependency_test.py new file mode 100644 index 000000000..5fd9f592d --- /dev/null +++ b/packages/genkit-flask/tests/flask_dependency_test.py @@ -0,0 +1,32 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +"""genkit-flask must pull in Flask's async extra on its own. + +``genkit_flask_handler`` returns an ``async def`` view, which Flask runs only +when ``asgiref`` is installed. The workspace venv gets ``asgiref`` from +genkit-django, so this checks the declared metadata rather than the venv. +""" + +import re +from importlib.metadata import requires + + +def test_declares_flask_async_extra() -> None: + """``genkit-flask`` requires ``flask[async]``, not bare ``flask``.""" + reqs = [r for r in requires('genkit-flask') or [] if re.match(r'flask\b', r, re.IGNORECASE)] + assert len(reqs) == 1, reqs + assert re.match(r'flask\s*\[\s*async\s*\]', reqs[0], re.IGNORECASE), reqs[0] diff --git a/uv.lock b/uv.lock index c2562173a..81049fd0d 100644 --- a/uv.lock +++ b/uv.lock @@ -1501,6 +1501,11 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7f/9c/34f6962f9b9e9c71f6e5ed806e0d0ff03c9d1b0b2340088a0cf4bce09b18/flask-3.1.3-py3-none-any.whl", hash = "sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c", size = 103424, upload-time = "2026-02-19T05:00:56.027Z" }, ] +[package.optional-dependencies] +async = [ + { name = "asgiref" }, +] + [[package]] name = "flask-hello" version = "0.2.0" @@ -1717,7 +1722,7 @@ dependencies = [ [package.metadata] requires-dist = [ - { name = "anthropic", specifier = ">=0.96.0" }, + { name = "anthropic", specifier = ">=0.96.0,<1" }, { name = "genkit", editable = "packages/genkit" }, ] @@ -1761,14 +1766,14 @@ name = "genkit-flask" version = "0.13.0" source = { editable = "packages/genkit-flask" } dependencies = [ - { name = "flask" }, + { name = "flask", extra = ["async"] }, { name = "genkit" }, { name = "pydantic" }, ] [package.metadata] requires-dist = [ - { name = "flask", specifier = ">=3.1.3" }, + { name = "flask", extras = ["async"], specifier = ">=3.1.3" }, { name = "genkit", editable = "packages/genkit" }, { name = "pydantic", specifier = ">=2.11" }, ]