Repository navigation
refactor(py)!: plugin packages expose only their top-level module - #6671
Conversation
There was a problem hiding this comment.
Code Review
This pull request performs a comprehensive refactoring across multiple Genkit Python packages (including genkit-amazon-bedrock, genkit-django, genkit-evaluators, genkit-fastapi, genkit-flask, genkit-google-cloud, genkit-ollama, and genkit-vertexai) to mark internal modules as private by prefixing their filenames and imports with an underscore (_). It also updates all corresponding references in source code, tests, and configuration files (such as pyproject.toml), and simplifies public imports in documentation (e.g., importing ModelGarden directly from genkit_vertexai). I have no feedback to provide as there are no review comments.
3a11d40 to
8c2891c
Compare
c496460 to
c764a9b
Compare
c764a9b to
542d5a9
Compare
542d5a9 to
14df3f6
Compare
14df3f6 to
ec39a5e
Compare
aa22719 to
d0ec735
Compare
built_in_formats moves to _formats/_builtin.py; imports point at defining modules.
dbde3f7 to
8070dd8
Compare
# Conflicts: # py/packages/genkit-google-cloud/src/genkit_google_cloud/telemetry/__init__.py # py/packages/genkit-vertexai/tests/model_garden/anthropic_generate_test.py # py/packages/genkit-vertexai/tests/model_garden/client_test.py # py/packages/genkit-vertexai/tests/model_garden/model_garden_test.py
apascal07
left a comment
There was a problem hiding this comment.
py/pyproject.toml lines 483-487 turn off ty unresolved-import for all of packages/genkit-vertexai/** because of the model_garden relative imports this PR removes; ty check . passes at this head without it, and leaving it lets a broken vertexai import through. Line 252 ignores F401 for packages/genkit/src/genkit/_ai/__init__.py, which does not exist.
…_plugin.py Co-authored-by: Alex Pascal <apascal07@gmail.com>
|
@apascal07 dropped both pyproject overrides in 1c5a2b1: the vertexai ty |
# Conflicts: # py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/__init__.py # py/packages/genkit-amazon-bedrock/tests/plugin_test.py # py/packages/genkit-ollama/tests/plugin_api_test.py
…lic surface The Python plugins on main export only what a caller needs and take flat keyword arguments instead of nested option objects (#6671, #6706). The client now does the same. define_mcp_client and McpClient take command, args, env and cwd as keyword arguments and build the stdio config internally. The provider name is also the tool name prefix, as in the Go plugin, so tool_prefix and the tool_prefix property go away, and the name has to satisfy the tool name rule as well as the selector rule. disabled goes away: not calling define_mcp_client does the same. create_mcp_client goes away. An unregistered client has no use on its own while generate(tools=) takes names rather than actions, and McpClient is still there for the host to build clients without registering each. dynamic_action_provider becomes private: no caller outside the package needs it. The package exports McpClient and define_mcp_client. Errors are GenkitError with a status, as for the other plugins after #6710, so the error classes are no longer exported. A test pins the exported names, replacing the smoke test main deleted.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…lic surface The Python plugins on main export only what a caller needs and take flat keyword arguments instead of nested option objects (#6671, #6706). The client now does the same. define_mcp_client and McpClient take command, args, env and cwd as keyword arguments and build the stdio config internally. The provider name is also the tool name prefix, as in the Go plugin, so tool_prefix and the tool_prefix property go away, and the name has to satisfy the tool name rule as well as the selector rule. disabled goes away: not calling define_mcp_client does the same. create_mcp_client goes away. An unregistered client has no use on its own while generate(tools=) takes names rather than actions, and McpClient is still there for the host to build clients without registering each. dynamic_action_provider becomes private: no caller outside the package needs it. The package exports McpClient and define_mcp_client. Errors are GenkitError with a status, as for the other plugins after #6710, so the error classes are no longer exported. A test pins the exported names, replacing the smoke test main deleted.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…lic surface The Python plugins on main export only what a caller needs and take flat keyword arguments instead of nested option objects (#6671, #6706). The client now does the same. define_mcp_client and McpClient take command, args, env and cwd as keyword arguments and build the stdio config internally. The provider name is also the tool name prefix, as in the Go plugin, so tool_prefix and the tool_prefix property go away, and the name has to satisfy the tool name rule as well as the selector rule. disabled goes away: not calling define_mcp_client does the same. create_mcp_client goes away. An unregistered client has no use on its own while generate(tools=) takes names rather than actions, and McpClient is still there for the host to build clients without registering each. dynamic_action_provider becomes private: no caller outside the package needs it. The package exports McpClient and define_mcp_client. Errors are GenkitError with a status, as for the other plugins after #6710, so the error classes are no longer exported. A test pins the exported names, replacing the smoke test main deleted.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
…ping The host follows the same surface rules as the client: no exported nested config, flat keyword arguments, and only names a caller needs (#6671, #6706). define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of the mcpServers block Claude Desktop and Cursor read, so a block loaded from one of those files passes straight through. Each entry is validated into the internal stdio config, so a misspelt key still fails without echoing values. connect takes command, args, env and cwd as keyword arguments, as define_mcp_client does. The mapping key is the server name and its tool name prefix, as in the Go plugin. Keys are unique, so the shared-prefix check and tool_prefix go away. McpHostServer and create_mcp_host go away, server_names goes (tests read the host's clients), and dynamic_action_provider becomes private. The package now exports McpClient, McpHost, define_mcp_client and define_mcp_host, which the exports test pins.
Plugin packages now expose only their package root (plus
expwhere a plugin has experimental pieces). Imports from the root keep working unchanged:Importing a submodule path now raises
ModuleNotFoundError:genkit_amazon_bedrock.{config, converters, embedders, image, model_info, models, plugin, rerank, stream, transport}genkit_ollama.{constants, embedders, models, plugin_api}genkit_flask.handler,genkit_django.handler,genkit_fastapi.handlergenkit_evaluators.plugingenkit_google_cloud.telemetry,genkit_google_cloud.session_storegenkit_vertexai.model_garden,genkit_vertexai.constantsDecisions
expfor experimental pieces), so a submodule import was never needed. Moving the internals behind the root lets them change without breaking your app.__init__.py:genkit_vertexai._model_garden,genkit_openai._models,genkit_google_genai._models(and_context_caching),genkit_google_genai._evaluators,genkit_google_cloud._telemetry, and core'sgenkit._ai._formats. An__init__.pyre-export made an internal package look like an API. Imports go to the defining module, e.g.genkit._ai._formats._builtin.built_in_formats. Wheels still ship the modules.genkit_fastapi.handlerorgenkit_google_cloud.telemetry.*now needsgenkit_fastapi._handler/genkit_google_cloud._telemetry.*. Better: filter on the package prefix, e.g.genkit_fastapi.Layout only; no behavior changes. The Bedrock and Ollama surface changes that used to ride along are split out into the PRs stacked on top.