Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

__init__.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import os
  17. import importlib
  18. import inspect
  19. from types import ModuleType
  20. from typing import Dict, Type
  21. _package_path = os.path.dirname(__file__)
  22. __all_classes: Dict[str, Type] = {}
  23. def _import_submodules() -> None:
  24. for filename in os.listdir(_package_path): # noqa: F821
  25. if filename.startswith("__") or not filename.endswith(".py") or filename.startswith("base"):
  26. continue
  27. module_name = filename[:-3]
  28. try:
  29. module = importlib.import_module(f".{module_name}", package=__name__)
  30. _extract_classes_from_module(module) # noqa: F821
  31. except ImportError as e:
  32. print(f"Warning: Failed to import module {module_name}: {str(e)}")
  33. def _extract_classes_from_module(module: ModuleType) -> None:
  34. for name, obj in inspect.getmembers(module):
  35. if (inspect.isclass(obj) and
  36. obj.__module__ == module.__name__ and not name.startswith("_")):
  37. __all_classes[name] = obj
  38. globals()[name] = obj
  39. _import_submodules()
  40. __all__ = list(__all_classes.keys()) + ["__all_classes"]
  41. del _package_path, _import_submodules, _extract_classes_from_module