Repository navigation
fix(py): cap anthropic dependency below 1.0 and require flask[async] #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb04988
fix(py): cap anthropic below 1.0 in genkit-anthropic
huangjeff5 e833d06
fix(py): depend on flask[async] in genkit-flask
huangjeff5 bcf3c1a
ci(py): install each wheel in an isolated venv
huangjeff5 28c570b
ci: add check_isolated_wheels step to python.yml workflow
huangjeff5 8f44abf
ci(py): fix dist directory lookup in check_isolated_wheels
huangjeff5 8588fe1
ci(py): drop monorepo py/ paths from check_isolated_wheels
huangjeff5 939ad1d
Update packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py
huangjeff5 184061f
test(anthropic): import Requirement for the specifier check
huangjeff5 699af56
Merge branch 'main' into fix/py-0.13.1-hotfix-pins
huangjeff5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/genkit-anthropic/tests/anthropic_sdk_contract_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.