Skip to content

Commit

Permalink
Improve grpc type checking (#5189)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored Jan 24, 2025
1 parent 06d5ac3 commit 1982f1b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
35 changes: 35 additions & 0 deletions python/fixup_generated_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path
from typing import Dict

this_file_dir = Path(__file__).parent

files = [
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2_grpc.py",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2_grpc.pyi",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2.py",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2.pyi",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2_grpc.py",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2_grpc.pyi",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2.py",
this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2.pyi",
]

substitutions: Dict[str, str] = {
"\nimport agent_worker_pb2 as agent__worker__pb2\n": "\nfrom . import agent_worker_pb2 as agent__worker__pb2\n",
"\nimport agent_worker_pb2\n": "\nfrom . import agent_worker_pb2\n",
"\nimport cloudevent_pb2 as cloudevent__pb2\n": "\nfrom . import cloudevent_pb2 as cloudevent__pb2\n",
"\nimport cloudevent_pb2\n": "\nfrom . import cloudevent_pb2\n",
}


def main():
for file in files:
with open(file, "r") as f:
content = f.read()

print("Fixing imports in file:", file)
for old, new in substitutions.items():
content = content.replace(old, new)

with open(file, "w") as f:
f.write(content)

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

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

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

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

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

6 changes: 5 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ samples-code-check = """pyright ./samples"""

check = ["fmt", "lint", "pyright", "mypy", "test", "markdown-code-lint", "samples-code-check"]

gen-proto = "python -m grpc_tools.protoc --python_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --grpc_python_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --mypy_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --mypy_grpc_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --proto_path ../protos/ agent_worker.proto --proto_path ../protos/ cloudevent.proto"
gen-proto = [
{ cmd = "python -m grpc_tools.protoc --python_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --grpc_python_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --mypy_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --mypy_grpc_out=./packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos --proto_path ../protos/ agent_worker.proto --proto_path ../protos/ cloudevent.proto" },
{ script = "fixup_generated_files:main" }
]


gen-proto-samples = "python -m grpc_tools.protoc --python_out=./samples/core_xlang_hello_python_agent/protos --grpc_python_out=./samples/core_xlang_hello_python_agent/protos --mypy_out=./samples/core_xlang_hello_python_agent/protos --mypy_grpc_out=./samples/core_xlang_hello_python_agent/protos --proto_path ../protos/ agent_events.proto"

Expand Down

0 comments on commit 1982f1b

Please sign in to comment.