Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to uv #303

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Switch to uv #303

wants to merge 1 commit into from

Conversation

brianhelba
Copy link
Contributor

No description provided.

@@ -30,17 +30,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
Copy link
Contributor Author

@brianhelba brianhelba Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uv docs suggest that keeping actions/setup-python can ultimately make the setup faster, since a Python will be installed in advance from a GitHub cache: https://docs.astral.sh/uv/guides/integration/github/#setting-up-python / https://github.com/astral-sh/setup-uv#do-i-still-need-actionssetup-python-alongside-setup-uv . I don't think I fully understand what this means.

I'm also not sure how much time this actually saves in reality, and it makes the configuration longer and more verbose.

@@ -32,7 +32,7 @@ dependencies = [
"sentry-sdk[celery,django]",
]

[project.optional-dependencies]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv automatically installs the dev dependency group by default, so switch dev from an extra to a dependency group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is worse, since it makes it possible to install dev without actually installing the package itself, which makes no sense.

@@ -1,5 +1,8 @@
[tox]
min_version = 4.22
requires =
tox
tox-uv
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause tox-uv to automatically get installed in an intermediate virtual environment. It's technically more efficient to run uvx --with tox-uv tox instead of uvx tox, but making this extra virtual environment and installing tox a second time is so fast with uv that I don't think it's worth making the command more awkward.

dev = [
"django-browser-reload",
"django-debug-toolbar",
"django-minio-storage",
"django-s3-file-field[minio]",
"iptools",
"ipython",
"tox",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tox should now be a uv "tool", which will be installed automatically by uvx tox, so there's no need to list it as a dev dependency.

dev = [
"django-browser-reload",
"django-debug-toolbar",
"django-minio-storage",
"django-s3-file-field[minio]",
"iptools",
"ipython",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether ipython should be removed. It's not used directly by most development workflows, but it does benefit ./manage.py shell_plus. Running uv run --with ipython ./manage.py shell_plus would technically get us to the same place, but I like the idea of it working by default.

An alternative is that it could be placed in its own dependency group, perhaps even one that's auto-included into dev.


ENV PYTHONDONTWRITEBYTECODE 1
Copy link
Contributor Author

@brianhelba brianhelba Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this and adding --compile-bytecode now totally inverts the policy, such that .pyc files will all be generated at package install time. This makes for larger images, but faster container initial startups, which I think is the right trade-off.

However, in reality, there's usually only one container ever created per image build (unless docker compose down is run significantly more often than docker compose build), so this is really just shifting the .pyc compilation time from one step to another.

Also, the --compile-bytecode option causes:

uv will process the entire site-packages directory (including packages that are not being modified by the current operation) for consistency

so maybe it's doing even more work than necessary.

@brianhelba brianhelba force-pushed the uv branch 2 times, most recently from 3e06794 to 8e00862 Compare February 13, 2025 04:34
dev = [
"django-browser-reload",
"django-debug-toolbar",
"django-minio-storage",
"django-s3-file-field[minio]",
"iptools",
"ipython",
"tox",
{include-group = "type"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a significant improvement, as type stubs (including the packages for the test environment) will be installed in the development environment, which significantly improves IDE autocomplete.

Some downstreams adopted the practice of putting these dependencies in an optional extra, but this approach is more correct and works more naturally with Tox.

@brianhelba
Copy link
Contributor Author

Consider https://github.com/dropseed/heroku-buildpack-uv to help with deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant