-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tools, build system: introduce PYTHON3_WITH_PEP723 #22223
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -186,6 +186,12 @@ OS_ARCH = $(word 2, $(UNAME)) | |||||||
| # set python path, e.g. for tests | ||||||||
| PYTHONPATH := $(RIOTBASE)/dist/pythonlibs/:$(PYTHONPATH) | ||||||||
|
|
||||||||
| # Set python3 frontend capable of PEP 723 inline script metadata. Users may | ||||||||
| # choose `pipx run` or just `python3` instead. In case of just `python3`, there | ||||||||
| # will be no PEP 723 support and users will just have to install the right | ||||||||
| # python modules beforehand. | ||||||||
| PYTHON3_WITH_PEP723 ?= uv run | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
as python without PEP 723 is a valid choice ( as illustrated by this PR and the documentation above) further more it reduces the inconvenience if one does not want to use uv
|
||||||||
|
|
||||||||
| # Basic utilities included before anything else | ||||||||
| include $(RIOTMAKE)/utils/checks.mk | ||||||||
|
|
||||||||
|
|
@@ -877,7 +883,7 @@ cleanterm: $(TERMDEPS) | |||||||
| $(TERMPROG) $(TERMFLAGS) $(TERMTEE) | ||||||||
|
|
||||||||
| list-ttys: | ||||||||
| $(Q)$(RIOTTOOLS)/usb-serial/ttys.py | ||||||||
| $(Q)$(PYTHON3_WITH_PEP723) $(RIOTTOOLS)/usb-serial/ttys.py | ||||||||
|
|
||||||||
| doc doc-man doc-latex: | ||||||||
| $(MAKE) -C $(RIOTBASE) $@ | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| #!/usr/bin/env python3 | ||
| #!/usr/bin/env -S uv run | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the entire point of PEP723 to not introduce a dependancy on a specific tool
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes But. Python does not ship any out of the box that qualifies for the shebang. All our invocations of any of our Python scripts happen through the PYTHON3_WITH_PEP723 executor and thus ignore the shebang. The use that remains for the shebang (or, really, the executable bit set on the file) is for developers while they work on that script, or when they invoke it directly for some other reason. Nothing we set in there will work for everyone, but that path is not taken by RIOT itself, so just placing something in there is no new dependency, and anyone who invokes it and runs into trouble can just prefix it with the tool of their choosing. Would it be better if python3 just did this? Yes. But that's not in there now, not sure if planned, and even if, some time down the road until users have it. Until then, we can make the best possible guess there, or leave it to the respective script's maintainers to pick any that works for them.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read the cover letter of the PR first before commenting.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬆️ I was referring to Karl. @chrysn clearly did.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but uv is just a random choice why should the shebang point to uv and not just python which with the right dependencies installed is capable of executing a python-script since our automatic exec happens through a PEP runner (selectable) anyway there is no reason to put that into the shebang
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The optimization goal for the she-bang is to pick something that is simple to maintain and works well for the majority of users. Asking users to install
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why uv and not npm or pip or pipx or poetry or nix or ... the python packagemanger should be a user choice a python script should not care not all packemanger are able to read pep but if they install a python and the dependancies the *system python is able to exec that script
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the build system we can control how scripts are executed. The proposal here is to just use The shebang format however expects a single interpreter. So we have to make a choice here. Here are the options for the list that I consider as serious suggestions, and what pros/cons I see for them as shebang:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this
a valid way of installing something (at least they added a Its is not even like clicking on every executable (something people get made fun of after security incidents) it is injecting a download directly into your system no rubber-ducky needed. maybe we should add the download ahead of the shebang just to be sure.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to add to suggestion 1 uv run dist/tools/usb-serial/ttys.py |
||
|
|
||
| # SPDX-FileCopyrightText: 2023 Otto-von-Guericke-Universität Magdeburg | ||
| # SPDX-FileCopyrightText: 2026 ML!PA Consulting GmbH | ||
| # SPDX-License-Identifier: LGPL-2.1-only | ||
|
|
||
| # /// script | ||
| # requires-python = ">=3.10" | ||
| # dependencies = [ | ||
| # "pyudev" | ||
| # ] | ||
| # /// | ||
| """ | ||
| Command line utility to list and filter TTYs | ||
| """ | ||
|
|
||

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.
use python to exec python scripts