←back to thread

741 points chirau | 3 comments | | HN request time: 0.686s | source
Show context
nrvn ◴[] No.44359113[source]
this is my new fav for running small executable scripts:

  #!/usr/bin/env -S uv --quiet run --script
  # /// script
  # requires-python = ">=3.13"
  # dependencies = [
  #     "python-dateutil",
  # ]
  # ///
  #
  # [python script that needs dateutil]
replies(1): >>44359527 #
1. mdeeks ◴[] No.44359527[source]
I really wish that hashbang line was something way WAY easier to remember like `#!/usr/bin/env uvx`. I have to look this up every single time I do it.
replies(1): >>44359888 #
2. PufPufPuf ◴[] No.44359888[source]
Sadly hashbangs are technically limited to: 1) Support only absolute paths, making it necessary to use /usr/bin/env which is in standardized location to look up the uv binary 2) Support only a single argument (everything after the space is passed as a single arg, it's not parsed into multiple args like a shell would), making it necessary to use -S to "S"plit the arguments. It's a feature of env itself, for this very use case.

So there isn't really much to do to make it simpler.

replies(1): >>44360527 #
3. mdeeks ◴[] No.44360527[source]
I wasn't really referring to env. I meant change the behavior of uvx. If the first argument passed to uvx is a file path, then execute it exactly the same way as `uv --quiet run --script` does.

Or maybe create a second binary or symlink called `uvs` (short for uv script) that does the same thing.