Skip to content

Replace pkg_resources with os.path for config file lookup#5510

Open
Mr-Neutr0n wants to merge 2 commits intofacebookresearch:mainfrom
Mr-Neutr0n:fix/replace-pkg-resources-with-importlib
Open

Replace pkg_resources with os.path for config file lookup#5510
Mr-Neutr0n wants to merge 2 commits intofacebookresearch:mainfrom
Mr-Neutr0n:fix/replace-pkg-resources-with-importlib

Conversation

@Mr-Neutr0n
Copy link

Summary

  • Removes dependency on deprecated pkg_resources from setuptools
  • Replaces pkg_resources.resource_filename() with simple os.path.join() using __file__
  • setuptools 81 (scheduled for 2025-12) will remove pkg_resources entirely

Related Issue

Fixes #5494

Technical Details

Since the configs directory is already symlinked/copied into detectron2/model_zoo/ during package installation via package_data, we can simply use os.path.dirname(__file__) to locate it at runtime. This is simpler and more maintainable than using importlib.resources.

Test plan

  • Verify from detectron2 import model_zoo works without warning
  • Verify model_zoo.get_config_file() returns correct paths
  • Test with setuptools < 81 (current) and simulate setuptools 81+ (pkg_resources removed)

pkg_resources is deprecated and will be removed in setuptools 81
(scheduled for 2025-12). Replace pkg_resources.resource_filename with
a simple os.path.join using __file__ since the configs directory is
already symlinked/copied into model_zoo during package installation.

Fixes facebookresearch#5494
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 6, 2026
@Mr-Neutr0n
Copy link
Author

bump — any thoughts on this? pkg_resources is deprecated and this swaps it for a simpler os.path approach. lmk if there's anything i should change

Since pkg_resources is no longer imported anywhere in the codebase,
remove it from the isort configuration as well.
@Mr-Neutr0n
Copy link
Author

Friendly bump! Let me know if there's anything I should update or improve to help move this forward.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to futureproof model_zoo.py against setuptools breaking change announced for 2025-12

1 participant