Last active
November 8, 2023 22:19
-
-
Save MananAmin/12c896e42cd6f3d31b1915f187affb27 to your computer and use it in GitHub Desktop.
python patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pluggy import PluginManager | |
# singleton class | |
class MetaPluginManager(type): | |
_plugin_manager: PluginManager = None | |
@staticmethod | |
def get_plugin_manager(): | |
if not MetaPluginManager._plugin_manager: | |
MetaPluginManager._plugin_manager = PluginManager('demo') | |
# MetaPluginManager._plugin_manager.add_hookspecs(_hooks) | |
return MetaPluginManager._plugin_manager | |
def __getattr__(cls, attr): | |
pm = MetaPluginManager.get_plugin_manager() | |
return getattr(pm, attr) | |
class plugin_manager(metaclass=MetaPluginManager): | |
pass | |
# source: allure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment