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

Support the .python-version file #6

Closed
edmorley opened this issue Feb 28, 2023 · 7 comments · Fixed by #272
Closed

Support the .python-version file #6

edmorley opened this issue Feb 28, 2023 · 7 comments · Fixed by #272
Assignees
Labels
enhancement New feature or request

Comments

@edmorley
Copy link
Member

edmorley commented Feb 28, 2023

We should support the .python-version file as a means for specifying what Python version an app is using.

This file format (used by pyenv and others) now also supports specifying Python versions in the X.Y format (and not just X.Y.Z), making it a strong contender over the Heroku-specific runtime.txt file.

Officially supported syntax:

  • 3.12.6
  • 3.12
  • comments (lines starting with #)
  • blank lines
  • pyenv supports specifying multiple versions, however, this buildpack can't, so we'll either want to only use the first version, or error if there are multiple versions specified

Unofficially supported syntax:

...though the python- forms are undocumented and likely going to be deprecated soon (pyenv/pyenv#3054 (comment)), so I'm leaning towards not supporting them.

For more background, see:

@edmorley
Copy link
Member Author

edmorley commented Sep 9, 2024

I found a bug in pyenv's handling of some of the more obscure syntax variants, which I filed as:
pyenv/pyenv#3054

And have opened pyenv/pyenv#3056 to fix.

@edmorley edmorley self-assigned this Sep 16, 2024
edmorley added a commit that referenced this issue Sep 16, 2024
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.

We support the following `.python-version` syntax:
- Major Python version (eg `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 (eg `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)

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 eventually be deprecated (and
eventually removed) in favour of the `.python-version` file.

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 fixing by the user.

Closes #6.
Closes #9.
GUS-W-12151504.
GUS-W-11475071.
edmorley added a commit that referenced this issue Sep 16, 2024
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 eventually be deprecated (and
eventually removed) in favour of the `.python-version` file.

We support the following `.python-version` syntax:
- Major Python version (eg `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 (eg `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 fixing by the user.

Closes #6.
Closes #9.
GUS-W-12151504.
GUS-W-11475071.
edmorley added a commit that referenced this issue Sep 16, 2024
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.
@megahall
Copy link

I created a one line .python-version containing 3.12 and tested this on Heroku but it did not work for me. Is there some special procedure or ETA before this buildpack update kicks in?

remote: -----> Python app detected
remote: -----> No Python version was specified. Using the same version as the last build: python-3.12.6
remote:        To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes

@edmorley
Copy link
Member Author

@megahall Hi! This repository is for the Heroku Python Cloud Native Buildpack (the next generation of buildpacks, currently in preview), rather than the existing (classic) Heroku Python buildpack, which is at:
https://github.com/heroku/heroku-buildpack-python

Support for Poetry and .python-version will be backported to the classic buildpack soon, but if you wanted to try out the Python CNB in the meantime, there is more information here:
https://github.com/heroku/buildpacks

@edmorley
Copy link
Member Author

Support for Poetry and .python-version will be backported to the classic buildpack soon

To track that, subscribe to:

@merwok
Copy link

merwok commented Sep 17, 2024

if you wanted to try out the Python CNB in the meantime, there is more information here

I was curious about this, as I’ve been following recent activity, but all the docs I found talk about running tools locally, not using the CNB on heroku.

@edmorley
Copy link
Member Author

all the docs I found talk about running tools locally, not using the CNB on heroku.

Yeah it's currently not possible to use CNBs on Heroku (only locally using the Pack CLI), however, that's coming soon:
heroku/roadmap#20

@edmorley
Copy link
Member Author

If there is a way to make this clearer in the docs, feedback welcome :-)

(This repo's README has a banner here which links to a CNB overview repo that links to the roadmap item here - but perhaps the latter needs a specific banner call-out?)

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 a pull request may close this issue.

3 participants