Skip to content

Commit

Permalink
Migrate generated project from runtime.txt to .python-version (#5652
Browse files Browse the repository at this point in the history
)

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
heroku/heroku-buildpack-python#1642
https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#using-the-python-version-file-input
  • Loading branch information
edmorley authored Jan 26, 2025
1 parent 70bd35d commit 827d357
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/.github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions {{cookiecutter.project_slug}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ docs/_build/
# PyBuilder
target/

# pyenv
.python-version

{% if cookiecutter.use_celery == 'y' -%}
# celery beat schedule file
celerybeat-schedule
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/runtime.txt

This file was deleted.

0 comments on commit 827d357

Please sign in to comment.