functions.py 516 B

12345678910111213141516171819
  1. import importlib
  2. import inspect
  3. def load_model_class(identifier: str, prefix: str = "models."):
  4. module_path, class_name = identifier.split('@')
  5. # Import the module
  6. module = importlib.import_module(prefix + module_path)
  7. cls = getattr(module, class_name)
  8. return cls
  9. def get_model_source_path(identifier: str, prefix: str = "models."):
  10. module_path, class_name = identifier.split('@')
  11. module = importlib.import_module(prefix + module_path)
  12. return inspect.getsourcefile(module)