Skip to content

Commit

Permalink
Add plugin registry
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Nov 7, 2024
1 parent efc2c11 commit f6d9448
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PluginContext:
* the variables: conda_store, log, stdout, stderr
* the functions: run_command, run
"""
def __init__(self, conda_store=None, stdout=None, stderr=None):
def __init__(self, conda_store=None, stdout=None, stderr=None, log_level=logging.INFO):
if stdout is not None and stderr is None:
stderr = stdout

Expand All @@ -25,8 +25,7 @@ def __init__(self, conda_store=None, stdout=None, stderr=None):
self.log = logging.getLogger(f"conda_store_server.plugins.plugin_context.{self.id}")
self.log.propagate = False
self.log.addHandler(logging.StreamHandler(stream=self.stdout))
# TODO: get log level from config
self.log.setLevel(logging.INFO)
self.log.setLevel(log_level)
self.conda_store = conda_store

def run_command(self, command, redirect_stderr=True, **kwargs):
Expand Down
36 changes: 36 additions & 0 deletions conda-store-server/conda_store_server/plugins/registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from conda_store_server.plugins import BUILTIN_PLUGINS


class PluginRegistry():
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super(PluginRegistry, cls).__new__(cls)
return cls._instance

def __init__(self):
# plugins are registered in the map of the form:
# {plugin_name: plugin_class}
self.registered = {}

def list_plugin_names(self):
return self.registered.keys()

def get_plugin(self, name):
return self.registered.get(name)

def register_plugin(self, p):
"""Adds plugin to the list of registered plugins"""
plugin_name = p.name()
if plugin_name not in self.registered:
self.registered[plugin_name] = p

def collect_plugins(self):
"""Registers all availble plugins with the plugin registry"""
for plugin in BUILTIN_PLUGINS:
self.register_plugin(plugin)

0 comments on commit f6d9448

Please sign in to comment.