moved singleton_proxy to helper.depless

This commit is contained in:
Adam Saudagar 2023-03-07 00:22:24 +05:30
parent 5fb58d9998
commit 788e78b9bb
2 changed files with 21 additions and 20 deletions

20
fishy/helper/depless.py Normal file
View File

@ -0,0 +1,20 @@
"""
no imports from fishy itself here, or anything which depends on fishy
"""
def singleton_proxy(instance_name):
def decorator(root_cls):
if not hasattr(root_cls, instance_name):
raise AttributeError(f"{instance_name} not found in {root_cls}")
class SingletonProxy(type):
def __getattr__(cls, name):
return getattr(getattr(cls, instance_name), name)
class NewClass(root_cls, metaclass=SingletonProxy):
...
return NewClass
return decorator

View File

@ -6,6 +6,7 @@ from abc import ABC, abstractmethod
from typing import Tuple, Optional
import platform
from fishy.helper.depless import singleton_proxy
class IOSServices(ABC):
@ -59,26 +60,6 @@ class IOSServices(ABC):
"""
# todo move this into helper and use for config and similar places
# but make sure other fishy stuff is not imported while importing helper
# to do that, move everything which uses fishy stuff into a different helper script
def singleton_proxy(instance_name):
def decorator(root_cls):
if not hasattr(root_cls, instance_name):
raise AttributeError(f"{instance_name} not found in {root_cls}")
class SingletonProxy(type):
def __getattr__(cls, name):
return getattr(getattr(cls, instance_name), name)
class NewClass(root_cls, metaclass=SingletonProxy):
...
return NewClass
return decorator
@singleton_proxy("_instance")
class os_services:
_instance: Optional[IOSServices] = None