Skip to content

Remove runtime pkg_resources dependency in default and server_ingester#7057

Merged
cdavalos7 merged 2 commits intotensorflow:masterfrom
0xmagnus91:fix/pkg-resources-removal-safe
Mar 5, 2026
Merged

Remove runtime pkg_resources dependency in default and server_ingester#7057
cdavalos7 merged 2 commits intotensorflow:masterfrom
0xmagnus91:fix/pkg-resources-removal-safe

Conversation

@0xmagnus91
Copy link
Contributor

Motivation for features / changes

Fixes #7003.

pkg_resources is removed in newer setuptools, which can break TensorBoard at import/runtime. This change removes runtime reliance on pkg_resources in the two affected code paths.

Technical description of changes

  • Replaced dynamic plugin discovery in tensorboard/default.py:
    • from pkg_resources.iter_entry_points(...)
    • to importlib.metadata.entry_points(...) with compatibility handling for different Python return shapes.
  • Replaced version parsing in tensorboard/data/server_ingester.py:
    • from pkg_resources.parse_version(...)
    • to packaging.version.parse(...).
  • Updated related tests:
    • tensorboard/default_test.py now patches _iter_entry_points and uses load()-style fake entry points.
    • tensorboard/version_test.py now validates PEP 440 behavior using packaging.version.
  • Updated Bazel deps to use expect_packaging_installed where packaging is now required.

Detailed steps to verify changes work correctly (as executed by you)

Executed locally in an isolated venv:

  • python -m py_compile tensorboard/default.py tensorboard/default_test.py tensorboard/data/server_ingester.py tensorboard/version_test.py
  • PYTHONPATH=. python tensorboard/version_test.py (passes)

Attempted but environment-limited locally:

  • bazel test //tensorboard:version_test //tensorboard:default_test //tensorboard/data:server_ingester_test (bazel not available in local shell)
  • Direct execution of default_test.py and server_ingester_test.py without Bazel-generated artifacts hit local environment/import constraints.

Alternate designs / implementations considered (or N/A)

  • N/A

@0xmagnus91
Copy link
Contributor Author

Added local validation results while workflow runs are pending maintainer approval for fork PR CI.

Local command executed:
bazel test //tensorboard:version_test //tensorboard:default_test //tensorboard/data:server_ingester_test

Result: all 3 targets passed locally.

Could a maintainer approve the pending workflow runs so required checks can execute on this PR? Thanks.

@@ -466,6 +464,11 @@ py_library(name = "expect_absl_testing_absltest_installed")
# `pip install setuptools`.
py_library(name = "expect_pkg_resources_installed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind removing this one, please?

def _iter_entry_points(group):
"""Returns entry points for a given group across Python versions."""
entry_points = metadata.entry_points()
if hasattr(entry_points, "select"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a comment clarifying why this check exists?

Maybe:

# In newer Python versions, `metadata.entry_points()` returns an `EntryPoints`
# object with a `select()` method.
# Before "selectable" entry points existed, it would return a dictionary.

self._path = path
self._version = (
pkg_resources.parse_version(version)
packaging_version.parse(version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to reformat these lines for the linter check to pass.

- Remove unused expect_pkg_resources_installed BUILD target
- Add clarifying comment for entry_points() version compatibility check
- Collapse ternary expression in server_ingester.py for readability
- Fix pre-existing Black formatting issues in touched files
@0xmagnus91
Copy link
Contributor Author

Thanks for the review! Pushed a follow-up commit addressing all three comments:

  1. Removed the expect_pkg_resources_installed target from tensorboard/BUILD
  2. Added the clarifying comment for the entry_points() version check in default.py
  3. Reformatted the ternary in server_ingester.py

Also fixed a few pre-existing Black formatting issues in the touched files (extra blank lines, unnecessary tuple parentheses) to help the lint-python-yaml-docs check pass.

@cdavalos7 cdavalos7 merged commit 29f809f into tensorflow:master Mar 5, 2026
35 of 38 checks passed
@alth-ansys
Copy link

alth-ansys commented Mar 5, 2026

Hi,

Is there any intention to produce a release (patch ?) following this PR by any chance ?

Many thanks for producing a fix for this issue either case 👍🏻

@arcra
Copy link
Member

arcra commented Mar 5, 2026

Our team is working on producing release 2.21 right now, but trying to update the protobuf dependency to match the one used by TensorFlow 2.21 has been challenging, since other dependency compatibility issues arise.

I'll ask the team to include this change in that release and/or produce a patch release afterwards.

@alth-ansys
Copy link

Thanks @arcra 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecated pkg_resources package

4 participants