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

Fix for Pipenv not caching dependencies #1130

Closed
wants to merge 2 commits into from

Conversation

litchfield
Copy link

Having 'git' in one of your package names will prevent your deps from caching, resulting in painfully long build times. This is a simple fix.

@litchfield litchfield requested a review from a team as a code owner December 8, 2020 13:35
@litchfield litchfield changed the title Pipfile cache fix when not using git deps Fixed for Pipenv not caching dependencies Dec 8, 2020
@litchfield litchfield changed the title Fixed for Pipenv not caching dependencies Fix for Pipenv not caching dependencies Dec 8, 2020
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

@litchfield Sorry for the delayed reply. I don't suppose you have a testcase Pipfile + Pipfile.lock I can use to try out the before/after?

I'm also curious about the choices behind the buildpack's existing behaviour to skip pipenv install. Specifically:

  1. Is the speedup here from not having to install pipenv itself, or in being able to skip the pipenv install step?
  2. Why does this code even need to check for the presence of git in Pipfile.lock at all? Surely the lockfile should have an explicit SHA256 and not a branch name, so be deterministic? If not, should pipenv change here?

@litchfield
Copy link
Author

Thanks. Reading the patch, this was a quick fix to tighten existing regex and get it working. But I agree, not sure why we would even check if we have a lock file. I don’t have a pip file handy but any with a git source reference should do it.

@edmorley
Copy link
Member

edmorley commented Apr 8, 2021

Reading through #656 and #654 it appears the issue is more to to with editable dependencies rather than git. I'm pretty sure this is due to the path rewriting hacks (#1006 has some background on these) meaning that editable installs aren't correctly restored for subsequent builds.

Hopefully in the future when we can remove the path rewriting the need to repeat the pipenv install may go away.

@edmorley edmorley added the bug label Sep 21, 2022
edmorley added a commit that referenced this pull request Jan 5, 2024
Previously the buildpack would skip running `pipenv install` for repeat
Pipenv builds if (a) the SHA256 of the `Pipfile.lock` file had not changed
since the last successful build, and (b) there were no Git VCS references
in the lockfile.

However, this has a few issues:
1. There are other cases where it's not safe to assume that there is no
    need to re-run `pipenv install`, such as when installing a non-editable
    local dependency (see #1525), or when using editable local dependencies
    with the current path re-writing strategy (see #1520).
2. The current Git VCS check has false positives (see #1130, #1398).
3. Even if we try and add more checks/workarounds to resolve (1) and (2),
    we're still having to make assumptions about internal Pipenv implementation
    details, and hardcode these in the buildpack, hoping we didn't miss anything
    and that Pipenv's behaviour doesn't change over time (which is not the case,
    as seen by the recent regression pypa/pipenv#6054)

As such, we now instead always re-run `pipenv install`, and defer to Pipenv to
decide whether the environment needs updating.

This should still be fast, since the cached `site-packages` is still being used (and
if there are any scenarios in which it's not fast, then that's an upstream Pipenv
bug).

Integration tests were also added for various types of editable Pipenv installs,
since we previously only had test coverage of editable installs for Pip.

Fixes #1520.
Fixes #1525.
Closes #1130.
Closes #1398.
@edmorley
Copy link
Member

edmorley commented Jan 5, 2024

The fragile git check has been removed as of #1526. The pipenv install step is now run every time, however, this doesn't mean the cache isn't used. The site-packages directory is still cached - it will just now be up to Pipenv to determine whether the environment needs updating, or whether the install step can no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants