Skip to content

Commit

Permalink
Load conda-lock plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Nov 7, 2024
1 parent 688077d commit 3ce4a49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
32 changes: 32 additions & 0 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from contextlib import contextmanager
from typing import Any, Dict
import pluggy

import pydantic
from celery import Celery, group
Expand All @@ -27,6 +28,8 @@
from traitlets.config import LoggingConfigurable

from conda_store_server import CONDA_STORE_DIR, BuildKey, api, registry, storage
from conda_store_server.plugins import hookspec, registry
from conda_store_server.exception import CondaStorePluginNotFoundError
from conda_store_server._internal import conda_utils, environment, orm, schema, utils


Expand Down Expand Up @@ -471,6 +474,35 @@ def celery_app(self):
self._celery_app.config_from_object(self.celery_config)
return self._celery_app

@property
def plugin_registry(self):
if hasattr(self, "_plugin_registry"):
return self._plugin_registry

self._plugin_registry = registry.PluginRegistry()
self._plugin_registry.collect_plugins()
return self._plugin_registry

@property
def plugin_manager(self):
if hasattr(self, "_plugin_manager"):
return self._plugin_manager

self._plugin_manager = pluggy.PluginManager(hookspec.spec_name)
self._plugin_manager.add_hookspecs(hookspec.CondaStoreSpecs)

# Load lock plugin
self.load_plugin_by_name("lock-conda_lock")

return self._plugin_manager

def load_plugin_by_name(self, name, *args, **kwargs):
"""Loads a plugin from the plugin registry into the plugin manager"""
target_plugin = self.plugin_registry.get_plugin(name)
if target_plugin is None:
raise CondaStorePluginNotFoundError(name, self.plugin_registry.list_plugin_names())
self.plugin_manager.register(target_plugin(*args, **kwargs))

def ensure_settings(self, db: Session):
"""Ensure that conda-store traitlets settings are applied"""
settings = schema.Settings(
Expand Down
19 changes: 19 additions & 0 deletions conda-store-server/conda_store_server/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.


class CondaStoreError(Exception):
pass


class CondaStorePluginNotFoundError(CondaStoreError):
"""Exception raised by conda store when a specified plugin is not found
Attributes:
plugin -- plugin that was not found
available_plugins -- list of registered plugins
"""

def __init__(self, plugin, available_plugins):
self.message = f"Plugin {plugin} was requested but not found! The following plugins are available {','.join(available_plugins)}"
super().__init__(self.message)

0 comments on commit 3ce4a49

Please sign in to comment.