Fixed pkg_resource deprecation warning#5484
Fixed pkg_resource deprecation warning#5484volks73 wants to merge 5 commits intofacebookresearch:mainfrom
pkg_resource deprecation warning#5484Conversation
ruck94301
left a comment
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?).
I have observed a deprecation warning message for using
pkg_resources. This PR migrates frompkg_resourcestoimportlib.resourcesaccording to the migration guide: https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename.The
pkg_resourcesis only used in one location for one function.This also adds some environment files and directories to the git ignore list.