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

Support wheel cache when using --require-hashes #11897

Merged
merged 11 commits into from
Apr 15, 2023

Conversation

sbidoul
Copy link
Member

@sbidoul sbidoul commented Mar 25, 2023

closes #5037

@ewdurbin would you like to test this and try to break it?

I'm not doing it for the bounty, as this is also one of the things in my way of actually using hashes. So hopefully we'll share a 🍺 if our paths cross one day.

TODO

  • investigate how this impacts pip wheel (I think it works but the warning should be silenced)

@ewdurbin
Copy link
Member

Exciting! I will do my very best to try to get pip built locally using this (I would honestly have attacked this myself if I knew how to get the dev env working 😂)

@sbidoul
Copy link
Member Author

sbidoul commented Mar 25, 2023

knew how to get the dev env working

Nothing fancy really: pip install -e . -r tests/requirements.txt in a venv goes a long way.

@sbidoul sbidoul force-pushed the cache-hash-checking-sbi branch 2 times, most recently from 9abf6b0 to a1c78e5 Compare March 25, 2023 15:37
@sbidoul sbidoul added this to the 23.1 milestone Mar 25, 2023
@sbidoul
Copy link
Member Author

sbidoul commented Mar 25, 2023

Combined with #11872, one can use --no-binary and benefit from caching and hash checking at the same time 🥳

@sbidoul sbidoul marked this pull request as ready for review March 25, 2023 17:35
news/5037.feature.rst Outdated Show resolved Hide resolved
@pfmoore
Copy link
Member

pfmoore commented Apr 1, 2023

I'd like to get this in 23.1. @ewdurbin if you can confirm it fixes the issue within the next week or so, that would be excellent. Please ask for help if you are still unsure how to test against the version with the PR.

@ewdurbin
Copy link
Member

ewdurbin commented Apr 1, 2023

Thanks for the ping. PyCon prep has me pretty slammed but I need to do some warehouse work in the next day or so. I'll try running from this branch to confirm it works in dev.

@ewdurbin
Copy link
Member

ewdurbin commented Apr 3, 2023

knew how to get the dev env working

Nothing fancy really: pip install -e . -r tests/requirements.txt in a venv goes a long way.

Hmmm, I guess I was tricked by the tox.ini in the past and never found success.

Testing this now.

@ewdurbin
Copy link
Member

ewdurbin commented Apr 3, 2023

Hmmmmm I must be holding it wrong, but with the refactor of our actions in https://github.com/pypi/warehouse/pull/13357/files I would have expected the pip cache to pick up the wheels from the new "deps" initial job, but no dice: https://github.com/pypi/warehouse/actions/runs/4596723814/jobs/8118550985

@pradyunsg
Copy link
Member

Cache not found for input keys: pip-Linux

There was no cache available when pip ran, based on the output of the cache action prior.

@ewdurbin
Copy link
Member

ewdurbin commented Apr 3, 2023

Cache not found for input keys: pip-Linux

There was no cache available when pip ran, based on the output of the cache action prior.

That was the first run, so there was no cache. The deps build step did create it:

deps stashes

Then the downstream build matrix was able to get it:

tests recv

@sbidoul
Copy link
Member Author

sbidoul commented Apr 3, 2023

@ewdurbin I don't immediately understand what's wrong with your test.

I rebased this PR in case there is some interaction with some previously unmerged pip 23.1 change.

FWIW, I just tried this script which shows it works fine.

#!/bin/bash
set -eaux -o pipefail

VENV=$(mktemp -d)
python -m venv $VENV
source $VENV/bin/activate
pip install -U git+https://github.com/pypa/pip@refs/pull/11897/head

REQS=$(mktemp)
export PIP_CACHE_DIR=$(mktemp -d)
export PIP_NO_BINARY=:all:

cat <<EOF > $REQS
lxml==4.9.2 \
  --hash sha256:2455cfaeb7ac70338b3257f41e21f0724f4b5b0c0e7702da67ee6c3640835b67 \
  --hash sha256:7b515674acfdcadb0eb5d00d8a709868173acece5cb0be3dd165950cbfdf5409
EOF

echo "======= first install builds from source"
pip install -r $REQS

echo "======= reinstall gets wheel from cache"
pip install --force-reinstall -r $REQS

@ewdurbin
Copy link
Member

ewdurbin commented Apr 3, 2023

@sbidoul seems rebasing was the trick! all deps were installed from cache 🎉

This is result expected and satisfies #5037 as I understand it.

@sbidoul
Copy link
Member Author

sbidoul commented Apr 7, 2023

This one is now ready.

"and re-downloading source."
)
req.link = direct_url_as_link(req.download_info)
link = req.link
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I'm afraid this part still needs some work. If req.download_info contains an invalid hash, it re-downloads an URL with an invalid hash fragment, which means we never get a good cache entry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I resolved this by adding a new cached_wheel_source_link field to InstallRequirement. I also renamed original_link_is_in_wheel_cache to is_wheel_from_cache to better reflect its meaning.

@sbidoul
Copy link
Member Author

sbidoul commented Apr 10, 2023

So this is ready again 🟢

@sbidoul
Copy link
Member Author

sbidoul commented Apr 13, 2023

I'm fairly confident this change is correct and safe. I'll be available post-release to handle any issue as quickly as possible.
In the next iteration I plan to follow-up with #11943 and #6469.

link: Link,
download_dir: str,
hashes: Optional[Hashes],
warn_on_hash_mismatch: bool = True,
Copy link
Member

Choose a reason for hiding this comment

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

Not some that needs to change, I’m just suddenly curious how peopel choose between positive and negative flags. Personally I’d probably choose to implement this as suppress_hash_mismatch_warning=False.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case I think I wanted to avoid a double negation and save half a brain cycle when reading the only condition using this flag.

Comment on lines 112 to 115
# When is_wheel_from_cache is True, it means that this InstallRequirement
# is a local wheel file in the cache of locally built wheels.
self.is_wheel_from_cache = False
# When is_wheel_from_cache is True, this is the source link corresponding
# to the cache entry, which was used to download and build the cached wheel.
self.cached_wheel_source_link: Optional[Link] = None
Copy link
Member

Choose a reason for hiding this comment

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

Do we need two attributes for this? From what I can tell these are always set together and is_wheel_from_cache can be entirely implied by cached_wheel_source_link is not None.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is indeed a logical next step in this refactoring. Done.

@pfmoore
Copy link
Member

pfmoore commented Apr 15, 2023

@sbidoul This is going to miss 23.1. If you want to get it included in that release, can you do anything in the next hour or two? Otherwise, I'll push it to 23.2.

@sbidoul sbidoul merged commit dbf4e68 into pypa:main Apr 15, 2023
@sbidoul sbidoul deleted the cache-hash-checking-sbi branch April 15, 2023 09:38
@pfmoore
Copy link
Member

pfmoore commented Apr 15, 2023

Wow, that was quick! Thanks.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support wheel cache when using --require-hashes
5 participants