8000 Ensure that channel configuration remains identical with --update by maresb · Pull Request #817 · conda/conda-lock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ensure that channel configuration remains identical with --update #817

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

Merged
merged 1 commit into from
Jul 2, 2025
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
12 changes: 12 additions & 0 deletions
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ def make_lock_files( # noqa: C901
if original_lock_content is not None:
platforms_already_locked = list(original_lock_content.metadata.platforms)
if update is not None:
# Check if channels have changed since lockfile was last generated
if lock_spec.channels != original_lock_content.metadata.channels:
Copy link
Preview
Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message prints channel URLs but the test asserts channel names ('defaults' and 'conda-forge') should appear; consider including channel names (e.g., c.name or str(c)) in the formatted message.

Copilot uses AI. Check for mistakes.

raise RuntimeError(
"The channel configuration has changed since the lockfile was last generated. "
"A partial update cannot be safely performed when channels have been modified, "
"as this could result in packages being resolved from different channels with "
"different priorities.\n\n"
f"Original channels: {[c.url for c in original_lock_content.metadata.channels]}\n"
f"New channels: {[c.url for c in lock_spec.channels]}\n\n"
"Please regenerate the lockfile from scratch by running the same command "
"without the --update flag."
)
# Narrow `update` sequence to list for mypy
update = list(update)
update_spec = UpdateSpecification(
Expand Down
69 changes: 69 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
extract_input_hash,
install,
main,
make_lock_files,
make_lock_spec,
render_lockfile_for_platform,
run_lock,
Expand Down Expand Up @@ -3478,3 +3479,71 @@ def get_content_hashes_for_lock_file(lock_file: Path) -> dict[str, str]:
)
postupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml")
assert preupdate_hashes != postupdate_hashes


def test_update_with_changed_channels_raises_error(
tmp_path: Path, conda_exe: str
) -> None:
"""Test that updating with changed channels raises an error."""

# Create a simple environment file
environment_yml = tmp_path / "environment.yml"
environment_yml.write_text("""
channels:
- conda-forge
dependencies:
- python=3.9
""")
from conda_lock.lockfile.v1.models import (
HashModel,
LockedDependency,
Lockfile,
LockMeta,
)

# Create an existing lockfile with different channels
lockfile_path = tmp_path / "conda-lock.yml"
existing_lockfile = Lockfile(
package=[
LockedDependency(
name="python",
version="3.9.18",
manager="conda",
platform="linux-64",
url="https://conda.anaconda.org/defaults/linux-64/python-3.9.18-h955ad1f_0.conda",
hash=HashModel(md5="abc123", sha256="def456"),
category="main",
optional=False,
)
],
metadata=LockMeta(
content_hash={"linux-64": "test_hash"},
channels=[
Channel.from_string("defaults")
], # Different from environment.yml
platforms=["linux-64"],
sources=["environment.yml"],
),
)

# Write the existing lockfile
with open(lockfile_path, "w") as f:
yaml.dump(existing_lockfile.dict_for_output(), f)

# Try to update - this should raise an error
with pytest.raises(RuntimeError) as exc_info:
make_lock_files(
conda=conda_exe,
src_files=[environment_yml],
kinds=["lock"],
lockfile_path=lockfile_path,
update=["python"], # Try to update python
mapping_url=DEFAULT_MAPPING_URL,
)

# Verify the error message contains the expected information
error_msg = str(exc_info.value)
assert "channel configuration has changed" in error_msg
assert "defaults" in error_msg
assert "conda-forge" in error_msg
assert "without the --update flag" in error_msg
Loading
0