heroku / buildpacks-python

Heroku's Cloud Native Buildpack for Python applications.
BSD 3-Clause "New" or "Revised" License
27 stars 3 forks source link

Warn or error if a virtual environment was included in the app source #271

Open edmorley opened 1 month ago

edmorley commented 1 month ago

When using Python virtual environments, it's common to store the virtual environment (aka venv / virtualenv) inside the project directory, inside a directory named .venv/ or venv/. (At least when creating them manually, or using 'uv' which prefers storing them inside the project. Poetry/Pipenv prefer a global venv location outside of the project.)

This directory should always be added to the .gitignore, but sometimes users forget, meaning it is committed to the Git repo, and will be included in the app source when using a Git based deployment mechanism (such as git push heroku main).

In addition, even if users add the .venv/ to their .gitignore, it will still be included in the app source when building locally using pack build, unless they know to also exclude the directory via the project.toml exclude field: https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md#iobuildpacksinclude-optional-and-iobuildpacksexclude-optional

(Even if they have added the .venv to their .dockerignore that won't help, since Pack CLI doesn't use that file - at least not yet; perhaps we should suggest this upstream?)

We should warn or even error if a .venv/ or venv/ directory is present during the build, since:

GUS-W-12421020.