Use `uv add --script` in guide (#6215)

This commit is contained in:
Zanie Blue 2024-08-19 17:47:17 -05:00 committed by GitHub
parent a1f98e240a
commit 39c3c01f0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -119,8 +119,14 @@ Python recently added a standard format for
[inline script metadata](https://packaging.python.org/en/latest/specifications/inline-script-metadata/#inline-script-metadata). [inline script metadata](https://packaging.python.org/en/latest/specifications/inline-script-metadata/#inline-script-metadata).
This allows the dependencies for a script to be declared in the script itself. This allows the dependencies for a script to be declared in the script itself.
To use inline script metadata, include a `script` section at the top of the script and declare the uv supports adding and updating inline script metadata for you. Use `uv add --script` to declare the
dependencies using TOML: dependencies for the script:
```console
$ uv add --script example.py 'requests<3' 'rich'
```
This will add a `script` section at the top of the script declaring the dependencies using TOML:
```python title="example.py" ```python title="example.py"
# /// script # /// script