-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fixed pkg_resource
deprecation warning
#5484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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'.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?).
I have observed a deprecation warning message for using
pkg_resources
. This PR migrates frompkg_resources
toimportlib.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.