Skip to content

Commit

Permalink
Persist packages from original lockfile for platforms not requested f…
Browse files Browse the repository at this point in the history
…or lock

Addresses #196: for requested platforms replaces lock content without erroneously persisting packages.

Co-authored-by: Arie Knoester <arikstr@gmail.com>
Reviewed-by: Matt Fisher <mfisher87@gmail.com>
  • Loading branch information
itsarobin and ArieKnoester committed Aug 20, 2023
1 parent 41f5927 commit 3b9364f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def make_lock_files( # noqa: C901
or not check_input_hash
or lock_spec.content_hash_for_platform(platform)
!= lock_content.metadata.content_hash[platform]
# TODO: Modify above line to allow for quick fail on differing environments
):
platforms_to_lock.append(platform)
if platform in platforms_already_locked:
Expand All @@ -378,7 +379,8 @@ def make_lock_files( # noqa: C901

if platforms_to_lock:
print(f"Locking dependencies for {platforms_to_lock}...", file=sys.stderr)
lock_content = lock_content | create_lockfile_from_spec(

new_lock_content = create_lockfile_from_spec(
conda=conda,
spec=lock_spec,
platforms=platforms_to_lock,
Expand All @@ -389,6 +391,21 @@ def make_lock_files( # noqa: C901
strip_auth=strip_auth,
)

if not lock_content:
lock_content = new_lock_content
else:
# Persist packages from original lockfile for platforms not requested for lock
packages_not_to_lock = [
dep
for dep in lock_content.package
if dep.platform not in platforms_to_lock
]
filtered_lock_content = lock_content.copy(
deep=True,
update={"package": packages_not_to_lock},
)
lock_content = filtered_lock_content | new_lock_content

if "lock" in kinds:
write_conda_lock_file(
lock_content,
Expand Down

0 comments on commit 3b9364f

Please sign in to comment.