Live data from Hacker News

Uv: Running a script with dependencies

docs.astral.sh

81–90 of 174 posts

Re: Uv: Running a script with dependencies

#81
post #18

Earlier quoted context omitted.

Its needed on my ubuntu 24.04 system $ cat test.sh #!/usr/bin/env bash -c "echo hello" $ ./test.sh /usr/bin/env: ‘bash -c "echo hello"’: No such file or directory /usr/bin/env: use -[v]S to pass options in shebang lines $ ./test.sh # with -S hello

Interesting, I guess it is indeed a BSD thing, cause this works for me with or without '-S' on Mac

There currently is a patch for adding '-S' to OpenBSD and in the discussion, the one who came originally up with it commented on how he added it to FreeBSD:

"IIRC, the catalyst for it was that early FreeBSD (1990's?) did split up the words on the '#!' line because that seemed convenient. Years later, someone else noticed that this behavior did not match '#!' processing on any other unix, so they changed the behavior so it would match. Someone else then thought that was a bug, because they had scripts which depended on the earlier behavior. I forget how many times the behavior of '#!' processing bounced back and forth, but I had some scripts which ran on multiple versions of Unix and one of these commits broke one of those scripts.

I read up on all the commit-log history, and fixed '#!' processing one more time so that it matched how other unixes do it, and I think I also left comments in the code for that processing to document that "Yes, '#!'-parsing is really supposed to work this way".

And then in an effort to help those people who depended on the earlier behavior, I implemented '-S' to the 'env' command.

I have no idea how much '-S' is used, but it's been in FreeBSD since June 2005, and somewhere along the line those changes were picked up by MacOS 10. The only linux I work on is RHEL, and it looks like Redhat added '-S' between RHEL7 and RHEL8." [https://marc.info/?l=openbsd-tech&m=175307781323403&w=2]

Re: Uv: Running a script with dependencies

#82
post #24
post #4

The "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…

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.

Re: Uv: Running a script with dependencies

#83

Love this feature of UV. Here's a one-liner to launch jupyter notebook without even "installing" it: uv run --with jupyter jupyter notebook Everything is put into a temporary virtual environment that's cleaned up afterwards. Best thing is that if you run it from a project it will pick up those dependencies as well.

Note that it's not really "cleaned up" insofar as there is a uv cache folder that will grow bigger over time as you keep using that feature.

Re: Uv: Running a script with dependencies

#84
post #83

Love this feature of UV. Here's a one-liner to launch jupyter notebook without even "installing" it: uv run --with jupyter jupyter notebook Everything is put into a temporary virtual environment that's cleaned up afterwards. Best thing is that if you run it from a project it will pick up those dependencies as well.

Note that it's not really "cleaned up" insofar as there is a uv cache folder that will grow bigger over time as you keep using that feature.

True. It's a good idea to periodically run:

  uv cache clean
Or, if you want to specifically clean just jupyter:

  uv cache clean jupyter

Re: Uv: Running a script with dependencies

#86
post #36
post #31

Earlier quoted context omitted.

> he said his original goal was just to raise $5k to buy a computer. Privately, I was skeptical that the $5k computer had anything to do with Requests. Requests is a small pure-Python library; if you want to work on it, then any cheap laptop is more than sufficient. $5k is the price of a beefy server or top-end gaming rig. Kenneth Reitz has probably done more to enrich my life than most anyone else who builds things.…

Kenneth Reitz has been good and bad at times. And while things of his are genius level, he also has done asshole level things. But on the other hand, we get that with a lot of geniuses for some reason or another. Really smart people can be really dumb too. It would be like saying, "Don't use Laplace transforms because he did some unsavory thing at some point in time."

Looking at this drama for a bit, I haven't seen anybody advocate for 'canceling' requests itself.

Maybe it's more like: Laplace created awesome things, but let's be fair and also put in his wikipedia page a bit about his political shenanigans.

A lot of of so-called geniuses, especially the self-styled ones with some narcissistic traits, get away with being an asshole. Their admirers have different norms for regular, boring people. I don't think that is fair or healthy for a community.

Re: Uv: Running a script with dependencies

#89
post #4

The "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…

I hope it's in the same format as requirements files. Because then one could put a comment with a one liner next to it for people who don't have uv.

Something like `pip install -r <(head myscript.py)`. (Not exactly, but you get the idea).

Re: Uv: Running a script with dependencies

#90
I like it, and I once thought about this as well:

> Python doesn't require a requirements.txt file, but if you don't maintain this file, or neglect to provide one, it could result in broken functionalities - an unfortunate circumstance for a scripting language.

https://twitter.com/_damnever/status/1697247813854503250

Post reply on HN