From a7b5e65bd5ecc7420b59fb14fb2b38c8c8ee82d6 Mon Sep 17 00:00:00 2001 From: Nick Groszewski Date: Mon, 12 Aug 2024 17:24:14 -0400 Subject: [PATCH] =?UTF-8?q?Avoid=20discrepancies=20due=20to=20`importlib.m?= =?UTF-8?q?etadata.version`=20not=20working=20i=E2=80=A6=20(#6894)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …nternally If `protobuf` isn't installed locally, the underlying call to `json_format.MessageToJson` will still fail. --- tensorboard/plugin_util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tensorboard/plugin_util.py b/tensorboard/plugin_util.py index 97f2e6abe8..10458c94c4 100644 --- a/tensorboard/plugin_util.py +++ b/tensorboard/plugin_util.py @@ -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,