Skip to content

Instantly share code, notes, and snippets.

@MananAmin
Last active November 8, 2023 22:19
Show Gist options
  • Save MananAmin/12c896e42cd6f3d31b1915f187affb27 to your computer and use it in GitHub Desktop.
Save MananAmin/12c896e42cd6f3d31b1915f187affb27 to your computer and use it in GitHub Desktop.
python patterns
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