Migrate generated project from runtime.txt to .python-version

Heroku now supports the `.python-version` file as an alternative to the
Heroku-specific (and now deprecated) `runtime.txt` file, and recommends
apps switch to using the former since it's more widely supported by other
tooling.

The `.python-version` file is supported by pyenv, uv, the GitHub Actions
`setup-python` action and many others.

In addition, the `.python-version` file supports the version being specified
as just the major version (eg `3.12` vs `3.12.N`) which means will pick up
Python patch updates automatically (which is the recommended usage on
Heroku).

See:
https://devcenter.heroku.com/changelog-items/3005
https://github.com/heroku/heroku-buildpack-python/issues/1642
https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#using-the-python-version-file-input
This commit is contained in:
Ed Morley 2025-01-22 22:05:06 +00:00
parent bb6e4085c7
commit 665e3e2578
No known key found for this signature in database
GPG Key ID: 82FED877C369F134
6 changed files with 6 additions and 9 deletions

View File

@ -76,7 +76,7 @@ def remove_utility_files():
def remove_heroku_files():
file_names = ["Procfile", "runtime.txt", "requirements.txt"]
file_names = ["Procfile", "requirements.txt"]
for file_name in file_names:
if file_name == "requirements.txt" and "{{ cookiecutter.ci_tool }}".lower() == "travis":
# don't remove the file if we are using travisci but not using heroku

View File

@ -98,7 +98,7 @@ updates:
# Enable version updates for Python/Pip - Production
- package-ecosystem: 'pip'
# Look for a `requirements.txt` in the `root` directory
# also 'setup.cfg', 'runtime.txt' and 'requirements/*.txt'
# also 'setup.cfg', '.python-version' and 'requirements/*.txt'
directory: '/'
# Every weekday
schedule:

View File

@ -28,7 +28,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version-file: '.python-version'
{%- if cookiecutter.open_source_license != 'Not open source' %}
# Consider using pre-commit.ci for open source project
@ -88,9 +88,9 @@ jobs:
{%- else %}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version-file: '.python-version'
cache: pip
cache-dependency-path: |
requirements/base.txt

View File

@ -59,9 +59,6 @@ docs/_build/
# PyBuilder
target/
# pyenv
.python-version
{% if cookiecutter.use_celery == 'y' -%}
# celery beat schedule file
celerybeat-schedule

View File

@ -0,0 +1 @@
3.12

View File

@ -1 +0,0 @@
python-3.12.7