Shortcuts

Source code for mmrazor.utils.placeholder

# Copyright (c) OpenMMLab. All rights reserved.
[docs]def get_placeholder(string: str) -> object: """Get placeholder instance which can avoid raising errors when down-stream dependency is not installed properly. Args: string (str): the dependency's name, i.e. `mmcls` Raises: ImportError: raise it when the dependency is not installed properly. Returns: object: PlaceHolder instance. """ def raise_import_error(package_name): raise ImportError( f'`{package_name}` is not installed properly, plz check.') class PlaceHolder(): def __init__(self) -> None: raise_import_error(string) return PlaceHolder
[docs]def get_package_placeholder(string: str) -> object: """Get placeholder instance which can avoid raising errors when down-stream dependency is not installed properly. Args: string (str): the dependency's name, i.e. `mmcls` Raises: ImportError: raise it when the dependency is not installed properly. Returns: object: PlaceHolder instance. """ def raise_import_error(package_name): raise ImportError( f'`{package_name}` is not installed properly, plz check.') class PlaceHolderMetaclass(type): """Used to support usage of PlaceHolder.xxxx.""" def __getattr__(self, name): raise_import_error(string) class PlaceHolder(metaclass=PlaceHolderMetaclass): def __init__(self) -> None: raise_import_error(string) return PlaceHolder
Read the Docs v: latest
Versions
latest
stable
v1.0.0
v1.0.0rc2
v1.0.0rc1
v1.0.0rc0
v0.3.1
v0.3.0
v0.2.0
quantize
main
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.