Skip to content

Conversation

@Sorixelle
Copy link
Member

Using plain pip+venvs to manage dependencies for build tooling has a few downsides:

  • Manual activation: Developers have to remember to activate the repo's venv with source .venv/bin/activate on each new terminal session, and possibly deactivate as well when they're done
  • Dependency locking: The requirements.txt only specifies ranges of versions, which can potentially cause breakages due to dependency updates without warning

While the second can be solved with just pip, the first has no easy solution. Instead, to tackle both issues, we can use uv, a new Python package manager which tackles these problems.

This PR creates a pyproject.toml file with dependencies imported from both requirements.txt and docs/requirements.txt, with the intention of using uv (or possibly some other tool later down the line, if uv stops being the new hotness for whatever reason) to install them. It also sets up both waf and the docs site build to use uv run for execution, automatically running them within uv's managed venv and saving developers from having to manually activate the venv themselves.

The docs have been updated to include uv setup instructions for both Ubuntu and macOS, and remove the venv setup step (since uv handles this automatically).

A few changes have also been made to the pyproject.toml files in python_libs, to ensure uv builds and installs the libraries inside it's venv correctly. The __init__.py files have been removed, as the declare_namespace calls were emitting deprecation warnings with recent versions of setuptools, and are obsoleted by PEP 420.

Copy link
Collaborator

@Hexxeh Hexxeh left a comment

Choose a reason for hiding this comment

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

I'm fine with this, let's get @gmarull to weigh in from Core side though.

@Sorixelle Sorixelle force-pushed the python-uv branch 5 times, most recently from 45bfb8b to 69b0d73 Compare July 20, 2025 11:37
@jwise
Copy link

jwise commented Jul 25, 2025

ping @gmarull now that he's back in the office :)

@Sorixelle
Copy link
Member Author

Not sure what's up with that build failure, can't reproduce it locally - maybe try rerun it, if it's still broken after that I'll dig into it further.

@gmarull
Copy link
Collaborator

gmarull commented Jul 25, 2025

I'm not really a fan of fancy new Python package managers unless they become the official package manager. Who knows if uv will be the last (it seems to be venture backed, scaring enough)? Pip, despite its many problems, has been running for years. The only advantage I see in uv is the lock file (something we can still manage with experimental pip lock), the others are mostly redundant on a project like ours where we install dependencies once and rarely touch them anymore. I'd probably have another take if we were a Python project. So my vote is a -1, I prefer to keep things simple. I've yet to find any issues with the current setup.

@Hexxeh
Copy link
Collaborator

Hexxeh commented Jul 25, 2025

I had similar thoughts, but I think the things that convinced me were:

  • It integrates with waf so you don't need to remember the virtualenv
  • There's no lock in. If uv goes out of fashion, you can just drop back to pip with little cost.

@jwise
Copy link

jwise commented Jul 26, 2025

I kicked it to rerun it. The new SDK requires uv, so it makes sense to me that the firmware should too (and maintaining venvs by hand really does suck...).

@jwise
Copy link

jwise commented Jul 26, 2025

@gmarull In light of @Hexxeh 's and my comments above, do you still -1?

docs/Makefile Outdated
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SPHINXBUILD ?= uv run sphinx-build
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer not to have this managed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same reason as waf

waf
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env -S uv run --script
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here, this creates a hidden development flow dependency on uv, which I'd avoid. If we use uv, let's make it transparent, explicit and optional.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not really a hidden dependency, I've documented the requirement in the getting-started docs. I can drop this, but it means you'd have to prefix every Python command with uv run (worse for the docs - more like SPHINXBUILD="uv run sphinx-build" make which is very unintuitive). Feels like putting a fair bit of overhead on developers, which is part of what I was trying to reduce with this PR.

Copy link

Choose a reason for hiding this comment

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

the opposite version of this is: if you don't want to use uv, you can still python3 waf build

Copy link
Collaborator

Choose a reason for hiding this comment

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

By hidden dependency I mean waf now depends on uv to run, you have no other choice. Considering uv is not the official Python package manager solution, I'd avoid this. We should be able to still use pip.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd agree it's hidden in a sense, but as @jwise pointed out you do have another choice.

This is also to my mind the biggest benefit of uv for me, so I'd prefer to keep it as it is currently in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sold this is an advantage. If activating the venv is an issue, there are quite a few shell scripts/plugins etc that will automatically load venvs if found when entering a directory, and then, regardless of who created such venv or which tool, commands will work as usual.

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't - as Joshua mentioned, you can still use python3 waf and it will be run with whatever Python is currently in PATH, without interacting with uv at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I know, but that's precisely what I do not want. This forces a different workflow if I do not stick with uv.

"svg-path>=7.0",
]

[tool.uv.sources]
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't there any standard way to define this? it worked pre-uv...

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like there is. I'll do that instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, nope, I've run into astral-sh/uv#3271 - doesn't work if you run uv outside of the repo root (eg. in docs/). Will probably have to put that one back, unless there's any better way to do it.

@Sorixelle Sorixelle force-pushed the python-uv branch 2 times, most recently from 3c09c68 to d783c65 Compare August 1, 2025 03:51
@Sorixelle
Copy link
Member Author

I'm going to look into that build failure. nanopb/nanopb#599 seems relevant, some sort of race condition probably?

@Sorixelle Sorixelle force-pushed the python-uv branch 4 times, most recently from 15a32fb to ada73a9 Compare August 1, 2025 05:04
@Sorixelle
Copy link
Member Author

Think I squashed it. Solution feels a little hacky, so I'm open to better suggestions.

Copy link
Collaborator

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

My only objection now is to not force uv, ie, make it part of official GSG, but keep the option to use pip if someone prefers to (of course it'll become 'officially unsupported', same as other toolchains than the ARM GNU). I think it's a more future-proof solution.

waf
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env -S uv run --script
Copy link
Collaborator

Choose a reason for hiding this comment

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

By hidden dependency I mean waf now depends on uv to run, you have no other choice. Considering uv is not the official Python package manager solution, I'd avoid this. We should be able to still use pip.

docs/Makefile Outdated
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SPHINXBUILD ?= uv run sphinx-build
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same reason as waf

Dependencies imported from requirements.txt with `uv add -r requirements.txt`.

Signed-off-by: Ruby Iris Juric <[email protected]>
Imported with `uv add -r docs/requirements.txt`.

Signed-off-by: Ruby Iris Juric <[email protected]>
The packages weren't being installed into uv's venv, since they had no build
system defined. The declare_namespace calls are also deprecated in recent
setuptools, and are no longer necessary.

Signed-off-by: Ruby Iris Juric <[email protected]>
nanopb_generator will attempt to use protoc to generate a Python file as part of
it's operation, if that file doesn't exist yet. It seems like when waf runs
those generations in parallel, there's a race to generate that file that
results in build failures when the race is lost. To resolve this, we call the
function that generates that file during configure so we avoid the parallel
race during build.

Signed-off-by: Ruby Iris Juric <[email protected]>
@gmarull
Copy link
Collaborator

gmarull commented Aug 1, 2025

So my last take on this: happy to use uv, but as soon as dev workflow is not altered if using standard venv/pip. In any case, feel free to merge whatever you think is best, but I won't ack.

@github-actions
Copy link

github-actions bot commented Sep 1, 2025

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the stale Stale issue or PR (will be closed soon) label Sep 1, 2025
@github-actions github-actions bot closed this Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale issue or PR (will be closed soon)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants