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

Persist packages from original lockfile _only_ for platforms not requested for lock #485

Merged
merged 8 commits into from
Sep 11, 2023

Conversation

itsarobin
Copy link
Contributor

@itsarobin itsarobin commented Aug 20, 2023

Description

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

TODO:

  • Add unit tests

Co-authored-by: Arie Knoester arikstr@gmail.com
Reviewed-by: Matt Fisher mfisher87@gmail.com

@netlify
Copy link

netlify bot commented Aug 20, 2023

Deploy Preview for conda-lock ready!

Name Link
🔨 Latest commit 4fbf8aa
🔍 Latest deploy log https://app.netlify.com/sites/conda-lock/deploys/64ff4a6ed5f5070008cf12e1
😎 Deploy Preview https://deploy-preview-485--conda-lock.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mfisher87
Copy link
Contributor

@maresb What do you think of this approach? We have to add some unit tests, but want to check that the approach is sound and take feedback in to account before writing unit tests for what might be a bad idea 😸

for dep in lock_content.package
if dep.platform not in platforms_to_lock
]
filtered_lock_content = lock_content.copy(
Copy link
Contributor

Choose a reason for hiding this comment

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

Better name: lock_content_to_persist?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya. I'd even rename the original to original_lock_content. And maybe new_lock_contentfresh_lock_content in order to reserve new_lock_content for the final result.

I'm a big fan of long and descriptive variable names.

Copy link
Contributor

@mfisher87 mfisher87 Aug 21, 2023

Choose a reason for hiding this comment

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

Ya. I'd even rename the original to original_lock_content. And maybe new_lock_content → fresh_lock_content in order to reserve new_lock_content for the final result.

I'm a big fan of long and descriptive variable names.

💯 same here :)

Copy link
Contributor

Choose a reason for hiding this comment

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

itsarobin added a commit to itsarobin/conda-lock that referenced this pull request Aug 25, 2023
  - `lock_content` -> `old_lock_content`
  - `new_lock_content` -> `fresh_lock_content`
  - `filtered_lock_content` -> `lock_content_to_persist`
  - create var `new_lock_content` from merge of `filtered_lock_content`
    and `fresh_lock_content`
@itsarobin itsarobin force-pushed the issue-196 branch 4 times, most recently from fb65026 to 40dc5f3 Compare August 27, 2023 22:23
@mfisher87
Copy link
Contributor

Unit tests for this change are in. We're thinking one more unit test to validate a single-platform update works as expected (that's not testing new functionality, it's testing a feature that pre-dates this change hasn't regressed).

Then we're thinking we will work on variable naming!

environments/README.md Outdated Show resolved Hide resolved
@itsarobin itsarobin changed the title Persist packages from original lockfile for platforms not requested for lock Persist packages from original lockfile _only_ for platforms not requested for lock Sep 3, 2023
@mfisher87 mfisher87 force-pushed the issue-196 branch 5 times, most recently from 647aeca to e9a50df Compare September 3, 2023 23:14
@mfisher87
Copy link
Contributor

While doing this renaming work, I felt the need to refactor. I actually got sucked a little bit in to doing a refactor and then pulled myself back and made this change as simple as I could.

This change made it clear that there's a point midway in make_lock_files where we switch from operating on old lock content to operating on new lock content (I left a comment to that effect), and that's a good indicator we could extract all the behavior that calculates the new lock content into a new function. There are likely even more functions to extract here, the complexity of this function is pretty high. We could get rid of that noqa marker :) My domain knowledge is pretty low, though, so I may need to ask many questions to do such a refactor if you agree it's warranted.

TODO: Rebase again, mark ready for review

mfisher87 and others added 6 commits September 10, 2023 10:05
Co-authored-by: Arie Knoester <arikstr@gmail.com>
Reviewed-by: Matt Fisher <mfisher87@gmail.com>
…or lock

Addresses conda#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>
Co-authored-by: Arie Knoester <arikstr@gmail.com>
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
Copy link
Contributor

@mfisher87 mfisher87 Sep 10, 2023

Choose a reason for hiding this comment

The 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 new_lock_content: Lockfile because original_lock_content could be None when we do this assignment:

        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.

@@ -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
Copy link
Contributor

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.

@mfisher87
Copy link
Contributor

@maresb I feel this is ready for a full review :) Thanks for your time thinking about this change!

@itsarobin itsarobin marked this pull request as ready for review September 10, 2023 16:36
@itsarobin itsarobin requested a review from a team as a code owner September 10, 2023 16:36
@itsarobin itsarobin requested a review from maresb September 10, 2023 16:36
@maresb
Copy link
Contributor

maresb commented Sep 10, 2023

Thanks so much for this!!!

I'm currently on the road and a bit slammed, so I'm not sure how long it'll take me to give the 👍 but at first glance everything looks good.

