diff --git a/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py b/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py index f6102d79b..b290650e9 100644 --- a/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py +++ b/conda-store-server/conda_store_server/_internal/action/generate_lockfile.py @@ -3,15 +3,9 @@ # license that can be found in the LICENSE file. import json -import os import pathlib -import typing -import yaml -from conda_lock.conda_lock import run_lock - -from conda_store_server._internal import action, conda_utils, schema, utils -from conda_store_server._internal.action.utils import logged_command +from conda_store_server._internal import action, schema, utils @action.action diff --git a/conda-store-server/conda_store_server/_internal/worker/build.py b/conda-store-server/conda_store_server/_internal/worker/build.py index aed4280cb..62a362cee 100644 --- a/conda-store-server/conda_store_server/_internal/worker/build.py +++ b/conda-store-server/conda_store_server/_internal/worker/build.py @@ -17,8 +17,8 @@ from sqlalchemy.orm import Session from conda_store_server import api -from conda_store_server.plugins import plugin_context from conda_store_server._internal import action, conda_utils, orm, schema, utils +from conda_store_server.plugins import plugin_context class LoggedStream: @@ -233,11 +233,9 @@ def build_conda_environment(db: Session, conda_store, build): conda_store=conda_store, build=build, prefix="hook-lock_environment: ", - ) - ), - spec=schema.CondaSpecification.parse_obj( - build.specification.spec + ), ), + spec=schema.CondaSpecification.parse_obj(build.specification.spec), platforms=settings.conda_solve_platforms, ) diff --git a/conda-store-server/conda_store_server/app.py b/conda-store-server/conda_store_server/app.py index 43d94f5ad..7ea130bd7 100644 --- a/conda-store-server/conda_store_server/app.py +++ b/conda-store-server/conda_store_server/app.py @@ -7,8 +7,8 @@ import sys from contextlib import contextmanager from typing import Any, Dict -import pluggy +import pluggy import pydantic from celery import Celery, group from sqlalchemy.orm import Session, sessionmaker @@ -28,9 +28,9 @@ from traitlets.config import LoggingConfigurable from conda_store_server import CONDA_STORE_DIR, BuildKey, api, registry, storage -from conda_store_server.plugins import hookspec, plugin_registry -from conda_store_server.exception import CondaStorePluginNotFoundError from conda_store_server._internal import conda_utils, environment, orm, schema, utils +from conda_store_server.exception import CondaStorePluginNotFoundError +from conda_store_server.plugins import hookspec, plugin_registry def conda_store_validate_specification( @@ -491,7 +491,7 @@ def plugin_manager(self): self._plugin_manager = pluggy.PluginManager(hookspec.spec_name) self._plugin_manager.add_hookspecs(hookspec.CondaStoreSpecs) - # Get settings - required to configure the lock plugin with the + # Get settings - required to configure the lock plugin with the # correct conda command with self.session_factory() as db: settings = self.get_settings(db) @@ -500,7 +500,7 @@ def plugin_manager(self): self.load_plugin_by_name( "lock-conda_lock", conda_command=settings.conda_command, - conda_flags=self.conda_flags + conda_flags=self.conda_flags, ) return self._plugin_manager @@ -509,7 +509,9 @@ 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()) + raise CondaStorePluginNotFoundError( + name, self.plugin_registry.list_plugin_names() + ) self.plugin_manager.register(target_plugin(*args, **kwargs)) def ensure_settings(self, db: Session): diff --git a/conda-store-server/conda_store_server/plugins/__init__.py b/conda-store-server/conda_store_server/plugins/__init__.py index 9cb4f144e..1dc19cb83 100644 --- a/conda-store-server/conda_store_server/plugins/__init__.py +++ b/conda-store-server/conda_store_server/plugins/__init__.py @@ -4,7 +4,4 @@ from conda_store_server.plugins.lock import conda_lock - -BUILTIN_PLUGINS = [ - conda_lock.CondaLock -] +BUILTIN_PLUGINS = [conda_lock.CondaLock] diff --git a/conda-store-server/conda_store_server/plugins/hookspec.py b/conda-store-server/conda_store_server/plugins/hookspec.py index 082458809..8385d76fa 100644 --- a/conda-store-server/conda_store_server/plugins/hookspec.py +++ b/conda-store-server/conda_store_server/plugins/hookspec.py @@ -2,13 +2,13 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -import pluggy import typing +import pluggy + from conda_store_server._internal import conda_utils, schema from conda_store_server.plugins import plugin_context - spec_name = "conda-store-server" hookspec = pluggy.HookspecMarker(spec_name) @@ -23,7 +23,7 @@ class CondaStoreSpecs: def lock_environment( self, context: plugin_context.PluginContext, - spec: schema.CondaSpecification, + spec: schema.CondaSpecification, platforms: typing.List[str] = [conda_utils.conda_platform()], ) -> str: """Lock spec""" diff --git a/conda-store-server/conda_store_server/plugins/lock/conda_lock.py b/conda-store-server/conda_store_server/plugins/lock/conda_lock.py index bde97537e..1ec9f7c41 100644 --- a/conda-store-server/conda_store_server/plugins/lock/conda_lock.py +++ b/conda-store-server/conda_store_server/plugins/lock/conda_lock.py @@ -8,7 +8,6 @@ import typing import yaml - from conda_lock.conda_lock import run_lock from conda_store_server._internal import conda_utils, schema @@ -16,12 +15,14 @@ from conda_store_server.plugins.plugin_context import PluginContext -class CondaLock(): +class CondaLock: @classmethod def name(cls): return "lock-conda_lock" - def __init__(self, conda_flags="--strict-channel-priority", conda_command="mamba", *kwargs): + def __init__( + self, conda_flags="--strict-channel-priority", conda_command="mamba", *kwargs + ): self.conda_command = conda_command self.conda_flags = conda_flags @@ -29,7 +30,7 @@ def __init__(self, conda_flags="--strict-channel-priority", conda_command="mamba def lock_environment( self, context: PluginContext, - spec: schema.CondaSpecification, + spec: schema.CondaSpecification, platforms: typing.List[str] = [conda_utils.conda_platform()], ) -> str: context.log.info("lock_environment entrypoint for conda-lock") diff --git a/conda-store-server/conda_store_server/plugins/plugin_context.py b/conda-store-server/conda_store_server/plugins/plugin_context.py index bd949646d..fb027b214 100644 --- a/conda-store-server/conda_store_server/plugins/plugin_context.py +++ b/conda-store-server/conda_store_server/plugins/plugin_context.py @@ -15,14 +15,19 @@ class PluginContext: * the variables: conda_store, log, stdout, stderr * the functions: run_command, run """ - def __init__(self, conda_store=None, stdout=None, stderr=None, log_level=logging.INFO): + + 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 self.id = str(uuid.uuid4()) self.stdout = stdout if stdout is not None else io.StringIO() self.stderr = stderr if stderr is not None else io.StringIO() - self.log = logging.getLogger(f"conda_store_server.plugins.plugin_context.{self.id}") + 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)) self.log.setLevel(log_level) diff --git a/conda-store-server/conda_store_server/plugins/plugin_registry.py b/conda-store-server/conda_store_server/plugins/plugin_registry.py index c30633ca8..b4940d8a3 100644 --- a/conda-store-server/conda_store_server/plugins/plugin_registry.py +++ b/conda-store-server/conda_store_server/plugins/plugin_registry.py @@ -5,7 +5,7 @@ from conda_store_server.plugins import BUILTIN_PLUGINS -class PluginRegistry(): +class PluginRegistry: _instance = None def __new__(cls): diff --git a/conda-store-server/tests/plugins/lock/test_conda_lock.py b/conda-store-server/tests/plugins/lock/test_conda_lock.py index 6303f56c2..c4cb57d9f 100644 --- a/conda-store-server/tests/plugins/lock/test_conda_lock.py +++ b/conda-store-server/tests/plugins/lock/test_conda_lock.py @@ -2,12 +2,12 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -import pytest -import yaml import os - from unittest import mock +import pytest +import yaml + from conda_store_server._internal import conda_utils from conda_store_server.plugins import plugin_context from conda_store_server.plugins.lock import conda_lock @@ -28,8 +28,7 @@ def test_solve_lockfile( tmp_path, request, ): - """Test that the call to conda_lock.run_lock is formed correctly. - """ + """Test that the call to conda_lock.run_lock is formed correctly.""" tmp_path.mkdir(exist_ok=True) os.chdir(tmp_path) @@ -69,7 +68,7 @@ def run_lock_side_effect(lockfile_path, **kwargs): def test_solve_lockfile_simple(tmp_path, simple_specification): tmp_path.mkdir(exist_ok=True) os.chdir(tmp_path) - + locker = conda_lock.CondaLock( conda_command="mamba", conda_flags="--strict-channel-priority" ) @@ -104,6 +103,7 @@ def test_solve_lockfile_multiple_platforms(tmp_path, specification, request): ) assert len(lock_result["package"]) != 0 + # Checks that conda_flags is used by conda-lock def test_solve_lockfile_invalid_conda_flags(tmp_path, simple_specification): tmp_path.mkdir(exist_ok=True) @@ -116,7 +116,7 @@ def test_solve_lockfile_invalid_conda_flags(tmp_path, simple_specification): with pytest.raises( Exception, match=(r"Command.*--this-is-invalid.*returned non-zero exit status") ): - locker.lock_environment( + locker.lock_environment( context=plugin_context.PluginContext(), spec=simple_specification, platforms=[conda_utils.conda_platform()],