[6d389a]: / mmaction / utils / decorators.py

Download this file

38 lines (25 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (c) OpenMMLab. All rights reserved.
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__}. '
'For OpenMMLAB codebases, you may need to install mmcv-full '
'first before you install the particular codebase. ')
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__}. '
'For OpenMMLAB codebases, you may need to install mmcv-full '
'first before you install the particular codebase. ')
cls.__init__ = MethodType(import_error_init, cls)
return cls
return decorate