-
Notifications
You must be signed in to change notification settings - Fork 106
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
Persist packages from original lockfile _only_ for platforms not requested for lock #485
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c78d26e
Add test for updating for a single platform
mfisher87 45b880d
Add unit tests for dependency removal and pip move
itsarobin 45a8029
Persist packages from original lockfile for platforms not requested f…
itsarobin 982d292
Add documentation on correct dev environment setup
itsarobin cc91ed7
Satisfy linters
mfisher87 2a1fb78
Improve lock content variable names
mfisher87 99922db
Clarify dev dependencies README
mfisher87 4fbf8aa
Remove pip dev requirements instructions
mfisher87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,7 +250,7 @@ def fn_to_dist_name(fn: str) -> str: | |
return fn | ||
|
||
|
||
def make_lock_files( | ||
def make_lock_files( # noqa: C901 | ||
*, | ||
conda: PathLike, | ||
src_files: List[pathlib.Path], | ||
|
@@ -341,35 +341,35 @@ def make_lock_files( | |
virtual_package_repo=virtual_package_repo, | ||
required_categories=required_categories if filter_categories else None, | ||
) | ||
lock_content: Optional[Lockfile] = None | ||
original_lock_content: Optional[Lockfile] = None | ||
|
||
platforms_to_lock: List[str] = [] | ||
platforms_already_locked: List[str] = [] | ||
if lockfile_path.exists(): | ||
import yaml | ||
|
||
try: | ||
lock_content = parse_conda_lock_file(lockfile_path) | ||
original_lock_content = parse_conda_lock_file(lockfile_path) | ||
except (yaml.error.YAMLError, FileNotFoundError): | ||
logger.warning( | ||
"Failed to parse existing lock. Regenerating from scratch" | ||
) | ||
lock_content = None | ||
original_lock_content = None | ||
else: | ||
lock_content = None | ||
original_lock_content = None | ||
|
||
if lock_content is not None: | ||
platforms_already_locked = list(lock_content.metadata.platforms) | ||
platforms_to_lock: List[str] = [] | ||
platforms_already_locked: List[str] = [] | ||
if original_lock_content is not None: | ||
platforms_already_locked = list(original_lock_content.metadata.platforms) | ||
update_spec = UpdateSpecification( | ||
locked=lock_content.package, update=update | ||
locked=original_lock_content.package, update=update | ||
) | ||
for platform in lock_spec.platforms: | ||
if ( | ||
update | ||
or platform not in lock_content.metadata.platforms | ||
or platform not in platforms_already_locked | ||
or not check_input_hash | ||
or lock_spec.content_hash_for_platform(platform) | ||
!= lock_content.metadata.content_hash[platform] | ||
!= original_lock_content.metadata.content_hash[platform] | ||
): | ||
platforms_to_lock.append(platform) | ||
if platform in platforms_already_locked: | ||
|
@@ -385,9 +385,12 @@ def make_lock_files( | |
) | ||
platforms_to_lock = sorted(set(platforms_to_lock)) | ||
|
||
if platforms_to_lock: | ||
if not platforms_to_lock: | ||
new_lock_content = original_lock_content | ||
else: | ||
print(f"Locking dependencies for {platforms_to_lock}...", file=sys.stderr) | ||
lock_content = lock_content | create_lockfile_from_spec( | ||
itsarobin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fresh_lock_content = create_lockfile_from_spec( | ||
conda=conda, | ||
spec=lock_spec, | ||
platforms=platforms_to_lock, | ||
|
@@ -398,9 +401,24 @@ def make_lock_files( | |
strip_auth=strip_auth, | ||
) | ||
|
||
if not original_lock_content: | ||
new_lock_content = fresh_lock_content | ||
else: | ||
# Persist packages from original lockfile for platforms not requested for lock | ||
packages_not_to_lock = [ | ||
dep | ||
for dep in original_lock_content.package | ||
if dep.platform not in platforms_to_lock | ||
] | ||
lock_content_to_persist = original_lock_content.copy( | ||
deep=True, | ||
update={"package": packages_not_to_lock}, | ||
) | ||
new_lock_content = lock_content_to_persist | fresh_lock_content | ||
|
||
if "lock" in kinds: | ||
write_conda_lock_file( | ||
lock_content, | ||
new_lock_content, | ||
lockfile_path, | ||
metadata_choices=metadata_choices, | ||
) | ||
|
@@ -410,7 +428,9 @@ def make_lock_files( | |
file=sys.stderr, | ||
) | ||
|
||
assert lock_content is not None | ||
# After this point, we're working with `new_lock_content`, never | ||
# `original_lock_content` or `fresh_lock_content`. | ||
assert new_lock_content is not None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this assertion a bit confusing. I was not able to type if not platforms_to_lock:
new_lock_content = original_lock_content I would like to move this check in to the type system, but that seems better left for a larger refactor effort. |
||
|
||
# check for implicit inclusion of cudatoolkit | ||
# warn if it was pulled in, but not requested explicitly | ||
|
@@ -422,13 +442,13 @@ def make_lock_files( | |
for pkg in itertools.chain(*lock_spec.dependencies.values()) | ||
) | ||
if not cudatoolkit_requested: | ||
for package in lock_content.package: | ||
for package in new_lock_content.package: | ||
if package.name == "cudatoolkit": | ||
logger.warning(_implicit_cuda_message) | ||
break | ||
|
||
do_render( | ||
lock_content, | ||
new_lock_content, | ||
kinds=[k for k in kinds if k != "lock"], | ||
include_dev_dependencies=include_dev_dependencies, | ||
filename_template=filename_template, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# How to install dev environment | ||
|
||
* First install dev dependencies: | ||
|
||
``` | ||
mamba env create -f environments/dev-environment.yaml | ||
mamba activate conda-lock-dev | ||
``` | ||
|
||
* Then, install `conda-lock` in editable mode. This will also install its runtime | ||
dependencies as defined in `pyproject.toml`. | ||
|
||
``` | ||
pip install --editable . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
dependencies: | ||
- zlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
dependencies: | ||
- zlib | ||
- xz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
dependencies: | ||
- six |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
dependencies: | ||
- pip: | ||
- six |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
- osx-64 | ||
dependencies: | ||
- zlib ==1.2.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
channels: | ||
- conda-forge | ||
platforms: | ||
- linux-64 | ||
- osx-64 | ||
dependencies: | ||
- zlib ==1.2.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since previously we were mutating
lock_content
in this conditional block, the "else" condition was lack of mutation. I think making that case explicit and first made this renaming change the most readable.