Skip to content

Commit 1e22fc3

Browse files
committed
Avoid discrepancies due to importlib.metadata.version not working i… (#6894)
…nternally If `protobuf` isn't installed locally, the underlying call to `json_format.MessageToJson` will still fail.
1 parent 6bc92af commit 1e22fc3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tensorboard/plugin_util.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,14 @@ def proto_to_json(proto):
201201
Args:
202202
proto: The proto to convert to JSON.
203203
"""
204-
current_version = metadata.version("protobuf")
204+
# Fallback for internal usage, since non third-party code doesn't really
205+
# have the concept of "versions" in a monorepo. The package version chosen
206+
# below is the minimum value to choose the non-deprecated kwarg to
207+
# `MessageToJson`.
208+
try:
209+
current_version = metadata.version("protobuf")
210+
except metadata.PackageNotFoundError:
211+
current_version = "5.0.0"
205212
if version.parse(current_version) >= version.parse("5.0.0"):
206213
return json_format.MessageToJson(
207214
proto,

0 commit comments

Comments
 (0)