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

Speed up update-python3-dependencies #7234

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Speed up update-python3-dependencies #7234

merged 1 commit into from
Oct 9, 2024

Conversation

legoktm
Copy link
Member

@legoktm legoktm commented Sep 23, 2024

Status

Ready for review

Description of Changes

The make update-python3-dependencies step is slow for two main reasons: container image layering and pip-compile.

Switch to the new uv tool, which reimplements pip-compile in a much faster way. The output is basically the same, except the sorting is smarter (e.g. pytest comes before pytest-cov) and package names are properly normalized. We can also drop the --allow-unsafe because uv is entirely independent of setuptools and pip-tools.

Because uv is independent of the system Python (it's pure Rust), we can run it on the host and outside the container, so no image rebuilding happens during the updates, it'll just be needed once afterwards.

uv is still quite new to the Python ecosystem, but this allows us to begin using it without any lock-in, it should be trivial to swap back to pip-tools if needed.

Overall make update-python3-dependencies now takes seconds to run instead of minutes \o/

Refs freedomofpress/securedrop-tooling#16.

Testing

How should the reviewer test this PR?

  • Visual review; no changes to dependencies outside of removal of pip-tools
  • Run make update-python3-dependencies yourself.

Deployment

Any special considerations for deployment? n/a

Checklist

  • Linting (make lint) and tests (make test) pass in the development container
  • Linting and tests (make -C admin test) pass in the admin development container
  • I have written a test plan and validated it for this PR
  • I have opened a PR in the docs repo for these changes, or will do so later
    • I'll do this post-merge

@legoktm legoktm requested a review from a team as a code owner September 23, 2024 20:12
@legoktm
Copy link
Member Author

legoktm commented Sep 23, 2024

This is a rather conservative PR, there are other places we could be swapping in uv for speed like in CI or in admin/, but I think we can start with this for now and expand it over time.

Copy link
Member

@cfm cfm left a comment

Choose a reason for hiding this comment

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

This looks like a great improvement. Given the relatively privileged place pip-compile or uv occupies in our toolchain—as the producer of hashes for build-time verification—I would question the adoption of uv if it were closed-source. (Or at least I'd want us to do something like verify its output with pip-compile in CI.) But since it's (a) open-source, (b) format-compatible, and (c) as easily swapped out as you've swapped it in here, I don't much care how it's funded. :-)

I'll leave this open for other feedback for twenty-four hours. Barring objections, I'll approve and merge it tomorrow.

@cfm
Copy link
Member

cfm commented Oct 7, 2024

Ah, @legoktm, do you mind rebasing after #7233?

@cfm cfm added blocked needs/discussion queued up for discussion at future team meeting. Use judiciously. labels Oct 7, 2024
@cfm cfm removed blocked needs/discussion queued up for discussion at future team meeting. Use judiciously. labels Oct 8, 2024
@cfm
Copy link
Member

cfm commented Oct 8, 2024

Discussed further out of band: no objections.

@legoktm
Copy link
Member Author

legoktm commented Oct 9, 2024

I'm gonna make one change, we don't actually need to run this in the container anymore, so it'll be even faster.

The `make update-python3-dependencies` step is slow for two main
reasons: container image layering and pip-compile.

Switch to the new uv tool, which reimplements pip-compile in a much
faster way. The output is basically the same, except the sorting is
smarter (e.g. pytest comes before pytest-cov) and package names are
properly normalized. We can also drop the `--allow-unsafe` because uv is
entirely independent of setuptools and pip-tools.

Because uv is independent of the system Python (it's pure Rust), we can
run it on the host and outside the container, so no image rebuilding
happens during the updates, it'll just be needed once afterwards.

uv is still quite new to the Python ecosystem, but this allows us to
begin using it without any lock-in, it should be trivial to swap back to
pip-tools if needed.

Overall `make update-python3-dependencies` now takes seconds to run
instead of minutes \o/

Refs <freedomofpress/securedrop-tooling#16>.
Copy link
Member

@cfm cfm left a comment

Choose a reason for hiding this comment

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

@cfm cfm added this pull request to the merge queue Oct 9, 2024
Merged via the queue into develop with commit 7c291d0 Oct 9, 2024
30 checks passed
@legoktm legoktm deleted the uv branch October 9, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants