Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated fix for refs/heads/bazel_7_path #230

Open
wants to merge 1 commit into
base: bazel_7_path
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions bazel/protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def get_staged_proto_file(label, context, source_file):
# probably even in different repositories)
prefix = _make_prefix(source_file.owner)
copied_proto = context.actions.declare_file(source_file.path[len(prefix):])

# print(">>[xuan_testing] copy proto from: " + str(source_file.path) + " to :" + str(copied_proto.path))
# copy proto from: src/proto/grpc/channelz/channelz.proto
# to :bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto
Expand Down Expand Up @@ -274,6 +275,7 @@ def declare_out_files(protos, context, generated_file_format):
"""

out_file_paths = []

# print("[xuan_testing] gen_path: " + str(context.genfiles_dir.path))
for proto in protos:
if not is_in_virtual_imports(proto):
Expand All @@ -295,6 +297,7 @@ def declare_out_files(protos, context, generated_file_format):
# )
# print("[xuan_testing] path: " + str(path))
# _virtual_imports/channelz_proto_descriptors/channelz_pb2_grpc.py

return [
context.actions.declare_file(
proto_path_to_generated_filename(
Expand Down Expand Up @@ -324,12 +327,15 @@ def get_out_dir(protos, context):
fail("Proto sources must be either all virtual imports or all real")
if at_least_one_virtual:
out_dir = get_include_directory(protos[0])

# print(" [xuan_testing] include_directory: " + str(out_dir))
# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
ws_root = protos[0].owner.workspace_root

# print(" [xuan_testing] ws_root: " + str(ws_root))
# ws_root:
prefix = "/" + _make_prefix(protos[0].owner) + _VIRTUAL_IMPORTS[1:]

# print(" [xuan_testing] prefix: " + str(prefix))
# /src/proto/grpc/channelz/_virtual_imports/
return struct(
Expand Down
22 changes: 18 additions & 4 deletions bazel/python_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
load("@rules_python//python:py_info.bzl", "PyInfo")
load("@com_google_protobuf//bazel:py_proto_library.bzl", protobuf_py_proto_library = "py_proto_library")

load(
"//bazel:protobuf.bzl",
"declare_out_files",
Expand All @@ -26,10 +25,9 @@ load(
"get_proto_arguments",
"get_staged_proto_file",
"includes_from_deps",
"is_well_known",
"is_in_virtual_imports",
"is_well_known",
"protos_from_context",
"proto_path_to_generated_filename",
)

_VIRTUAL_IMPORTS = "/_virtual_imports/"
Expand Down Expand Up @@ -204,12 +202,15 @@ def _generate_pb2_grpc_src_impl(context):
is_virtual = False
for proto in protos:
print(">>[xuan_testing] pb2_grpc protos: " + str(proto))

# <generated file src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto>
# <generated file src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz.proto>
print(">>[xuan_testing] pb2_grpc protos.path: " + str(proto.path))

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto
# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz.proto
print(">>[xuan_testing] pb2_grpc protos.dirname: " + str(proto.dirname))

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1
if is_in_virtual_imports(proto):
Expand All @@ -223,14 +224,17 @@ def _generate_pb2_grpc_src_impl(context):
# [<generated file src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py>]

print(">>>>>>[xuan_testing] pb2_grpc out_files.dirname: " + str(out_files[0].dirname))

# bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors
# bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1
# bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1
if is_virtual:
root, relative = out_files[0].path.split(_VIRTUAL_IMPORTS, 2)

# root: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1
# relative: channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py
result = root + _VIRTUAL_IMPORTS + relative.split("/", 1)[0]

# bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors
print(">>>>>>[xuan_testing] result: " + str(result))
out_path = result
Expand All @@ -240,32 +244,38 @@ def _generate_pb2_grpc_src_impl(context):
arguments = []
tools = [context.executable._protoc, context.executable._grpc_plugin]
out_dir = get_out_dir(protos, context)

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
print("[xuan_testing] pb2_grpc out_dir: " + str(out_dir))

# struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors",
# path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors")
# struct(import_path = None, path = "bazel-out/k8-fastbuild/bin")
# struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors",
# path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors")
print("[xuan_testing] pb2_grpc out_dir.path: " + str(out_dir.path))

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
# bazel-out/k8-fastbuild/bin
# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
print("[xuan_testing] pb2_grpc context.genfiles_dir.path: " + str(context.genfiles_dir.path))

# bazel-out/k8-fastbuild/bin
if out_dir.import_path:
# is virtual imports
out_path = out_dir.path
else:
out_path = context.genfiles_dir.path
print(">>>>>>[xuan_testing] pb2_grpc out_path: " + str(out_path))

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
# bazel-out/k8-fastbuild/bin
# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
# Fix 1:
# out_path = out_files[0].dirname
if is_virtual:
out_path = result

# bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors
# Fix 2:
# out_path = result
Expand All @@ -285,17 +295,19 @@ def _generate_pb2_grpc_src_impl(context):
"--proto_path={}".format(get_include_directory(i))
for i in includes
]

# bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors
arguments.append("--proto_path={}".format(context.genfiles_dir.path))
print("[xuan_testing] pb2_grpc proto_path: " + str(context.genfiles_dir.path))

# bazel-out/k8-fastbuild/bin
arguments += get_proto_arguments(protos, context.genfiles_dir.path)
print("[xuan_testing] pb2_grpc get_proto_arguments: " + str(arguments))
# --plugin=protoc-gen-PLUGIN=bazel-out/k8-opt-exec-ST-a828a81199fe/bin/src/compiler/grpc_python_plugin
# --PLUGIN_out=XXX
# --proto_path=bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors (Old & Fixed)
# --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/any_proto
# --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/duration_proto
# --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/duration_proto
# --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/timestamp_proto
# --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/wrappers_proto
# --proto_path=bazel-out/k8-fastbuild/bin
Expand Down Expand Up @@ -330,9 +342,11 @@ def _generate_pb2_grpc_src_impl(context):
# Expected: src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py

imports = []

# Fix 1:
if is_virtual:
import_path = out_path

# Handles virtual import cases
if out_path.startswith(context.genfiles_dir.path):
import_path = import_path[len(context.genfiles_dir.path) + 1:]
Expand Down
5 changes: 3 additions & 2 deletions examples/python/debug/asyncio_get_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import argparse
import asyncio
import logging
import os

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import channelz_pb2
import channelz_pb2_grpc
else:
Expand Down
5 changes: 3 additions & 2 deletions examples/python/debug/get_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

import argparse
import logging
import os

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import channelz_pb2
import channelz_pb2_grpc
else:
Expand Down
6 changes: 4 additions & 2 deletions examples/python/health_checking/greeter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
"""gRPC Python helloworld.Greeter client with health checking."""

import logging
import os
from time import sleep

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import health_pb2
import health_pb2_grpc
else:
from grpc_health.v1 import health_pb2
from grpc_health.v1 import health_pb2_grpc

import helloworld_pb2
import helloworld_pb2_grpc

Expand Down
6 changes: 4 additions & 2 deletions examples/python/health_checking/greeter_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@

from concurrent import futures
import logging
import os
import threading
from time import sleep

import grpc
from grpc_health.v1 import health
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import health_pb2
import health_pb2_grpc
else:
from grpc_health.v1 import health_pb2
from grpc_health.v1 import health_pb2_grpc

import helloworld_pb2
import helloworld_pb2_grpc

Expand Down
6 changes: 4 additions & 2 deletions examples/python/xds/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
import argparse
from concurrent import futures
import logging
import os
import socket

import grpc
from grpc_health.v1 import health
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import health_pb2
import health_pb2_grpc
else:
from grpc_health.v1 import health_pb2
from grpc_health.v1 import health_pb2_grpc

from grpc_reflection.v1alpha import reflection
import helloworld_pb2
import helloworld_pb2_grpc
Expand Down
2 changes: 1 addition & 1 deletion src/proto/grpc/channelz/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ grpc_proto_library(
proto_library(
name = "channelz_proto_descriptors",
srcs = ["channelz.proto"],
strip_import_prefix = "/src/proto/grpc/channelz",
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:wrappers_proto",
],
strip_import_prefix = "/src/proto/grpc/channelz",
)

filegroup(
Expand Down
1 change: 0 additions & 1 deletion src/proto/grpc/reflection/v1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ proto_library(
strip_import_prefix = "/src/proto/grpc/reflection/v1",
)


filegroup(
name = "reflection_proto_file",
srcs = [
Expand Down
6 changes: 4 additions & 2 deletions src/python/grpcio_channelz/grpc_channelz/v1/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.
"""AsyncIO version of Channelz servicer."""

import os

from grpc.experimental import aio
from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import channelz_pb2 as _channelz_pb2
import channelz_pb2_grpc as _channelz_pb2_grpc
else:
Expand Down
7 changes: 5 additions & 2 deletions src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
# limitations under the License.
"""Channelz debug service implementation in gRPC Python."""

import os

from google.protobuf import json_format
import grpc
from grpc._cython import cygrpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import channelz_pb2 as _channelz_pb2
import channelz_pb2_grpc as _channelz_pb2_grpc
else:
from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2
from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc


class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer):
"""Servicer handling RPCs for service statuses."""

Expand Down
5 changes: 3 additions & 2 deletions src/python/grpcio_channelz/grpc_channelz/v1/channelz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.
"""Channelz debug service implementation in gRPC Python."""

import os
import sys

import grpc
from grpc_channelz.v1._servicer import ChannelzServicer
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import channelz_pb2_grpc as _channelz_pb2_grpc
else:
from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc
Expand Down
5 changes: 3 additions & 2 deletions src/python/grpcio_health_checking/grpc_health/v1/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

import asyncio
import collections
import os
from typing import MutableMapping

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import health_pb2 as _health_pb2
import health_pb2_grpc as _health_pb2_grpc
else:
Expand Down
5 changes: 3 additions & 2 deletions src/python/grpcio_health_checking/grpc_health/v1/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"""Reference implementation for health checking in gRPC Python."""

import collections
import os
import sys
import threading

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import health_pb2 as _health_pb2
import health_pb2_grpc as _health_pb2_grpc
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
# limitations under the License.
"""The AsyncIO version of the reflection servicer."""

import os
from typing import AsyncIterable

import grpc
import os
if os.environ.get('BUILD_SYSTEM') == 'Bazel':

if os.environ.get("BUILD_SYSTEM") == "Bazel":
import reflection_pb2 as _reflection_pb2
else:
from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2

from grpc_reflection.v1alpha._base import BaseReflectionServicer


Expand Down
Loading