Commit Graph

1 Commits

Author SHA1 Message Date
Artem Oroberts 8eeff35b35 feat: Demonstrate CodeExecutor customization for environment setup
This change introduces a powerful pattern for customizing code execution environments by extending a base `CodeExecutor`. It showcases how to inject setup code to prepare the environment before a user's code is run, enabling advanced use cases that require specific configurations.

As a practical example, this change implements `CustomCodeExecutor`, a subclass of `VertexAiCodeExecutor`, to solve the problem of rendering non-standard characters in `matplotlib` plots (Issue #2993). The custom executor programmatically adds a Japanese font to the `matplotlib` font manager at runtime.

This is achieved by overriding the `execute_code` method to add font files to execution input and prepend the necessary font-loading logic. This approach is not limited to fonts and can be adapted for other setup tasks.

Fixes: #2993
PiperOrigin-RevId: 825240143
2025-10-28 15:53:03 -07:00