Skip to content

Commit

Permalink
Merge pull request #735 from maresb/improve-error-message
Browse files Browse the repository at this point in the history
Improve error message when update fails due to channel conflict
  • Loading branch information
maresb authored Oct 18, 2024
2 parents 772649c + 49f9eff commit ffdfebd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def make_lock_files( # noqa: C901
for dep in original_lock_content.package
if dep.platform not in platforms_to_lock
]
lock_content_to_persist = original_lock_content.copy(
lock_content_to_persist = original_lock_content.model_copy(
deep=True,
update={"package": packages_not_to_lock},
)
Expand Down
10 changes: 7 additions & 3 deletions conda_lock/lockfile/v2prelim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ def merge(self, other: "Optional[Lockfile]") -> "Lockfile":
elif not isinstance(other, Lockfile):
raise TypeError

assert (
self.metadata.channels == other.metadata.channels
), f"channels must match: {self.metadata.channels} != {other.metadata.channels}"
if self.metadata.channels != other.metadata.channels:
raise ValueError(
f"Cannot merge locked dependencies when the channels are not "
f"consistent. {self.metadata.channels} != {other.metadata.channels}. "
f"If the channels are indeed different, then you may need to delete "
f"the existing lockfile and relock from scratch."
)

ours = {d.key(): d for d in self.package}
theirs = {d.key(): d for d in other.package}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ def test_aggregate_lock_specs_invalid_channels():
sources=[],
)

add_conda_forge = base_spec.copy(
add_conda_forge = base_spec.model_copy(
update={
"channels": [
Channel.from_string("conda-forge"),
Expand All @@ -1949,7 +1949,7 @@ def test_aggregate_lock_specs_invalid_channels():
assert agg_spec.channels == add_conda_forge.channels

# swap the order of the two channels, which is an error
flipped = base_spec.copy(
flipped = base_spec.model_copy(
update={
"channels": [
Channel.from_string("defaults"),
Expand All @@ -1963,7 +1963,7 @@ def test_aggregate_lock_specs_invalid_channels():
[base_spec, add_conda_forge, flipped], platforms=[]
)

add_pytorch = base_spec.copy(
add_pytorch = base_spec.model_copy(
update={
"channels": [
Channel.from_string("pytorch"),
Expand Down

0 comments on commit ffdfebd

Please sign in to comment.