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

Add support for the .python-version file #272

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Conversation

edmorley
Copy link
Member

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:

  • Major Python version (e.g. 3.12, which will then be resolved to the latest Python 3.12). (This form is recommended, since it allows for Python security updates to be pulled in without having to manually bump the version.)
  • Exact Python version (e.g. 3.12.6)
  • Comments (lines starting with #)
  • Blank lines

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

  • Specifying multiple Python versions
  • Prefixing versions with python- (since this form is undocumented and will likely be deprecated in the future)

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

  • adding a mapping of major versions to the latest patch releases
  • explicit handling for EOL/unrecognised major versions
  • adding the concept of a "requested Python version" vs the resolved Python version (which should hopefully tie in well with use of a manifest in the future)

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.

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:
- Major Python version (e.g. `3.12`, which will then be resolved to the
  latest Python 3.12). (This form is recommended, since it allows for
  Python security updates to be pulled in without having to manually
  bump the version.)
- Exact Python version (e.g. `3.12.6`)
- Comments (lines starting with `#`)
- Blank lines

We don't support the following `.python-version` features:
- Specifying multiple Python versions
- Prefixing versions with `python-` (since this form is undocumented
  and will likely be deprecated in the future)

Since the `.python-version` file (unlike `runtime.txt`) supports
specifying just the Python major version, adding support also required:
- adding a mapping of major versions to the latest patch releases
- explicit handling for EOL/unrecognised major versions
- adding the concept of a "requested Python version" vs the resolved
  Python version (which should hopefully tie in well with use of a
  manifest in the future)

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.
@edmorley edmorley added the enhancement New feature or request label Sep 16, 2024
@edmorley edmorley self-assigned this Sep 16, 2024
README.md Show resolved Hide resolved
@edmorley edmorley marked this pull request as ready for review September 16, 2024 19:21
@edmorley edmorley requested a review from a team as a code owner September 16, 2024 19:21
@edmorley edmorley merged commit e3d1f4a into main Sep 17, 2024
8 checks passed
@edmorley edmorley deleted the python-version-file branch September 17, 2024 09:24
heroku-linguist bot added a commit that referenced this pull request Sep 17, 2024
## heroku/python

### Added

- The Python version can now be configured using a `.python-version` file. Both the `3.X` and `3.X.Y` version forms are supported. ([#272](#272))

### Changed

- pip is now only available during the build, and is longer included in the final app image. ([#264](#264))
- Improved the error messages shown when an end-of-life or unknown Python version is requested. ([#272](#272))
heroku-linguist bot added a commit to heroku/cnb-builder-images that referenced this pull request Sep 17, 2024
## heroku/python

### Added

- The Python version can now be configured using a `.python-version` file. Both the `3.X` and `3.X.Y` version forms are supported. ([#272](heroku/buildpacks-python#272))

### Changed

- pip is now only available during the build, and is longer included in the final app image. ([#264](heroku/buildpacks-python#264))
- Improved the error messages shown when an end-of-life or unknown Python version is requested. ([#272](heroku/buildpacks-python#272))
edmorley added a commit to heroku/heroku-buildpack-python that referenced this pull request Oct 14, 2024
Following on from the recent Python version refactoring, this now 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.

This change is the classic Python buildpack equivalent of the Python
CNB change here:
heroku/buildpacks-python#272

If both a `runtime.txt` file and a `.python-version` file are present,
then the `runtime.txt` file will take precedence. However, use of the
`.python-version` file is now recommended, since `runtime.txt` will
be deprecated in the future. Both the `runtime.txt` file and
`.python-version` file take precedence over any Python version specified
in a `Pipfile.lock` for Pipenv users.

We support the following `.python-version` syntax:
- Major Python version (e.g. `3.13`, which will then be resolved to the
  latest Python 3.13). (This form is recommended, since it allows for
  Python security updates to be pulled in without having to manually
  bump the version.)
- Exact Python version (e.g. `3.13.0`)
- Comments (lines starting with `#`)
- Blank lines

We don't support the following `.python-version` features:
- Specifying multiple Python versions
- Prefixing versions with `python-` (since this form is undocumented
  and will likely be deprecated by pyenv in the future)

In addition, the existing `runtime.txt` support has been updated to
allow specifying just the major Python version, in order to increase
feature parity between the files, and avoid confusion if users try to
use the major version only syntax from `.python-version` in their
`runtime.txt`.

Refs #913.
Refs #932.
GUS-W-7671453.
GUS-W-16821357.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic Python patch version updates Support the .python-version file
2 participants