Uv: Running a script with dependencies
91–100 of 174 posts
Re: Uv: Running a script with dependencies
#92The "declaring script dependencies" thing is incredibly useful: https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... # /// script # dependencies = [ # "requests Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, magically installed into a temporary virtual environment without you having to think about them at all. It's an implementation of Python PEP 723: h…
Re: Uv: Running a script with dependencies
#93Earlier quoted context omitted.
This is cool, but honestly I wish it was builtin language syntax not a magic comment, magic comments are kind of ugly. Maybe some day… (I realise there are some architectural issues with making it built-in syntax-magic comments are easier for external tools to parse, whereas the Python core has very limited knowledge of packaging and dependencies… still, one of these days…)
It IS built-in language syntax. It's defined in the PEP, that's built-in. It's syntax: "Any Python script may have top-level comment blocks that MUST start with the line # /// TYPE where TYPE determines how to process the content. That is: a single #, followed by a single space, followed by three forward slashes, followed by a single space, followed by the type of metadata. Block MUST end with the line # ///. That is…
I'm mostly joking, but normally when people say language syntax they mean something outside a comment block.
Re: Uv: Running a script with dependencies
#94Re: Uv: Running a script with dependencies
#95The "declaring script dependencies" thing is incredibly useful: https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... # /// script # dependencies = [ # "requests Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, magically installed into a temporary virtual environment without you having to think about them at all. It's an implementation of Python PEP 723: h…
My question is: if you already have to put the "import" there, why not have a PEP to specify the version in that same import statement, and let `uv` scan that dependency? It's something I never understood.
See also https://peps.python.org/pep-0723/#why-not-infer-the-requirem...
Re: Uv: Running a script with dependencies
#96This almost as great as how much I love that this gets posted like once every two weeks
Re: Uv: Running a script with dependencies
#97Earlier quoted context omitted.
shebang mode is also incredibly useful and allows execution like ./script.sh #!/usr/bin/env -S uv run --script # /// script # dependencies = [ # "requests
'env -s' it's not portable.
Edit: further reading https://unix.stackexchange.com/a/605761/472781> and https://unix.stackexchange.com/a/774145/472781> and also note that on older BSDs it also used to be like that
Re: Uv: Running a script with dependencies
#98Re: Uv: Running a script with dependencies
#99#!/usr/bin/env -S guix shell python python-requests python-pandas -- python3
in scripts for including per-script dependencies. This is language agnostic as long as the interpreter and its dependencies are available as guix packages. I think there may be a similiar approach for utilizing nix shells that way as well.
[0]: https://guix.gnu.org/manual/en/html_node/Invoking-guix-shell...