Python advice requested:

I need to include a small test program, written in Python, in a repository containing other software not in Python. The program will have multiple source files and use dependencies from PyPI, but does not need to be installed anywhere. The expected usage is to just run it directly from the directory where it lives.

Is there a suitable tool to use to run it which will create a temporary virtual environment, install the dependencies, run the program, and then clean that stuff up?

#Python

Running scripts | uv

A guide to using uv to run Python scripts, including support for inline dependency metadata, reproducible scripts, and more.

@aoristdual Interesting! When I first heard about this it was always referred to as 'single file scripts' so I wonder if it will work with local modules.

@kevin @aoristdual Yeah, you just need to make sure you list all the PyPI dependencies of local modules in the main file you run.

For example, this deploy calls "uv run generate_metadata.py"
https://github.com/python-docs-translations/dashboard/blob/a6586fb364c837ce38cc5df6b992569db93bd763/.github/workflows/update.yml#L59

Here's its inline script metadata:
https://github.com/python-docs-translations/dashboard/blob/a6586fb364c837ce38cc5df6b992569db93bd763/generate_metadata.py#L1-L12

Which includes things like potodo, needed for another local import.
#Python #uv

dashboard/.github/workflows/update.yml at a6586fb364c837ce38cc5df6b992569db93bd763 · python-docs-translations/dashboard

List of translation projects of the Python documentation - python-docs-translations/dashboard

GitHub