Skip to content

Change the editable VCS directory location for pip and Pipenv #1753

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

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Feb 19, 2025

When a dependency from a version control system (eg Git) is installed in editable mode, the package manager has to clone the repository somewhere long-lived, that is then referenced by the .pth file added to site-packages. (When installed in normal non-editable mode, the repo checkouts are instead saved to a temporary directory and deleted after the package is installed.)

Until now, the buildpack configured pip and Pipenv to store these repos at /app/.heroku/src/, then later copied those files into the build directory and build cache. However, this approach isn't needed with the .pth rewriting we have now. In addition, the existing implementation didn't actually restore the cached src/ directory, so the repos stored in the cache were never re-used on subsequent builds anyway.

Now, pip and pipenv are configured to store the repositories at <BUILD_DIR>/.heroku/python/src/, which means:

  • The behaviour now matches that when using Poetry.
  • The repos get cached/restored/invalidated for free, as part of the existing handling of the .heroku/python/ directory, and we avoid the additional directory copy from /app to /tmp, both of which help reduce build times.

GUS-W-17863838.

When a dependency from a version control system (eg Git) is installed
in editable mode, the package manager has to clone the repository
somewhere long-lived, that is then referenced by the `.pth` file added
to `site-packages`. (When installed in normal, non-editable mode, the
repo checkouts are instead deleted after the package is installed.)

Until now, the buildpack configured pip and Pipenv to store these repos
at `/app/.heroku/src/`, then later copied those files into the build
directory and build cache. However, this approach isn't needed with the
`.pth` rewriting we have now. In addition, the implementation didn't
restore the cached `src/` directory, so the repos stored in the cache
were never actually re-used on subsequent builds anyway.

Now, pip and pipenv are configured to store the repositories at
`<BUILD_DIR>/.heroku/python/src/`, which means:
- The behaviour now matches that when using Poetry.
- The repos get cached/restored/invalidated for free, as part of the
  existing handling of the `.heroku/python/` directory, and we
  avoid the additional directory copy from `/app` to `/tmp`, both of
  which help reduce build times.
@edmorley edmorley self-assigned this Feb 19, 2025
@edmorley edmorley marked this pull request as ready for review February 19, 2025 16:17
@edmorley edmorley requested a review from a team as a code owner February 19, 2025 16:17
@edmorley edmorley enabled auto-merge (squash) February 19, 2025 16:22
@edmorley edmorley merged commit ee0a9eb into main Feb 19, 2025
8 checks passed
@edmorley edmorley deleted the move-vcs-src-dir branch February 19, 2025 16:30
edmorley added a commit that referenced this pull request Feb 21, 2025
Heroku builds occur at a different path to which the app will be run
at run-time. As such, we have to perform path rewriting for editable
dependencies, so that they work after relocation.

The existing rewriting is performed at app boot (see code comment for
more details), and works fine with pip and Poetry.

However, I discovered that Pipenv doesn't correctly reinstall editable
VCS dependencies if they use the new PEP660 style editable interface,
which I've reported upstream here:
pypa/pipenv#6348

This issue has affected apps using editable VCS dependencies with Pipenv
for some time, but until now only at build-time for cached builds.

However, after #1753 (which thankfully isn't yet released, due to me
catching this as part of updating the tests to exercise the new PEP660
style editable interface) would otherwise affect apps at run-time too.

As a workaround, we can perform build time rewriting of paths too, but
must do so only for VCS dependencies (see code comment for why).

Lastly, the Pipenv bug also requires that we perform explicit cache
invalidation for Pipenv apps after the src dir move in #1753.
edmorley added a commit that referenced this pull request Feb 21, 2025
Heroku builds occur at a different path to which the app will be run
at run-time. As such, we have to perform path rewriting for editable
dependencies, so that they work after relocation.

The existing rewriting is performed at app boot (see code comment for
more details), and works fine with pip and Poetry.

However, I discovered that Pipenv doesn't correctly reinstall editable
VCS dependencies if they use the new PEP660 style editable interface,
which I've reported upstream here:
pypa/pipenv#6348

This issue has affected apps using editable VCS dependencies with Pipenv
for some time, but until now only at build-time for cached builds.

However, after #1753 (which thankfully isn't yet released, due to me
catching this as part of updating the tests to exercise the new PEP660
style editable interface) would otherwise affect apps at run-time too.

As a workaround, we can perform build time rewriting of paths too, but
must do so only for VCS dependencies (see code comment for why).

Lastly, the Pipenv bug also requires that we perform explicit cache
invalidation for Pipenv apps after the src dir move in #1753.
edmorley added a commit that referenced this pull request Feb 21, 2025
Heroku builds occur at a different path to which the app will be run
at run-time. As such, we have to perform path rewriting for editable
dependencies, so that they work after relocation.

The existing rewriting is performed at app boot (see code comment for
more details), and works fine with pip and Poetry.

However, I discovered that Pipenv doesn't correctly reinstall editable
VCS dependencies if they use the new PEP660 style editable interface,
which I've reported upstream here:
pypa/pipenv#6348

This issue has affected apps using editable VCS dependencies with Pipenv
for some time, but until now only at build-time for cached builds.

However, after #1753 (which thankfully isn't yet released, due to me
catching this as part of updating the tests to exercise the new PEP660
style editable interface) would otherwise affect apps at run-time too.

As a workaround, we can perform build time rewriting of paths too, but
must do so only for VCS dependencies (see code comment for why).

Lastly, the Pipenv bug also requires that we perform explicit cache
invalidation for Pipenv apps after the src dir move in #1753.

GUS-W-17884520.
edmorley added a commit that referenced this pull request Feb 22, 2025
Heroku builds occur at a different path to which the app will be run
at run-time. As such, we have to perform path rewriting for editable
dependencies, so that they work after relocation.

The existing rewriting is performed at app boot (see code comment for
more details), and works fine with pip and Poetry.

However, I discovered that Pipenv doesn't correctly reinstall editable
VCS dependencies if they use the new PEP660 style editable interface,
which I've reported upstream here:
pypa/pipenv#6348

This issue has affected apps using editable VCS dependencies with Pipenv
for some time, but until now only at build-time for cached builds.

However, after #1753 (which thankfully isn't yet released, due to me
catching this as part of updating the tests to exercise the new PEP660
style editable interface) would otherwise affect apps at run-time too.

As a workaround, we can perform build time rewriting of paths too, but
must do so only for VCS dependencies (see code comment for why).

Lastly, the Pipenv bug also requires that we perform explicit cache
invalidation for Pipenv apps after the src dir move in #1753.

GUS-W-17884520.
@heroku-linguist heroku-linguist bot mentioned this pull request Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants