Skip to content

Commit

Permalink
dist/tools/bmp: in-line dependencies using PEP 723
Browse files Browse the repository at this point in the history
PEP 723 is an accepted proposal to in-line script metadata. One such
use cases is to put script dependencies inside the script, which makes
the requirements.txt redundant [1].

With the correct shebang, it becomes even possible to run the script
directly, without creating a virtual environment and installing
dependencies in advance.

Combining both makes the execution of single-file scripts within RIOT
much easier and friendlier.

PEP 723 metadata can be used by `pipx` [2] and can be easily
installed when `pip` is available.

[1] `pip install` still requires a requirements.txt, which is
    generally accepted during development. An open issue exists to
    add support for reading dependencies from PEP 723 as well. See
    pypa/pip#12891
[2] https://github.com/pypa/pipx
  • Loading branch information
basilfx committed Feb 4, 2025
1 parent c81a103 commit fe3e724
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion dist/tools/bmp/bmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env -S pipx run

# Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
#
Expand All @@ -9,6 +9,17 @@
# @author Maximilian Deubel <[email protected]>
# @author Bas Stottelaar <[email protected]>

# /// script
# requires-python = ">=3.10"
# dependencies = [
# "humanize",
# "packaging",
# "progressbar",
# "pygdbmi",
# "pyserial"
# ]
# ///

# Black Magic Probe helper script
# This script can detect connected Black Magic Probes and can be used as a flashloader and much more

Expand Down
6 changes: 4 additions & 2 deletions dist/tools/bmp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Dependencies are listed as PEP 723 metadata in `bmp.py`. This file exists
# for compatibility reasons.
humanize
packaging
progressbar
pygdbmi
pyserial
progressbar
pyserial

0 comments on commit fe3e724

Please sign in to comment.