()
| 272 | |
| 273 | |
| 274 | def check_submodules(): |
| 275 | # This is to make sure the transformers module imported is the one in the repo. |
| 276 | spec = importlib.util.spec_from_file_location( |
| 277 | "transformers", |
| 278 | os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"), |
| 279 | submodule_search_locations=[PATH_TO_TRANSFORMERS], |
| 280 | ) |
| 281 | transformers = spec.loader.load_module() |
| 282 | |
| 283 | module_not_registered = [ |
| 284 | module |
| 285 | for module in get_transformers_submodules() |
| 286 | if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys() |
| 287 | ] |
| 288 | if len(module_not_registered) > 0: |
| 289 | list_of_modules = "\n".join(f"- {module}" for module in module_not_registered) |
| 290 | raise ValueError( |
| 291 | "The following submodules are not properly registered in the main init of Transformers:\n" |
| 292 | f"{list_of_modules}\n" |
| 293 | "Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value." |
| 294 | ) |
| 295 | |
| 296 | |
| 297 | if __name__ == "__main__": |
no test coverage detected