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
2 changes: 1 addition & 1 deletion packages/genkit-a2ui/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ classifiers = [
]
dependencies = [
"genkit>=0.14.0,<2",
"pydantic>=2.11",
"pydantic>=2.11,<3",
]
description = "A2UI (Agent-to-UI) middleware for Genkit."
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-amazon-bedrock/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ classifiers = [
# botocore is imported directly (config, exceptions) and pins the floor that
# keeps the manual AWS_REGION lookup in _transport.py necessary: it did not read
# AWS_REGION itself until 1.41.
dependencies = ["genkit>=0.14.0,<2", "boto3>=1.37.24", "botocore>=1.37.24"]
dependencies = ["genkit>=0.14.0,<2", "boto3>=1.37.24,<2", "botocore>=1.37.24,<2"]
description = "Bedrock on Genkit"
keywords = [
"genkit",
Expand Down
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.14.0,<2", "anthropic>=0.96.0,<1"]
dependencies = ["genkit>=0.14.0,<2", "anthropic>=0.98.0,<1"]
description = "Claude on Genkit"
keywords = [
"genkit",
Expand Down
4 changes: 2 additions & 2 deletions packages/genkit-django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ classifiers = [
]
dependencies = [
"genkit>=0.14.0,<2",
"pydantic>=2.11",
"django>=5.0",
"pydantic>=2.11,<3",
"django>=5.0,<7",
]
description = "A Genkit flow as a Django view"
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-fastapi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
"Typing :: Typed",
"License :: OSI Approved :: Apache Software License",
]
dependencies = ["genkit>=0.14.0,<2", "pydantic>=2.11", "fastapi>=0.100.0"]
dependencies = ["genkit>=0.14.0,<2", "pydantic>=2.11,<3", "fastapi>=0.100.0,<1"]
description = "Hang flows and agents on the FastAPI app you already have"
keywords = [
"genkit",
Expand Down
4 changes: 2 additions & 2 deletions packages/genkit-flask/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ classifiers = [
]
dependencies = [
"genkit>=0.14.0,<2",
"pydantic>=2.11",
"flask[async]>=3.1.3",
"pydantic>=2.11,<3",
"flask[async]>=3.1.3,<4",
]
description = "Hang a Genkit flow on the Flask app you already have"
keywords = [
Expand Down
14 changes: 7 additions & 7 deletions packages/genkit-google-cloud/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ classifiers = [
dependencies = [
"genkit>=0.14.0,<2",
"genkit-otel>=0.14.0,<2",
"google-cloud-logging>=3.10.0",
"opentelemetry-api>=1.20.0",
"opentelemetry-sdk>=1.20.0",
"opentelemetry-exporter-gcp-trace>=1.9.0",
"opentelemetry-exporter-gcp-monitoring>=1.9.0",
"google-cloud-logging>=3.10.0,<4",
"opentelemetry-api>=1.39.0,<2",
"opentelemetry-sdk>=1.39.0,<2", # LogRecordExporter (renamed from LogExporter in 1.39)
"opentelemetry-exporter-gcp-trace>=1.9.0,<2",
"opentelemetry-exporter-gcp-monitoring>=1.9.0,<2",
"strenum>=0.4.15; python_version < '3.11'",
"opentelemetry-exporter-gcp-logging>=1.9.0a0",
"opentelemetry-exporter-gcp-logging>=1.12.0a0,<2", # first release compatible with sdk 1.39
"typing_extensions>=4.0",
]
description = "Cloud Trace, Cloud Logging, and Firestore sessions for Genkit"
Expand All @@ -70,7 +70,7 @@ version = "0.14.0"

[project.optional-dependencies]
# genkit_google_cloud.exp.FirestoreSessionStore. Telemetry needs none of it.
firestore = ["google-cloud-firestore>=2.14.0"]
firestore = ["google-cloud-firestore>=2.14.0,<3"]

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit-python/issues"
Expand Down
6 changes: 3 additions & 3 deletions packages/genkit-google-genai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ classifiers = [
]
dependencies = [
"genkit>=0.14.0,<2",
"google-genai>=2.14.0,<3",
"httpx>=0.28.1",
"pydantic>=2.11",
"google-genai>=2.17.0,<3",
"httpx>=0.28.1,<1", # public: http_client_factory returns httpx.AsyncClient
"pydantic>=2.11,<3",
"typing_extensions>=4.2",
]
description = "Gemini and Veo on Genkit"
Expand Down
4 changes: 2 additions & 2 deletions packages/genkit-mcp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"anyio>=4.9.0",
"anyio>=4.12.0", # below 4.12 a broken stdin isn't a BrokenResourceError
"exceptiongroup>=1.2.0; python_version < '3.11'",
"genkit>=0.14.0,<2",
"mcp>=1.26.0,<2",
"pydantic>=2.10.5",
"pydantic>=2.10.5,<3",
]
description = "Model Context Protocol client for Genkit. Exposes an MCP server's tools as Genkit tools."
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-ollama/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.14.0,<2", "ollama>=0.5.3,<1.0"]
dependencies = ["genkit>=0.14.0,<2", "ollama>=0.6.0,<1"]
description = "Ollama on Genkit"
keywords = [
"genkit",
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-openai/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.14.0,<2", "openai>=1.60.0,<3", "strenum>=0.4.15; python_version < '3.11'"]
dependencies = ["genkit>=0.14.0,<2", "openai>=1.99.2,<3", "strenum>=0.4.15; python_version < '3.11'"]
description = "OpenAI-compatible models on Genkit"
keywords = [
"genkit",
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-otel/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ classifiers = [
]
dependencies = [
"genkit>=0.14.0,<2",
"opentelemetry-api>=1.38.0",
"opentelemetry-api>=1.38.0,<2",
]
description = "OpenTelemetry GenAI semantic-conventions instrumentation for Genkit (traces, metrics, and message-content capture)."
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
]
dependencies = [
"pydantic>=2.11",
"pydantic>=2.11,<3",
"jsonschema>=4.23.0",
"partial-json-parser>=0.2.1.1.post5",
"json5>=0.10.0",
Expand Down
77 changes: 71 additions & 6 deletions scripts/check_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@
_EXACT_PIN_RE = re.compile(r'^(genkit(?:-[a-z0-9-]+)?)(?:\[[a-z0-9,_-]+\])?==([^,;\s]+)$')
_CAPPED_RANGE_RE = re.compile(r'^(genkit(?:-[a-z0-9-]+)?)(?:\[[a-z0-9,_-]+\])?>=([^,;\s]+),<([^,;\s]+)$')
_CORE_DEP_RE = re.compile(r'^genkit(?![a-z0-9-])')
_THIRD_PARTY_RE = re.compile(r'^\s*([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?\s*(.*)$')

# Third-party deps that must carry an upper cap in published packages, and the
# only ones allowed to. A dep is capped at the next major (`<1` while 0.x) when
# (1) integration target: a genkit package exists to wrap it, or
# (2) contract: users write code or files against it and hand them to genkit.
# Everything else is an internal implementation detail and stays floor-only, so
# users can take upstream fixes without waiting on a genkit release.
REQUIRED_CAPS: dict[str, str] = {
# (1) Integration targets.
'anthropic': 'integration target: genkit-anthropic',
'boto3': 'integration target: genkit-amazon-bedrock',
'botocore': 'integration target: genkit-amazon-bedrock',
'django': 'integration target: genkit-django',
'fastapi': 'integration target: genkit-fastapi',
'flask': 'integration target: genkit-flask',
'google-cloud-firestore': 'integration target: genkit-google-cloud',
'google-cloud-logging': 'integration target: genkit-google-cloud',
'google-genai': 'integration target: genkit-google-genai',
'mcp': 'integration target: genkit-mcp',
'ollama': 'integration target: genkit-ollama',
'openai': 'integration target: genkit-openai',
'opentelemetry-api': 'integration target: genkit-otel, genkit-google-cloud',
'opentelemetry-exporter-gcp-logging': 'integration target: genkit-google-cloud',
'opentelemetry-exporter-gcp-monitoring': 'integration target: genkit-google-cloud',
'opentelemetry-exporter-gcp-trace': 'integration target: genkit-google-cloud',
'opentelemetry-sdk': 'integration target: genkit-google-cloud',
# (2) Contract.
'dotpromptz': 'contract: users write .prompt files it evaluates',
'pydantic': 'contract: users define schemas as BaseModel subclasses',
}

# Caps that apply to one package only: the dep is a contract in that package's
# public API but an internal detail everywhere else, where it stays floor-only.
SCOPED_CAPS: dict[tuple[str, str], str] = {
('genkit-google-genai', 'httpx'): 'contract: http_client_factory returns an httpx.AsyncClient',
}


def _strip_toml_comment(line: str) -> str:
Expand Down Expand Up @@ -171,6 +208,27 @@ def _check_intra_repo_spec(
return None


def _check_third_party_spec(pkg_name: str, section: str, spec: str) -> str | None:
"""Validate a third-party dependency specifier against the bounds policy, returning an error if invalid."""
requirement = spec.split(';', 1)[0].strip()
if _INTRA_REPO_NAME_RE.match(requirement):
return None
m = _THIRD_PARTY_RE.match(requirement)
if not m:
return None
name = m.group(1).lower().replace('_', '-')
version_spec = m.group(2)
if not re.search(r'>=|==|~=', version_spec):
return f"{section}: '{spec}' has no floor (add '>=<oldest supported>')"
has_cap = bool(re.search(r'<|~=|==', version_spec))
reason = REQUIRED_CAPS.get(name) or SCOPED_CAPS.get((pkg_name, name))
if reason and not has_cap:
return f"{section}: '{spec}' must cap the next major ({reason})"
if has_cap and not reason:
return f"{section}: '{spec}' caps a dep not in REQUIRED_CAPS/SCOPED_CAPS; drop the cap or add it with a reason"
return None


def check_package(pkg_path: str, core_version: str) -> tuple[str, str, list[str]]:
"""Validate a single publishable package directory under packages/*."""
toml_path = os.path.join(pkg_path, 'pyproject.toml')
Expand Down Expand Up @@ -206,15 +264,22 @@ def check_package(pkg_path: str, core_version: str) -> tuple[str, str, list[str]
pkg_errors.append(f"dependencies: missing core 'genkit>={core_version},<{exp_cap}' dependency")

for spec in dependencies:
err = _check_intra_repo_spec(pkg_name, 'dependencies', spec, core_version)
if err:
pkg_errors.append(err)
for err in (
_check_intra_repo_spec(pkg_name, 'dependencies', spec, core_version),
_check_third_party_spec(pkg_name, 'dependencies', spec),
):
if err:
pkg_errors.append(err)

for extra_name in sorted(raw_opt_deps):
section = f'optional-dependencies.{extra_name}'
for obj in raw_opt_deps[extra_name]:
err = _check_intra_repo_spec(pkg_name, f'optional-dependencies.{extra_name}', str(obj), core_version)
if err:
pkg_errors.append(err)
for err in (
_check_intra_repo_spec(pkg_name, section, str(obj), core_version),
_check_third_party_spec(pkg_name, section, str(obj)),
):
if err:
pkg_errors.append(err)

return pkg_name, pkg_version, pkg_errors

Expand Down
73 changes: 68 additions & 5 deletions tests/version_bounds_guard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _make_workspace_fixture(py_root: Path, version: str = '0.12.0', *, include_e
py_root,
'genkit',
version,
dependencies=['pydantic>=2.11'],
dependencies=['pydantic>=2.11,<3'],
optional_dependencies=extras,
)
_write_pkg(
Expand All @@ -113,7 +113,7 @@ def _make_workspace_fixture(py_root: Path, version: str = '0.12.0', *, include_e
py_root,
'genkit-anthropic',
version,
dependencies=[f'genkit>={version},<{cap}', 'anthropic>=0.96.0'],
dependencies=[f'genkit>={version},<{cap}', 'anthropic>=0.96.0,<1'],
)
_write_pkg(
py_root,
Expand Down Expand Up @@ -178,11 +178,11 @@ def test_real_workspace_passes_consistency_and_extras_contract() -> None:
}
assert referenced_plugins == all_plugins

# genkit-openai bounds openai>=1.60.0,<3.
# genkit-openai bounds openai>=1.99.2,<3.
openai_project = consistency.load_pyproject(str(PY_DIR / 'packages' / 'genkit-openai' / 'pyproject.toml'))[
'project'
]
assert 'openai>=1.60.0,<3' in openai_project['dependencies']
assert 'openai>=1.99.2,<3' in openai_project['dependencies']


def test_bump_transition_0_12_0_to_0_13_0_rolls_floors_and_advances_minor_cap(tmp_path: Path) -> None:
Expand Down Expand Up @@ -289,6 +289,69 @@ def test_consistency_rejects_unbounded_or_misbounded_plugin_deps(
assert any(expected_substring in err for err in errors), errors


@pytest.mark.parametrize(
('dep', 'expected_substring'),
[
('anthropic>=0.96.0', 'must cap the next major'),
('pydantic>=2.11', 'must cap the next major'),
('starlette>=0.46.1,<1', 'caps a dep not in REQUIRED_CAPS'),
('httpx~=0.28', 'caps a dep not in REQUIRED_CAPS'),
('structlog', 'has no floor'),
],
)
def test_consistency_enforces_third_party_bounds_policy(
tmp_path: Path,
dep: str,
expected_substring: str,
) -> None:
_make_workspace_fixture(tmp_path, '0.12.0', include_evaluators=False)
_write_pkg(tmp_path, 'genkit-openai', '0.12.0', dependencies=['genkit>=0.12.0,<2', dep])

errors = _workspace_errors(tmp_path)
assert any(expected_substring in err for err in errors), errors


@pytest.mark.parametrize(
'dep',
[
'starlette>=0.46.1',
'openai>=1.60.0,<3',
"strenum>=0.4.15; python_version < '3.11'",
"uvloop>=0.21.0; sys_platform != 'win32'",
],
)
def test_consistency_accepts_policy_compliant_third_party_deps(tmp_path: Path, dep: str) -> None:
_make_workspace_fixture(tmp_path, '0.12.0', include_evaluators=False)
_write_pkg(tmp_path, 'genkit-openai', '0.12.0', dependencies=['genkit>=0.12.0,<2', dep])

assert _workspace_errors(tmp_path) == []


@pytest.mark.parametrize(
('pkg', 'dep', 'expected_substring'),
[
('genkit-google-genai', 'httpx>=0.28.1', 'must cap the next major'),
('genkit-google-genai', 'httpx>=0.28.1,<1', None),
('genkit-openai', 'httpx>=0.28.1,<1', 'caps a dep not in REQUIRED_CAPS'),
('genkit-openai', 'httpx>=0.28.1', None),
],
)
def test_consistency_scopes_package_caps_to_their_package(
tmp_path: Path,
pkg: str,
dep: str,
expected_substring: str | None,
) -> None:
_make_workspace_fixture(tmp_path, '0.12.0', include_evaluators=False)
_write_pkg(tmp_path, pkg, '0.12.0', dependencies=['genkit>=0.12.0,<2', dep])

errors = _workspace_errors(tmp_path)
if expected_substring is None:
assert errors == []
else:
assert any(expected_substring in err for err in errors), errors


def test_consistency_rejects_missing_py_typed_and_classifier(tmp_path: Path) -> None:
_make_workspace_fixture(tmp_path, '0.12.0', include_evaluators=False)
_write_pkg(
Expand Down Expand Up @@ -326,7 +389,7 @@ def test_consistency_rejects_unbounded_extra_and_stale_exact_pin(tmp_path: Path)
tmp_path,
'genkit',
'0.12.0',
dependencies=['pydantic>=2.11'],
dependencies=['pydantic>=2.11,<3'],
optional_dependencies={'openai': ['genkit-openai']},
)
_write_pkg(
Expand Down
Loading
Loading