-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement] Remove dependency package warnings (#583)
* fix mmdet warnings * add unit test * remove mmcv-full uninstall warnings * add changelog * remove rebundent changelog of refactor unittest * fix conflict * fix warnings of mmcv-full uninstalled
- Loading branch information
Showing
16 changed files
with
117 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from .collect_env import collect_env | ||
from .decorators import import_module_error_class, import_module_error_func | ||
from .gradcam_utils import GradCAM | ||
from .logger import get_root_logger | ||
from .misc import get_random_string, get_shm_dir, get_thread_id | ||
from .precise_bn import PreciseBNHook | ||
|
||
__all__ = [ | ||
'get_root_logger', 'collect_env', 'get_random_string', 'get_thread_id', | ||
'get_shm_dir', 'GradCAM', 'PreciseBNHook' | ||
'get_shm_dir', 'GradCAM', 'PreciseBNHook', 'import_module_error_class', | ||
'import_module_error_func' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from types import MethodType | ||
|
||
|
||
def import_module_error_func(module_name): | ||
"""When a function is imported incorrectly due to a missing module, raise | ||
an import error when the function is called.""" | ||
|
||
def decorate(func): | ||
|
||
def new_func(*args, **kwargs): | ||
raise ImportError( | ||
f'Please install {module_name} to use {func.__name__}.') | ||
return func(*args, **kwargs) | ||
|
||
return new_func | ||
|
||
return decorate | ||
|
||
|
||
def import_module_error_class(module_name): | ||
"""When a class is imported incorrectly due to a missing module, raise an | ||
import error when the class is instantiated.""" | ||
|
||
def decorate(cls): | ||
|
||
def import_error_init(*args, **kwargs): | ||
raise ImportError( | ||
f'Please install {module_name} to use {cls.__name__}.') | ||
|
||
cls.__init__ = MethodType(import_error_init, cls) | ||
return cls | ||
|
||
return decorate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from mmaction.utils import import_module_error_class, import_module_error_func | ||
|
||
|
||
def test_import_module_error_class(): | ||
|
||
@import_module_error_class('mmdet') | ||
class ExampleClass: | ||
pass | ||
|
||
with pytest.raises(ImportError): | ||
ExampleClass() | ||
|
||
@import_module_error_class('mmdet') | ||
class ExampleClass: | ||
|
||
def __init__(self, a, b=3): | ||
self.c = a + b | ||
|
||
with pytest.raises(ImportError): | ||
ExampleClass(4) | ||
|
||
|
||
def test_import_module_error_func(): | ||
|
||
@import_module_error_func('_add') | ||
def ExampleFunc(a, b): | ||
return a + b | ||
|
||
with pytest.raises(ImportError): | ||
ExampleFunc(3, 4) |