Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion Dockerfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ RUN uv pip install --no-build-isolation --no-cache --system "git+https://github.

# b/404590350: Ray and torchtune have conflicting cli named `tune`. `ray` is not part of Colab's base image. Re-install `tune` to ensure the torchtune CLI is available by default.
# b/468367647: Unpin protobuf, version greater than v5.29.5 causes issues with numerous packages
# grpcio-tools must be installed here (not in kaggle_requirements.txt) to stay version-compatible with protobuf.
RUN uv pip install --system --force-reinstall --no-cache --no-deps torchtune
RUN uv pip install --system --force-reinstall --no-cache "protobuf==5.29.5"
RUN uv pip install --system --force-reinstall --no-cache "protobuf==5.29.5" "grpcio-tools>=1.60.0"

# Adding non-package dependencies:
ADD clean-layer.sh /tmp/clean-layer.sh
Expand Down
59 changes: 59 additions & 0 deletions tests/test_grpcio_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import subprocess
import sys
import tempfile
import unittest

PROTO_CONTENT = """\
syntax = "proto3";

package smoketest;

message PingRequest {
string message = 1;
}

message PingReply {
string message = 1;
}

service PingService {
rpc Ping (PingRequest) returns (PingReply);
}
"""


class TestGrpcioTools(unittest.TestCase):
def test_compile_proto(self):
with tempfile.TemporaryDirectory() as tmpdir:
proto_path = os.path.join(tmpdir, "ping.proto")
with open(proto_path, "w") as f:
f.write(PROTO_CONTENT)

subprocess.check_call([
sys.executable, "-m", "grpc_tools.protoc",
f"--proto_path={tmpdir}",
f"--python_out={tmpdir}",
f"--grpc_python_out={tmpdir}",
f"--pyi_out={tmpdir}",
"ping.proto",
])

pb2_path = os.path.join(tmpdir, "ping_pb2.py")
pb2_grpc_path = os.path.join(tmpdir, "ping_pb2_grpc.py")
pyi_path = os.path.join(tmpdir, "ping_pb2.pyi")
self.assertTrue(os.path.exists(pb2_path))
self.assertTrue(os.path.exists(pb2_grpc_path))
self.assertTrue(os.path.exists(pyi_path))

sys.path.insert(0, tmpdir)
try:
import ping_pb2
import ping_pb2_grpc

req = ping_pb2.PingRequest(message="hello")
self.assertEqual(req.message, "hello")
self.assertTrue(hasattr(ping_pb2_grpc, "PingServiceStub"))
self.assertTrue(hasattr(ping_pb2_grpc, "PingServiceServicer"))
finally:
sys.path.remove(tmpdir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is redundat.

Given you are using a tempfile.TemporaryDirectory(), it should delete the directory after the "with" claude exits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I removed that call and the now-pointless try/finally.