From 6ffcdb52e80b63e68c890aed52ff7f4d00e079b8 Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Tue, 8 Oct 2024 15:57:51 +0000 Subject: [PATCH] utils/check-package: add inline script requirements The check-package tool requires some PyPi package to be installed before it can run. This is typically done by manually installing them into the user's global Python environment or setting up a virtual environment, then manually installing each dependency. Python recently defined a format for managing script dependencies as inline metadata[1]. This can be used with the `uv` tool to run a Python script and automatically install the minimum required version of Python and PyPi dependencies. With this change, it's now possible to run check-package with uv run -s ./utils/check-package Note that, because check-package does not have the '.py' file extension we must specify the `-s` or `--script` argument. That argument was added very recently in release 0.4.19[2]. I set the minimum python to 3.9 as that is the oldest version still supported[3]. I verified 3.9 works by running uv run -p 3.9 -s ./utils/check-package `git ls-tree -r --name-only HEAD` --ignore-list=.checkpackageignore [1] https://packaging.python.org/en/latest/specifications/inline-script-metadata/#script-type [2] https://github.com/astral-sh/uv/releases/tag/0.4.19 [3] https://devguide.python.org/versions/ Signed-off-by: Brandon Maier Signed-off-by: Thomas Petazzoni --- utils/check-package | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/check-package b/utils/check-package index 872e66c126..6a5e89daa3 100755 --- a/utils/check-package +++ b/utils/check-package @@ -1,5 +1,12 @@ #!/usr/bin/env python3 # See utils/checkpackagelib/readme.txt before editing this file. +# /// script +# requires-python = ">=3.9" +# dependencies = [ +# "flake8", +# "python-magic", +# ] +# /// import argparse import inspect