Skip to content

Conversation

volks73
Copy link

@volks73 volks73 commented Aug 16, 2025

I have observed a deprecation warning message for using pkg_resources. This PR migrates from pkg_resources to importlib.resources according to the migration guide: https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename.

The pkg_resources is only used in one location for one function.

This also adds some environment files and directories to the git ignore list.

@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 Aug 16, 2025
Copy link

@ruck94301 ruck94301 left a comment

Choose a reason for hiding this comment

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

If you want to preserve compatibility with Python 3.7, you'll need to modify setup.py and docs/requirements.txt to require importlib_resources, the backport for python_version<'3.9'.

Choose a reason for hiding this comment

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

The change to .gitignore are not germane to replacing pkg_resource.resource_filename, right?
Should it be removed from the PR?

from detectron2.checkpoint import DetectionCheckpointer
from detectron2.config import CfgNode, LazyConfig, get_cfg, instantiate
from detectron2.modeling import build_model
from importlib import resources as importlib_resources

Choose a reason for hiding this comment

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

detectron2 is still advertising compatibility w/ Python 3.7.
importlib.resources is introduced in Python 3.9.
So I think this breaks some compatibility. Easy to fix, but needs attention.

skip_glob=*/__init__.py,**/configs/**,**/tests/config/**
known_myself=detectron2
known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,pkg_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle,packaging,timm,pandas,fairscale,pytorch3d,pytorch_lightning
known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,importlib_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle,packaging,timm,pandas,fairscale,pytorch3d,pytorch_lightning

Choose a reason for hiding this comment

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

Yes, remove pkg_resources. But I'm thinking that adding importlib_resources here only makes sense if you might possibly import it (and importing importlib.resources as importlib_resources doesn't count, right?).

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.

2 participants