You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixup_generated_files.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435
  1. from pathlib import Path
  2. from typing import Dict
  3. this_file_dir = Path(__file__).parent
  4. files = [
  5. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2_grpc.py",
  6. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2_grpc.pyi",
  7. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2.py",
  8. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/agent_worker_pb2.pyi",
  9. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2_grpc.py",
  10. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2_grpc.pyi",
  11. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2.py",
  12. this_file_dir / "packages/autogen-ext/src/autogen_ext/runtimes/grpc/protos/cloudevent_pb2.pyi",
  13. ]
  14. substitutions: Dict[str, str] = {
  15. "\nimport agent_worker_pb2 as agent__worker__pb2\n": "\nfrom . import agent_worker_pb2 as agent__worker__pb2\n",
  16. "\nimport agent_worker_pb2\n": "\nfrom . import agent_worker_pb2\n",
  17. "\nimport cloudevent_pb2 as cloudevent__pb2\n": "\nfrom . import cloudevent_pb2 as cloudevent__pb2\n",
  18. "\nimport cloudevent_pb2\n": "\nfrom . import cloudevent_pb2\n",
  19. }
  20. def main():
  21. for file in files:
  22. with open(file, "r") as f:
  23. content = f.read()
  24. print("Fixing imports in file:", file)
  25. for old, new in substitutions.items():
  26. content = content.replace(old, new)
  27. with open(file, "w") as f:
  28. f.write(content)