Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions tensorboard/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ py_library(
srcs = ["default.py"],
srcs_version = "PY3",
deps = [
"//tensorboard:expect_pkg_resources_installed",
"//tensorboard/backend:experimental_plugin",
"//tensorboard/plugins/audio:audio_plugin",
"//tensorboard/plugins/core:core_plugin",
Expand Down Expand Up @@ -341,7 +340,6 @@ py_test(
deps = [
":default",
":test",
"//tensorboard:expect_pkg_resources_installed",
"//tensorboard/plugins:base_plugin",
],
)
Expand All @@ -361,7 +359,6 @@ py_test(
deps = [
":test",
":version",
"//tensorboard:expect_pkg_resources_installed",
],
)

Expand Down Expand Up @@ -455,11 +452,6 @@ py_library(name = "expect_absl_logging_installed")
# `pip install absl-py`
py_library(name = "expect_absl_testing_absltest_installed")

# This is a dummy rule used as a pkg-resources dependency in open-source.
# We expect pkg-resources to already be installed on the system, e.g., via
# `pip install setuptools`.
py_library(name = "expect_pkg_resources_installed")

# This is a dummy rule used as a pandas dependency in open-source.
# We expect pandas to already be installed on the system, e.g. via
# `pip install pandas`.
Expand Down
1 change: 0 additions & 1 deletion tensorboard/data/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ py_library(
":grpc_provider",
":ingester",
"//tensorboard:expect_grpc_installed",
"//tensorboard:expect_pkg_resources_installed",
"//tensorboard/data/proto:protos_all_py_pb2",
"//tensorboard/util:tb_logging",
],
Expand Down
19 changes: 5 additions & 14 deletions tensorboard/data/server_ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time

import grpc
import pkg_resources
from packaging.version import parse as parse_version

from tensorboard.data import grpc_provider
from tensorboard.data import ingester
Expand Down Expand Up @@ -152,10 +152,7 @@ def start(self):
if popen.poll() is not None:
msg = (_maybe_read_file(error_file_path) or "").strip()
if not msg:
msg = (
"exited with %d; check stderr for details"
% popen.poll()
)
msg = "exited with %d; check stderr for details" % popen.poll()
raise DataServerStartupError(msg)
logger.info("Polling for data server port (attempt %d)", i)
port_file_contents = _maybe_read_file(port_file_path)
Expand Down Expand Up @@ -230,11 +227,7 @@ def __init__(self, path, version):
it's on you to make sure that it's up to date.
"""
self._path = path
self._version = (
pkg_resources.parse_version(version)
if version is not None
else version
)
self._version = parse_version(version) if version is not None else version

@property
def path(self):
Expand All @@ -260,7 +253,7 @@ def at_least_version(self, required_version):
"""
if self._version is None:
return True
return self._version >= pkg_resources.parse_version(required_version)
return self._version >= parse_version(required_version)


def get_server_binary():
Expand All @@ -287,9 +280,7 @@ def get_server_binary():
else:
pkg_result = tensorboard_data_server.server_binary()
version = tensorboard_data_server.__version__
logging.info(
"Server binary (from Python package v%s): %s", version, pkg_result
)
logging.info("Server binary (from Python package v%s): %s", version, pkg_result)
if pkg_result is None:
raise NoDataServerError(
"TensorBoard data server not supported on this platform."
Expand Down
9 changes: 3 additions & 6 deletions tensorboard/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
for less repetition.
"""


import logging

import pkg_resources
from importlib import metadata

from tensorboard.plugins.audio import audio_plugin
from tensorboard.plugins.core import core_plugin
Expand Down Expand Up @@ -119,8 +118,6 @@ def get_dynamic_plugins():
[1]: https://packaging.python.org/specifications/entry-points/
"""
return [
entry_point.resolve()
for entry_point in pkg_resources.iter_entry_points(
"tensorboard_plugins"
)
entry_point.load()
for entry_point in metadata.entry_points().select(group="tensorboard_plugins")
]
23 changes: 13 additions & 10 deletions tensorboard/default_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
# ==============================================================================
"""Unit tests for `tensorboard.default`."""


from unittest import mock

import pkg_resources
from importlib import metadata

from tensorboard import default
from tensorboard.plugins import base_plugin
Expand All @@ -30,7 +29,7 @@ class FakePlugin(base_plugin.TBPlugin):
plugin_name = "fake"


class FakeEntryPoint(pkg_resources.EntryPoint):
class FakeEntryPoint(metadata.EntryPoint):
"""EntryPoint class that fake loads FakePlugin."""

@classmethod
Expand All @@ -40,10 +39,10 @@ def create(cls):
Returns:
instance of FakeEntryPoint
"""
return cls("foo", "bar")
return cls("foo", "bar", "tensorboard_plugins")

def resolve(self):
"""Returns FakePlugin instead of resolving module.
def load(self):
"""Returns FakePlugin instead of loading module.

Returns:
FakePlugin
Expand All @@ -52,13 +51,17 @@ def resolve(self):


class DefaultTest(test.TestCase):
@mock.patch.object(pkg_resources, "iter_entry_points")
def test_get_dynamic_plugin(self, mock_iter_entry_points):
mock_iter_entry_points.return_value = [FakeEntryPoint.create()]
@mock.patch.object(metadata, "entry_points")
def test_get_dynamic_plugin(self, mock_entry_points):
fake_eps = [FakeEntryPoint.create()]
mock_entry_points.return_value.select.return_value = fake_eps

actual_plugins = default.get_dynamic_plugins()

mock_iter_entry_points.assert_called_with("tensorboard_plugins")
mock_entry_points.assert_called_once()
mock_entry_points.return_value.select.assert_called_with(
group="tensorboard_plugins"
)
self.assertEqual(actual_plugins, [FakePlugin])


Expand Down
2 changes: 1 addition & 1 deletion tensorboard/pip_package/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ pillow
# 4.24.0 had an issue that broke our tests, so we should avoid that release:
# https://github.com/protocolbuffers/protobuf/issues/13485
protobuf >= 3.19.6, != 4.24.0
setuptools >= 41.0.0 # Note: provides pkg_resources as well as setuptools
setuptools >= 41.0.0
tensorboard-data-server >= 0.7.0, < 0.8.0
werkzeug >= 1.0.1
15 changes: 4 additions & 11 deletions tensorboard/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


import pkg_resources
from packaging.version import parse as parse_version

from tensorboard import test as tb_test
from tensorboard import version
Expand All @@ -22,21 +22,14 @@
class VersionTest(tb_test.TestCase):
def test_valid_pep440_version(self):
"""Ensure that our version is PEP 440-compliant."""
# pkg_resources.parse_version() doesn't have a public return type,
# so we get a handle to it by parsing known good and bad versions.
#
# Note: depending on the version of the module (which is bundled
# with setuptools), when called with a non-compliant version, it
# either returns a `LegacyVersion` (setuptools < 66) or raises an
# `InvalidVersion` exception (setuptools >= 66). Handle both cases.
compliant_version = pkg_resources.parse_version("1.0.0")
compliant_version = parse_version("1.0.0")
try:
legacy_version = pkg_resources.parse_version("arbitrary string")
legacy_version = parse_version("arbitrary string")
except Exception:
legacy_version = None
self.assertNotEqual(type(compliant_version), type(legacy_version))

tensorboard_version = pkg_resources.parse_version(version.VERSION)
tensorboard_version = parse_version(version.VERSION)
self.assertIsInstance(tensorboard_version, type(compliant_version))


Expand Down