From 0f43e44ad58d14fce09861aabc91bff4271a4355 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:15:38 -0800 Subject: [PATCH 1/2] Document running python recipes with `uv` --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 586ad997fe..ec5b0eb998 100644 --- a/README.md +++ b/README.md @@ -2802,6 +2802,33 @@ the final argument. For example, on Windows, if a recipe starts with `#! py`, the final command the OS runs will be something like `py C:\Temp\PATH_TO_SAVED_RECIPE_BODY`. +### Python Recipes with `uv` + +[`uv`](https://github.com/astral-sh/uv) is an excellent cross-platform python +project manager, written in Rust. + +Using the `[script]` attribute and `script-interpreter` setting, `just` can +easily be configured to run Python recipes with `uv`: + +```just +set unstable + +set script-interpreter := ['uv', 'run', '--script'] + +[script] +hello: + print("Hello from Python!") + +[script] +goodbye: + # /// script + # requires-python = ">=3.11" + # dependencies=["sh"] + # /// + import sh + print(sh.echo("Goodbye from Python!"), end='') +``` + ### Script Recipes Recipes with a `[script(COMMAND)]`1.32.0 attribute are run as From bfe031febf96e13da6579cf6188cdbaf82726928 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:17:08 -0800 Subject: [PATCH 2/2] Modify --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index ec5b0eb998..027e556718 100644 --- a/README.md +++ b/README.md @@ -2829,6 +2829,14 @@ goodbye: print(sh.echo("Goodbye from Python!"), end='') ``` +Of course, a shebang also works: + +```just +hello: + #!/usr/bin/env uv run --script + print("Hello from Python!") +``` + ### Script Recipes Recipes with a `[script(COMMAND)]`1.32.0 attribute are run as