22 lines
876 B
Python
22 lines
876 B
Python
from PytorchBoot.utils.log_util import Log
|
|
|
|
application_class = {}
|
|
def PytorchBootApplication(arg=None):
|
|
if callable(arg):
|
|
cls = arg
|
|
if "default" in application_class:
|
|
Log.error("Multiple classes annotated with default @PytorchBootApplication, require a 'name' parameter.", True)
|
|
application_class["default"] = cls
|
|
return cls
|
|
|
|
else:
|
|
name = arg
|
|
def decorator(cls):
|
|
if name is None:
|
|
raise Log.error("The 'name' parameter is required when using @PytorchBootApplication with arguments.", True)
|
|
if name in application_class:
|
|
raise Log.error(f"Multiple classes annotated with @PytorchBootApplication with the same name '{name}' found.", True)
|
|
application_class[name] = cls
|
|
return cls
|
|
return decorator
|