Skip to content

Commit

Permalink
[pre-commit.ci] Apply automatic pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 8, 2024
1 parent b847d5d commit 0309540
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down
14 changes: 8 additions & 6 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions conda-store-server/conda_store_server/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

from conda_store_server.plugins.lock import conda_lock


BUILTIN_PLUGINS = [
conda_lock.CondaLock
]
BUILTIN_PLUGINS = [conda_lock.CondaLock]
6 changes: 3 additions & 3 deletions conda-store-server/conda_store_server/plugins/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"""
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
import typing

import yaml

from conda_lock.conda_lock import run_lock

from conda_store_server._internal import conda_utils, schema
from conda_store_server.plugins import hookspec
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

@hookspec.hookimpl
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conda_store_server.plugins import BUILTIN_PLUGINS


class PluginRegistry():
class PluginRegistry:
_instance = None

def __new__(cls):
Expand Down
14 changes: 7 additions & 7 deletions conda-store-server/tests/plugins/lock/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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()],
Expand Down

0 comments on commit 0309540

Please sign in to comment.