I don't like having both requirements-dev.txt and environments/dev-environment.yaml which are not kept in sync. I think we could delete requirements-dev.txt if we simply refactor the mkdocs GitHub workflow to use setup-micromamba. Is this something you'd be able to take care of at the end of this PR? (I'm just thinking that this might be a reasonable add-on since you're already updating the corresponding docs.)

Left: requirements-dev.txt, Right: environments/dev-environment.yaml
image

@mfisher87
Copy link
Contributor

I could probably knock that out! I've used setup-micromamba a few times now. I'll see how the day plays out :)

@mfisher87
Copy link
Contributor

The test workflow and netlify builds use the requirements-dev.txt, so this ended up being a bit broader than expected. Is the netlify build configured in the repo somewhere, or in a GUI? Maybe removing requirements-dev.txt should be a different PR?

@maresb
Copy link
Contributor

maresb commented Sep 11, 2023

Ah, I'm so sorry, I didn't mean to send you down that rabbit hole!

Let's

  1. Undo the deletion of requirements-dev.txt
  2. Keep mention of requirements-dev.txt out of the docs, since I want to delete it
  3. Get this merged ASAP

I don't have access to Netlify myself, so it's a black box. We'll need help from @mariusvniekerk on this. I tried setting up Netlify through my GitHub, but this is what I end up with:

image

@mfisher87
Copy link
Contributor

Ah, I'm so sorry, I didn't mean to send you down that rabbit hole!

No sweat at all, I didn't fall in too deep :P I think I've got all the requests done now @maresb!

@mfisher87
Copy link
Contributor

@maresb I've used nwtgck/actions-netlify@v2 before to do Netlify deploys from GHA (both preview deploys and production deploys). With Actions, dealing with PRs from forks becomes complicated due to GitHub's security restrictions. Using pull_request event type with a fork PR denies access to repo secrets (needed to push to Netlify), and using pull_request_target event type denies access to the changes in the PR, so we can't preview.

One way I've seen to work around this is to have Actions build previews in response to comments (issue_comment event type) by people with a particular role, e.g. owner or maintainer, and containing specific text like /deploy-preview. Usually those projects will also have a bot that responds to new PRs to tell people how to request a preview, e.g.

🤖 Ping @conda-lock-team to request a docs preview. An owner or maintainer must post the comment /deploy-preview to trigger.

@mfisher87
Copy link
Contributor

requests.exceptions.HTTPError: 504 Server Error: Gateway Timeout for url: https://api.anaconda.org/download/conda-forge/micromamba/1.5.1/osx-64/micromamba-1.5.1-0.tar.bz2

I'm seeing this error 504 on PR #504 as well (just a coincidence :P )... I'm able to download this file just fine on my local machine.

@maresb
Copy link
Contributor

maresb commented Sep 11, 2023

I'm hoping that the error we're seeing is transient. I'm rerunning the failed tests.

I'm a bit confused by the last commit. Do we really want to offer requirements-dev.txt as an option for contributors to set up their dev environments? I see it more as a CI-only dependency.

Apart from that, this is really wonderful, and really boosts the code quality here! As soon as we clarify the README and the failing test I'm ready to merge.

@mfisher87
Copy link
Contributor

mfisher87 commented Sep 11, 2023

I'm hoping that the error we're seeing is transient. I'm rerunning the failed tests.

Looks like we're in luck 🥳

I'm a bit confused by the last commit

My fault, forgot I need to be pushing to @itsarobin's fork instead of mine :)

Thanks for supporting this change! It's always been a pleasure to interact on this repo ❤️

@maresb maresb merged commit 8b3dc62 into conda:main Sep 11, 2023
@maresb
Copy link
Contributor

maresb commented Sep 11, 2023

Thank you @mfisher87! Likewise, it's a pleasure to get such well-curated PRs that I can review in just a few minutes! All this refactoring and cleanup is greatly appreciated.

@mfisher87 mfisher87 deleted the issue-196 branch September 11, 2023 19:11
weiji14 added a commit to pangeo-data/pangeo-docker-images that referenced this pull request Sep 14, 2023
Shouldn't be needed anymore after conda/conda-lock#485. Also removed some extra whitespace.
scottyhq pushed a commit to pangeo-data/pangeo-docker-images that referenced this pull request Sep 14, 2023
* Bump conda-lock from 1.4 to 2.3

Bumps [conda-lock](https://github.com/conda/conda-lock) from 1.4.0 to 2.3.0.
- [Release notes](https://github.com/conda/conda-lock/releases)
- [Commits](conda/conda-lock@v1.4.0...v2.3.0)

* [condalock-command] autogenerated conda-lock files

* Remove rm conda-lock.yml workaround

Shouldn't be needed anymore after conda/conda-lock#485. Also removed some extra whitespace.

---------

Co-authored-by: pangeo-bot <pangeo-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants