Skip to content

Commit

Permalink
feat: add uv run shebang til
Browse files Browse the repository at this point in the history
  • Loading branch information
jthodge committed Aug 22, 2024
1 parent cc60497 commit 5ea9855
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions patterns/uv-run-in-the-shebang-line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# `uv run` in the Shebang Line

Beginning a script with `#!/usr/bin/env -S uv run` and then `chmod 755` the script.

```python
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "flask==3.*",
# ]
# ///
import flask
# ...
```

This allows you to run the script on any machine with the `uv` binary installed
via `./script.py`.

And, it will automatically:

1. Create its own isolated, sandboxed environment
2. Install all required dependencies in the environment
3. Run itself in that environment (even using the correctly installed version
of Python)

via [alsuren](https://github.com/alsuren) ➡️ [diff](https://github.com/alsuren/sixdofone/pull/8/files#diff-568470d013cd12e4f388206520da39ab9a4e4c3c6b95846cbc281abc1ba3c959R1)

0 comments on commit 5ea9855

Please sign in to comment.