Skip to content
Draft
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
5 changes: 5 additions & 0 deletions bazel/common/proto_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,18 @@ def _toolchain_type(proto_lang_toolchain_info):
else:
return None

def _to_py_proto_name(name):
"""Normalizes a proto name to be Python-safe (replacing '-' with '_' and '.' with '/')."""
return name.replace("-", "_").replace(".", "/")

proto_common = struct(
compile = _compile,
declare_generated_files = _declare_generated_files,
check_collocated = _check_collocated,
experimental_should_generate_code = _experimental_should_generate_code,
experimental_filter_sources = _experimental_filter_sources,
get_import_path = _get_import_path,
to_py_proto_name = _to_py_proto_name,
ProtoLangToolchainInfo = ProtoLangToolchainInfo,
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = toolchains.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION,
INCOMPATIBLE_PASS_TOOLCHAIN_TYPE = True,
Expand Down
4 changes: 2 additions & 2 deletions bazel/private/oss/py_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def _py_proto_aspect_impl(target, ctx):
actions = ctx.actions,
proto_info = proto_info,
extension = "_pb2.py",
name_mapper = lambda name: name.replace("-", "_").replace(".", "/"),
name_mapper = proto_common.to_py_proto_name,
)

# Generate pyi files
generated_stubs = proto_common.declare_generated_files(
actions = ctx.actions,
proto_info = proto_info,
extension = "_pb2.pyi",
name_mapper = lambda name: name.replace("-", "_").replace(".", "/"),
name_mapper = proto_common.to_py_proto_name,
)

# Handles multiple repository and virtual import cases
Expand Down
Loading