Repository navigation
Upgrading python, uv, and dependencies
Every January, we need to upgrade the python version to the latest version. When we upgrade the python version, we also need to upgrade the dependencies of the project to ensure that they are compatible with the new python version.
Steps to upgrade the python version and dependencies:
- Upgrade the python version in the local environment and in the Dockerfile. e.g.
3.12 -> 3.13 - Upgrade
uvversion - project dependencies (libs and app)
Avoid duplicate tooling versions across apps. Common packages should be centralized in the pyproject.toml file in the
root of the monorepo.
[dependency-groups]
dev = [
"ruff>=0.4.2,<0.5",
"mypy>=1.10,<2",
"pytest>=8,<9"
]When we upgrade the python version is recommended to check and fix breaking changes first and then upgrade the dependencies.
This approach allows us to identify any compatibility issues early on and address them before upgrading all the
dependencies and reducing the risk of breaking the code. We should update uv the last,
as it is the tool we use to manage the dependencies and virtual environments,
and we want to ensure that it is compatible with the new python version before upgrading it. Upgrade the dependencies
gradually, starting with the most critical ones, and then upgrading the rest of the dependencies.
— Check the current python version
python --version
— Upgrade python to the latest version
brew update
brew upgrade
brew install python@3.12
— Check the python version again
python --version
ARG PYTHON_VERSION=3.13
FROM python:${PYTHON_VERSION}-slim-bookwormrequires-python = ">=3.13,<4"
uv lock --upgrade
uv sync
uv run python --version##dockerifle# Step 1 — Update Dockerfile
ARG UV_VERSION=0.11.7
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
FROM python:${PYTHON_VERSION}-slim-bookworm
COPY --from=uv /uv /bin/uv
curl -Ls https://astral.sh/uv/install.sh | shuv --versionThis step is necessary to ensure that the dependencies are compatible with the new python version. It is recommended to upgrade the dependencies selectively (Step 2), starting with the most critical ones, and then upgrading the rest of the dependencies. This approach allows you to identify any compatibility issues early on and address them before upgrading all the dependencies and reducing the risk of breaking the code.
uv lock --upgrade-package <package>Example: uv lock --upgrade-package ruff
In pyproject.toml file, we control the versions of the dependencies e.g. ruff>=0.4.2,<0.5, so when we run
the command uv lock --upgrade-package ruff you won't upgrade to the latest version. My recommendation is to upgrade
the dependencies one by one updating the pyproject.toml file.
Use the command uv tree to see the dependency tree and check the dependencies that need to be updated.
You can use uv tree | grep pytest to check the version of pytest and see if it is compatible with the new python version.
Use pip pages to check the latest version of the dependencies and update the pyproject.toml file accordingly.
uv lock --upgrade
uv sync
Run this command for all the applications in the monorepo to check the code style and linting issues, and to fix them if possible.
make check-code APP_PATH=app/ht_indexer
make fix-code APP_PATH=app/ht_indexermake type-check APP_PATH=app/ht_indexerStep 2 — Run tests
make test-alldocker compose run --rm ht-indexer-tests
docker compose run --rm solr-query-tests