Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
103 changes: 103 additions & 0 deletions bin/check_isolated_wheels
Original file line number Diff line number Diff line change
@@ -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 <module>`. 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
Comment thread
huangjeff5 marked this conversation as resolved.
Resolved
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."
2 changes: 1 addition & 1 deletion packages/genkit-anthropic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 54 additions & 0 deletions packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion packages/genkit-flask/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
32 changes: 32 additions & 0 deletions packages/genkit-flask/tests/flask_dependency_test.py
Original file line number Diff line number Diff line change
@@ -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]
11 changes: 8 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading