1
0
Fork 0
mirror of synced 2024-06-26 18:20:50 +12:00
Rare/rare/shared.py

49 lines
1.7 KiB
Python
Raw Normal View History

2021-10-08 07:19:24 +13:00
from argparse import Namespace
from typing import Optional
2021-10-08 07:19:24 +13:00
from legendary.core import LegendaryCore
from rare.utils.models import ApiResults, GlobalSignals
2021-10-08 07:19:24 +13:00
_legendary_core_singleton: Optional[LegendaryCore] = None
_global_signals_singleton: Optional[GlobalSignals] = None
_arguments_singleton: Optional[Namespace] = None
_api_results_singleton: Optional[ApiResults] = None
2021-10-08 07:19:24 +13:00
def LegendaryCoreSingleton(init: bool = False) -> LegendaryCore:
global _legendary_core_singleton
if _legendary_core_singleton is None and not init:
raise RuntimeError("Uninitialized use of LegendaryCoreSingleton")
if _legendary_core_singleton is None:
_legendary_core_singleton = LegendaryCore()
return _legendary_core_singleton
2021-10-08 07:19:24 +13:00
def GlobalSignalsSingleton(init: bool = False) -> GlobalSignals:
global _global_signals_singleton
if _global_signals_singleton is None and not init:
raise RuntimeError("Uninitialized use of GlobalSignalsSingleton")
if _global_signals_singleton is None:
_global_signals_singleton = GlobalSignals()
return _global_signals_singleton
2021-10-08 07:19:24 +13:00
def ArgumentsSingleton(args: Namespace = None) -> Optional[Namespace]:
global _arguments_singleton
if _arguments_singleton is None and args is None:
raise RuntimeError("Uninitialized use of ArgumentsSingleton")
if _arguments_singleton is None:
_arguments_singleton = args
return _arguments_singleton
2021-10-08 07:19:24 +13:00
def ApiResultsSingleton(res: ApiResults = None) -> Optional[ApiResults]:
global _api_results_singleton
if _api_results_singleton is None and res is None:
raise RuntimeError("Uninitialized use of ApiResultsSingleton")
if _api_results_singleton is None:
_api_results_singleton = res
return _api_results_singleton