Skip to content

Commit e1bf104

Browse files
committed
Pin Python minor version and document upgrade details
1 parent ecc0dd0 commit e1bf104

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

app/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# The build stage that will be used to deploy to the various environments
55
# needs to be called `release` in order to integrate with the repo's
66
# top-level Makefile
7-
FROM python:3-slim AS base
7+
FROM python:3.12-slim AS base
8+
# See /docs/app/README.md#Upgrading Python
9+
# for details on upgrading your Python version
810

911
# Install poetry, the package manager.
1012
# https://python-poetry.org

app/poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ packages = [{ include = "src" }]
66
authors = ["Nava Engineering <[email protected]>"]
77

88
[tool.poetry.dependencies]
9-
python = "^3.12"
9+
# See /docs/app/README.md#Upgrading Python
10+
# for details on upgrading your Python version
11+
python = "~3.12"
1012
SQLAlchemy = {version = "^2.0.21", extras = ["mypy"]}
1113
alembic = "^1.12.0"
1214
python-dotenv = "^1.0.0"

docs/app/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,60 @@ The API can be run in debug mode that allows for remote attach debugging (curren
152152
]
153153
}
154154
```
155+
156+
# Upgrading Python
157+
Python does [yearly releases](https://devguide.python.org/versions/) for their minor versions (eg. 3.12 -> 3.13). They do not
158+
use semvar versioning, and their [minor releases](https://devguide.python.org/developer-workflow/development-cycle/#devcycle) contain
159+
breaking changes.
160+
161+
We have this environment configured to use a specific minor version of python just in case anything would break when the yearly release does occur.
162+
163+
We recommend as a starting point, only pin the minor versions of Python (eg. 3.12), and not the patch versions (eg. 3.12.1) as those contain bug and security fixes.
164+
However, your project may have dependencies, or tools that rely on very specific patch versions of Python, so adjust your approach as necessary.
165+
166+
Along with any version upgrades, you should follow all best practices for upgrading software and test the functionality
167+
of your system before deploying to production. It is also recommended to review the [changelog](https://docs.python.org/3/whatsnew/changelog.html)
168+
for any breaking changes of features you may use.
169+
170+
## Local Development
171+
If you run any of the python code outside of the Docker container, first upgrade your version
172+
of Python locally. The exact way you upgrade will depend on how you originally installed Python,
173+
but one strongly recommended approach is to use [pyenv](https://github.com/pyenv/pyenv) which allows
174+
you to install and swap between different python versions locally.
175+
176+
If you run commands with Poetry, you'll also need to [configure](https://python-poetry.org/docs/managing-environments/#switching-between-environments)
177+
it to use the approach python version.
178+
179+
## Dockerfile
180+
The dockerfile that our API is built from specifies the Python version as the first step.
181+
To upgrade this, simply change the version to the version you would like to use.
182+
183+
For example, to upgrade from 3.12 to 3.13, change the following line:
184+
```dockerfile
185+
FROM python:3.12-slim AS base
186+
```
187+
to
188+
```dockerfile
189+
FROM python:3.13-slim AS base
190+
```
191+
192+
## Poetry
193+
Adjust the pyproject.toml file line that specifies the version of Python used
194+
to your new version. For example, to upgrade from 3.12 to 3.13, change it from:
195+
196+
```toml
197+
[tool.poetry.dependencies]
198+
python = "~3.12"
199+
```
200+
201+
to
202+
```toml
203+
[tool.poetry.dependencies]
204+
python = "~3.13"
205+
```
206+
207+
You will then need to run `poetry lock --no-update` to make the lock file reflect this change.
208+
209+
## Misc
210+
Some tools, include pyenv, reference the [.python-version](/app/.python-version) file in order to determine which
211+
version of python should be used. Update this to the approach version as well.

0 commit comments

Comments
 (0)