-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,8 @@ model_ts*.txt | |
| .idea | ||
| .vscode | ||
| _darcs | ||
| .venv | ||
| .envrc | ||
|
|
||
| # project dirs | ||
| /detectron2/model_zoo/configs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| # Copyright (c) Facebook, Inc. and its affiliates. | ||
|
|
||
| import atexit | ||
| import os | ||
| from typing import Optional | ||
| import pkg_resources | ||
| import torch | ||
|
|
||
| from contextlib import ExitStack | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. detectron2 is still advertising compatibility w/ Python 3.7. |
||
| from typing import Optional | ||
|
|
||
|
|
||
| class _ModelZooUrls: | ||
|
|
@@ -136,9 +139,10 @@ def get_config_file(config_path): | |
| Returns: | ||
| str: the real path to the config file. | ||
| """ | ||
| cfg_file = pkg_resources.resource_filename( | ||
| "detectron2.model_zoo", os.path.join("configs", config_path) | ||
| ) | ||
| file_manager = ExitStack() | ||
| atexit.register(file_manager.close) | ||
| ref = importlib_resources.files("detectron2.model_zoo") / os.path.join("configs", config_path) | ||
| cfg_file = file_manager.enter_context(importlib_resources.as_file(ref)) | ||
| if not os.path.exists(cfg_file): | ||
| raise RuntimeError("{} not available in Model Zoo!".format(config_path)) | ||
| return cfg_file | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ known_standard_library=numpy,setuptools,mock | |
| skip=./datasets,docs | ||
| 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 commentThe 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?). |
||
| no_lines_before=STDLIB,THIRDPARTY | ||
| sections=FUTURE,STDLIB,THIRDPARTY,myself,FIRSTPARTY,LOCALFOLDER | ||
| default_section=FIRSTPARTY | ||
|
|
||
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?