-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Switch to uv #303
Conversation
@@ -30,17 +30,11 @@ jobs: | |||
steps: | |||
- name: Checkout repository | |||
uses: actions/checkout@v4 | |||
- name: Set up Python | |||
uses: actions/setup-python@v5 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
3e06794
to
8e00862
Compare
dev = [ | ||
"django-browser-reload", | ||
"django-debug-toolbar", | ||
"django-minio-storage", | ||
"django-s3-file-field[minio]", | ||
"iptools", | ||
"ipython", | ||
"tox", | ||
{include-group = "type"}, |
There was a problem hiding this comment.
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.
Consider https://github.com/dropseed/heroku-buildpack-uv to help with deployment. |
No description provided.