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

@kevin I'm not sure if you'll get the automatic cleanup, at least not by default, but other than that: this sounds like a task for any of
- pipenv, using `pipenv run <file.py>`
- pdm in its non-installable project mode, also using `pdm run <file.py>`
- uv, probably (I don't actually know if it can do this but it tries to do everything so I'd imagine it can)

#Python

@diazona @kevin not sure about pipenv, but I *don't think* PDM would create a venv and install deps with just `pdm run`.

I would definitely recommend `uv run --script program.py` (which will do all that) as well as writing the dependencies directly in program.py, see https://packaging.python.org/en/latest/specifications/inline-script-metadata/#example.

Inline script metadata - Python Packaging User Guide

@pawamoy @kevin I thought about recommending pip-run, which does the same thing, but the OP mentioned it being multiple source files which I think rules that out.

#Python

@diazona @kevin yeah I'm not sure how `uv run --script` will behave either with multiple modules :) Try and let us know @kevin 😄