Skip to content

Commit

Permalink
Ensure conda_lock plugin users namespace+environment to get appropria…
Browse files Browse the repository at this point in the history
…te settings
  • Loading branch information
soapy1 committed Jan 27, 2025
1 parent ff3577c commit c8652f7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@


class CondaLock(lock.LockPlugin):
def _conda_command(self, conda_store) -> str:
settings = conda_store.get_settings()
return settings.conda_command
def _conda_command(self, conda_store, namespace=None, environment=None) -> str:
return conda_store.get_setting(
"conda_command", namespace=namespace, environment_name=environment
)

def _conda_flags(self, conda_store) -> str:
return conda_store.config.conda_flags
Expand All @@ -32,7 +33,9 @@ def lock_environment(
platforms: typing.List[str] = [conda_utils.conda_platform()],
) -> str:
context.log.info("lock_environment entrypoint for conda-lock")
conda_command = self._conda_command(context.conda_store)
conda_command = self._conda_command(
context.conda_store, namespace=context.namespace, environment=context.environment
)
conda_flags = self._conda_flags(context.conda_store)

environment_filename = pathlib.Path.cwd() / "environment.yaml"
Expand Down
16 changes: 8 additions & 8 deletions conda-store-server/conda_store_server/plugins/plugin_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class PluginContext:
----------
conda_store : conda_store_server.conda_store
conda_store instance
log : logging.logger
logger
log_level : int
logging level
stdout : io.StringIO
stream to write command output to
stderr : io.StringIO
Expand All @@ -33,12 +33,12 @@ class PluginContext:

def __init__(
self,
conda_store=None,
stdout=None,
stderr=None,
log_level=logging.INFO,
namespace=None,
environment=None,
conda_store,
stdout: io.StringIO | None = None,
stderr: io.StringIO | None = None,
log_level: int = logging.INFO,
namespace: str | None = None,
environment: str | None = None,
):
if stdout is not None and stderr is None:
stderr = stdout
Expand Down
26 changes: 26 additions & 0 deletions conda-store-server/tests/_internal/plugins/lock/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ def test_solve_lockfile_simple(conda_store, simple_specification):
assert "zlib" in [pkg["name"] for pkg in lock_result["package"]]


@mock.patch("conda_store_server._internal.plugins.lock.conda_lock.conda_lock.run_lock")
def test_solve_right_conda_command(mock_run_lock, conda_store, simple_specification):
# Update conda_command settings
conda_store.set_settings(
data={"conda_command": "conda"}
)

# Dump dummy data to the expected lockfile output location
def run_lock_side_effect(lockfile_path, **kwargs):
pass

mock_run_lock.side_effect = run_lock_side_effect

locker = conda_lock.CondaLock()
locker.lock_environment(
context=plugin_context.PluginContext(conda_store, namespace="test", environment="one"),
spec=simple_specification,
platforms=[conda_utils.conda_platform()],
)

# Check that the call to `conda_lock` is correctly formed
mock_run_lock.assert_called_once()
call_args = mock_run_lock.call_args_list[0][1]
assert call_args["conda_exe"] == "conda"


@pytest.mark.parametrize(
"specification",
[
Expand Down

0 comments on commit c8652f7

Please sign in to comment.