-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Description
The project currently uses runtime.txt to specify the Python version (python-3.13.3). This file is primarily used by cloud platforms like Heroku and some legacy deployment systems. However, the modern Python ecosystem has standardized on .python-version as the preferred method for specifying Python versions.
Current State
- File:
runtime.txtcontainspython-3.13.3 - Usage: Not actively used in CI/CD (GitHub Actions uses hardcoded env var)
- Docker: Python version is hardcoded in
Dockerfile(3.13.3) - Status:
.python-versionis currently in.gitignore(line 89)
Why Migrate?
- Standardization:
.python-versionis supported by multiple tools (pyenv, asdf, mise, direnv) - Developer Experience: Automatic version switching when entering the project directory
- CI/CD Integration: GitHub Actions
setup-pythoncan read from.python-version - Consistency: Single source of truth for Python version across environments
- Modern Practice: Aligns with current Python tooling ecosystem standards
Proposed Solution
1. Create .python-version file
Create a new file in the project root containing only the Python version number.
2. Update .gitignore
Uncomment or remove the .python-version exclusion to track it in version control.
3. Update GitHub Actions workflow
Modify .github/workflows/python-app.yml to read version from .python-version instead of hardcoded env variable.
4. Update documentation
Update README.md to mention .python-version usage and benefits for contributors.
5. Remove runtime.txt
Delete the legacy file after confirming no deployment dependencies.
6. Consider Dockerfile updates
Optionally create a mechanism to keep Dockerfile Python version in sync.
Suggested Approach
Step 1: Create .python-version
Create file at project root:
3.13.3
Step 2: Update .gitignore
File: .gitignore (line ~89)
Change:
# .python-versionTo:
# Track .python-version for consistent Python version across environmentsStep 3: Update GitHub Actions
File: .github/workflows/python-app.yml
Before (lines 16-17):
env:
PYTHON_VERSION: 3.13.3After:
# PYTHON_VERSION is now read from .python-version fileBefore (lines 29-31):
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}After:
- name: Set up Python
uses: actions/setup-python@v6.0.0
with:
python-version-file: '.python-version'Before (lines 55-57):
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v6.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}After:
- name: Set up Python
uses: actions/setup-python@v6.0.0
with:
python-version-file: '.python-version'Step 4: Update README.md
File: README.md
Add a new section after "About" or in "Install":
## Python Version Management
This project uses `.python-version` to specify the required Python version. If you use [pyenv](https://github.com/pyenv/pyenv), [asdf](https://asdf-vm.com/), or [mise](https://mise.jdx.dev/), the correct Python version will be automatically activated when you enter the project directory.
Alternatively, ensure you have Python 3.13.3 (or the version specified in `.python-version`) installed.Step 5: Remove runtime.txt
Delete the file:
rm runtime.txtStep 6 (Optional): Dockerfile Automation
Add a comment in Dockerfile at line 5 and 22:
# Python version should match .python-version file (currently 3.13.3)
FROM python:3.13.3-slim-bookworm AS builderOr create a build script that reads .python-version and passes it as a build arg.
Acceptance Criteria
-
.python-versionfile exists at project root with content3.13.3 -
.python-versionis tracked in git (not ignored) - GitHub Actions workflow successfully uses
python-version-file: '.python-version' - Both
lintandtestjobs in CI pass with the new configuration -
PYTHON_VERSIONenvironment variable is removed from workflow -
runtime.txtis deleted from the repository -
README.mddocuments the use of.python-version - All CI/CD checks pass (linting, testing, coverage)
- Docker builds continue to work (no regression)
- Documentation mentions benefits for developers using pyenv/asdf/mise