Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set channel priority to strict, print config info #693

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions conda-store-server/conda_store_server/action/generate_lockfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import os
import pathlib
import subprocess
import typing

import yaml
Expand All @@ -13,19 +15,42 @@ def action_solve_lockfile(
conda_command: str,
specification: schema.CondaSpecification,
platforms: typing.List[str] = [conda_utils.conda_platform()],
trallard marked this conversation as resolved.
Show resolved Hide resolved
# Avoids package compatibility issues, see:
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
conda_flags: str = "--strict-channel-priority",
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved
):
environment_filename = pathlib.Path.cwd() / "environment.yaml"
lockfile_filename = pathlib.Path.cwd() / "conda-lock.yaml"

with environment_filename.open("w") as f:
json.dump(specification.dict(), f)

run_lock(
environment_files=[environment_filename],
platforms=platforms,
lockfile_path=lockfile_filename,
conda_exe=conda_command,
)
def print_cmd(cmd):
context.log.info(f"Running command: {' '.join(cmd)}")
context.log.info(
subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding="utf-8")
)

# The info command can be used with either mamba or conda
print_cmd([conda_command, "info"])
# The config command is not supported by mamba
print_cmd(["conda", "config", "--show"])
print_cmd(["conda", "config", "--show-sources"])

# CONDA_FLAGS is used by conda-lock in conda_solver.solve_specs_for_arch
try:
conda_flags_name = "CONDA_FLAGS"
print(f"{conda_flags_name}={conda_flags}")
os.environ[conda_flags_name] = conda_flags
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved

run_lock(
environment_files=[environment_filename],
platforms=platforms,
lockfile_path=lockfile_filename,
conda_exe=conda_command,
)
finally:
os.environ.pop(conda_flags_name, None)

with lockfile_filename.open() as f:
return yaml.safe_load(f)
23 changes: 23 additions & 0 deletions conda-store-server/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ def test_solve_lockfile(conda_store, specification, request):
assert len(context.result["package"]) != 0


def test_solve_lockfile_valid_conda_flags(conda_store, simple_specification):
context = action.action_solve_lockfile(
conda_command=conda_store.conda_command,
specification=simple_specification,
platforms=[conda_utils.conda_platform()],
conda_flags="--strict-channel-priority",
)
assert len(context.result["package"]) != 0
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved


# Checks that conda_flags is used by conda-lock
def test_solve_lockfile_invalid_conda_flags(conda_store, simple_specification):
with pytest.raises(Exception, match=(
r"Command.*--this-is-invalid.*returned non-zero exit status"
)):
action.action_solve_lockfile(
conda_command=conda_store.conda_command,
specification=simple_specification,
platforms=[conda_utils.conda_platform()],
conda_flags="--this-is-invalid",
)
nkaretnikov marked this conversation as resolved.
Show resolved Hide resolved


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