Most active commenters

    /usr/bin/env -S uv run

    (simonwillison.net)
    66 points jcbhmr | 13 comments | | HN request time: 0.951s | source | bottom
    1. rikthevik ◴[] No.42200681[source]
    Fantastic. I'm very impressed with Simon Willison in general (what a dynamo) and this in particular.
    replies(1): >>42200892 #
    2. manfre ◴[] No.42200892[source]
    Simon is an impressive individual, but in this instance, you're praising the messenger and not the source.

    > Code from this PR [1] by David Laban.

    That leverages the features of uv run with embedding script dependencies [2].

    [1] https://github.com/alsuren/sixdofone/pull/8 [2] https://docs.astral.sh/uv/concepts/projects/run/#running-scr...

    3. smaddox ◴[] No.42201103[source]
    I've been using this for a few weeks now, and it's really handy. But I did learn the hard way that it fails if you don't have internet connection, even if you already have the venv cached.
    replies(1): >>42202309 #
    4. kixpanganiban ◴[] No.42201363[source]
    Curious - how many containers and machines images these days come with uv by default?
    5. thewisenerd ◴[] No.42201537[source]
    this builds upon PEP 723, which is "accepted", so it's likely here to stay.

    https://peps.python.org/pep-0723/

    I've been very slowly migrating scripts to work with this, and `pipx run`. glad to know uv has also picked it up.

    6. skavi ◴[] No.42201572[source]
    reminds me of nix-shell shebang [0] which enables a similar pattern for scripts of arbitrary languages.

    [0]: https://nixos.wiki/wiki/Nix-shell_shebang

    7. jauntywundrkind ◴[] No.42202198[source]
    Zx adds a couple nice ease of use things to node.js, designed to help shell scripting. Among other things, if you call /usr/bin/env zx, it will automatically retrieve any module imports you have in your code! https://github.com/google/zx
    8. usrme ◴[] No.42202309[source]
    That's really unexpected! I'd default to the assumption that it would "just work" if all the dependencies are already met.
    9. mrweasel ◴[] No.42202316[source]
    While neat, doesn't it also comes with certain issues?

    Startup times has to be slower, but probably only for the first run?

    There's a some level of violation of the "Principle Of Least Surprise", depending on the setting. For some it will be the reverse, the script they got just works, without any setup or package installation. For others we'll wonder why it just started downloading a bunch of packages we already have.

    Probably not the greatest idea for production environments, where you should not or can not just pull in packages from the internet.

    It's really cool that it works, but I think I'd recommended using it highly selectively.

    10. theanonymousone ◴[] No.42202373[source]
    Maybe surprisingly, JBang has offered this functionality for Java since 2020. Happy we have it un Python too, now.
    11. ginko ◴[] No.42202398[source]
    Doesn't look like my Ubuntu machine comes with 'uv' installed at least. Can't say I've ever heard of it either.
    12. p4bl0 ◴[] No.42202491[source]
    It's a neat trick, but it still depends on uv being installed and network connectivity.

    What's the advantage of this that makes it worth despite these constraints, compared to e.g. using pyinstaller [1] to build and distribute a single executable file with the python interpreter and all the dependencies of your project bundled in it in the exact versions you chose in your development virtual environment?

    [1] https://pyinstaller.org/