Imports the plugins listed in the arguments.
(plugins: List[str] = None)
| 174 | |
| 175 | |
| 176 | def import_plugins(plugins: List[str] = None) -> List[str]: |
| 177 | """ |
| 178 | Imports the plugins listed in the arguments. |
| 179 | """ |
| 180 | imported_plugins: List[str] = [] |
| 181 | if plugins is None or len(plugins) == 0: |
| 182 | return imported_plugins |
| 183 | |
| 184 | # Workaround for a presumed Python issue where spawned processes can't find modules in the current directory. |
| 185 | cwd = os.getcwd() |
| 186 | if cwd not in sys.path: |
| 187 | sys.path.append(cwd) |
| 188 | |
| 189 | for module_name in plugins: |
| 190 | try: |
| 191 | # TODO: include and exclude should be configurable, hard code now |
| 192 | import_module_and_submodules( |
| 193 | module_name, |
| 194 | include={ |
| 195 | 'easycv.toolkit.modelscope', |
| 196 | 'easycv.hooks', |
| 197 | 'easycv.models', |
| 198 | 'easycv.core', |
| 199 | 'easycv.toolkit', |
| 200 | 'easycv.predictors', |
| 201 | }, |
| 202 | exclude={ |
| 203 | 'easycv.toolkit.*', |
| 204 | 'easycv.*', |
| 205 | }) |
| 206 | logger.info('Plugin %s available', module_name) |
| 207 | imported_plugins.append(module_name) |
| 208 | except ModuleNotFoundError as e: |
| 209 | logger.error(f'Plugin {module_name} could not be loaded: {e}') |
| 210 | |
| 211 | return imported_plugins |
| 212 | |
| 213 | |
| 214 | def import_file_plugins(requirement_path=None) -> List[str]: |
searching dependent graphs…