heroku / buildpacks-python

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

Add support for the `.python-version` file #272

Closed edmorley closed 1 month ago

edmorley commented 1 month ago

This adds support for configuring the app's Python version using a .python-version file. This file is used by several tools in the Python ecosystem (such as pyenv, actions/setup-python, uv), whereas the existing runtime.txt file is proprietary to Heroku.

For now, if both a runtime.txt file and a .python-version file are present, then the runtime.txt file will take precedence. In the future, support for runtime.txt will be deprecated (and eventually removed) in favour of the .python-version file.

We support the following .python-version syntax:

We don't support the following .python-version features:

Since the .python-version file (unlike runtime.txt) supports specifying just the Python major version, adding support also required:

In addition, the "origin" of a Python version now has to be tracked, so that build output can state which file was used, or in the case of invalid version errors, which file needs to be fixed by the user.

Closes #6. Closes #9. GUS-W-12151504. GUS-W-11475071.