Skip to content

Commit

Permalink
Avoid discrepancies due to importlib.metadata.version not working i…
Browse files Browse the repository at this point in the history
…nternally

If `protobuf` isn't installed locally, the underlying call to
`json_format.MessageToJson` will still fail.
  • Loading branch information
groszewn committed Aug 12, 2024
1 parent 572c00b commit 2d24301
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tensorboard/plugin_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ def proto_to_json(proto):
Args:
proto: The proto to convert to JSON.
"""
current_version = metadata.version("protobuf")
# Fallback for internal usage, since non third-party code doesn't really
# have the concept of "versions" in a monorepo. The package version chosen
# below is the minimum value to choose the non-deprecated kwarg to
# `MessageToJson`.
try:
current_version = metadata.version("protobuf")
except metadata.PackageNotFoundError:
current_version = "5.0.0"
if version.parse(current_version) >= version.parse("5.0.0"):
return json_format.MessageToJson(
proto,
Expand Down

0 comments on commit 2d24301

Please sign in to comment.