diff --git a/tensorboard/pip_package/requirements.txt b/tensorboard/pip_package/requirements.txt index a19090f321..a55e3dfbec 100644 --- a/tensorboard/pip_package/requirements.txt +++ b/tensorboard/pip_package/requirements.txt @@ -20,14 +20,14 @@ absl-py >= 0.4 grpcio >= 1.48.2 markdown >= 2.6.8 numpy >= 1.12.0 +packaging # NOTE: this version must be >= the protoc version in our WORKSPACE file. # At the same time, any constraints we specify here must allow at least some # version to be installed that is also compatible with TensorFlow's constraints: # https://github.com/tensorflow/tensorflow/blob/25adc4fccb4b0bb5a933eba1d246380e7b87d7f7/tensorflow/tools/pip_package/setup.py#L101 # 4.24.0 had an issue that broke our tests, so we should avoid that release: # https://github.com/protocolbuffers/protobuf/issues/13485 -# 5.26.0 introduced a breaking change, so we restricted it for now. See issue #6808 for details. -protobuf >= 3.19.6, != 4.24.0, < 5.0.0 +protobuf >= 3.19.6, != 4.24.0 setuptools >= 41.0.0 # Note: provides pkg_resources as well as setuptools # A dependency of our vendored packages. This lower bound has not been correctly # vetted, but I wanted to be the least restrictive we can, since it's not a new diff --git a/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py b/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py index 697c36f969..6215416e95 100644 --- a/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py +++ b/tensorboard/plugins/custom_scalar/custom_scalars_plugin.py @@ -21,7 +21,8 @@ this plugin. """ - +from importlib.metadata import version as importlib_version +from packaging import version import re from google.protobuf import json_format @@ -318,9 +319,16 @@ def layout_impl(self, ctx, experiment): title_to_category[category.title] = category if merged_layout: - return json_format.MessageToJson( - merged_layout, including_default_value_fields=True - ) + current_protobuf_version = importlib_version("protobuf") + if version.parse(current_protobuf_version) < version.parse("5.0"): + return json_format.MessageToJson( + merged_layout, including_default_value_fields=True + ) + else: + return json_format.MessageToJson( + merged_layout, + always_print_fields_with_no_presence=True, + ) else: # No layout was found. return {} diff --git a/tensorboard/plugins/hparams/hparams_plugin.py b/tensorboard/plugins/hparams/hparams_plugin.py index d11e048099..f6187c28aa 100644 --- a/tensorboard/plugins/hparams/hparams_plugin.py +++ b/tensorboard/plugins/hparams/hparams_plugin.py @@ -18,7 +18,8 @@ this plugin. """ - +from importlib.metadata import version as importlib_version +from packaging import version import json @@ -116,14 +117,24 @@ def get_experiment_route(self, request): request_proto = _parse_request_argument( request, api_pb2.GetExperimentRequest ) + response_proto = get_experiment.Handler( + ctx, + self._context, + experiment_id, + request_proto, + ).run() + current_protobuf_version = importlib_version("protobuf") + if version.parse(current_protobuf_version) < version.parse("5.0"): + response = json_format.MessageToJson( + response_proto, including_default_value_fields=True + ) + else: + response = json_format.MessageToJson( + response_proto, always_print_fields_with_no_presence=True + ) return http_util.Respond( request, - json_format.MessageToJson( - get_experiment.Handler( - ctx, self._context, experiment_id, request_proto - ).run(), - including_default_value_fields=True, - ), + response, "application/json", ) except error.HParamsError as e: @@ -139,14 +150,24 @@ def list_session_groups_route(self, request): request_proto = _parse_request_argument( request, api_pb2.ListSessionGroupsRequest ) + response_proto = list_session_groups.Handler( + ctx, + self._context, + experiment_id, + request_proto, + ).run() + current_protobuf_version = importlib_version("protobuf") + if version.parse(current_protobuf_version) < version.parse("5.0"): + response = json_format.MessageToJson( + response_proto, including_default_value_fields=True + ) + else: + response = json_format.MessageToJson( + response_proto, always_print_fields_with_no_presence=True + ) return http_util.Respond( request, - json_format.MessageToJson( - list_session_groups.Handler( - ctx, self._context, experiment_id, request_proto - ).run(), - including_default_value_fields=True, - ), + response, "application/json", ) except error.HParamsError as e: