logoalt Hacker News

rikafurude21last Tuesday at 12:19 PM6 repliesview on HN

alternatively, uv lets you do this:

  #!/usr/bin/env -S uv run --script
  #
  # /// script
  # requires-python = ">=3.12"
  # dependencies = ["foo"]
  # ///

Replies

semi-extrinsiclast Tuesday at 2:47 PM

The /// script block is actually specified in PEP 723 and supported by several other tools apart from uv.

show 2 replies
satvikpendemyesterday at 11:23 PM

Rust is getting this feature too, it's great for one off scripts

nemosaltatlast Tuesday at 7:23 PM

I’ve started migrating all of my ~15 years of one-off python scripts to have this front matter. Right now, I just update when/if I use them. I keep thinking if were handier with grep/sed/regex etc, I’d try to programmatically update .pys system-wide. But, many aren’t git tracked/version controlled, just laying in whatever dir they service(d). I’ve several times started a “python script dashboard” or “hacky tools coordinator” but stop when I remember most of these are unrelated (to each-other) and un/rarely used. I keep watching the chatter and thinking this is probably an easy task for codex, or some other agent but these pys are “mine” (and I knew^ how they worked when I wrote^ them) and also, they’re scattered and there’s no way I’m turning an agent loose on my file system.

^mostly, some defs might have StackOverflow copy/pasta

show 1 reply
ncouturelast Tuesday at 5:16 PM

This is an awesome features for quick development.

I'm sure the documentation of this featureset highlights what I'm about to say but if you're attracted to the simplicity of writing Python projects who are initialized using this method, do not use this code in staging/prod.

If you don't see why this is not production friendly it's for the simple a good.reaaon that creating deployable artifacts packaging a project or a dependency of a project this uses this method, creating reproducible builds becomes impossible.

This will also lead to builds that pass your CI but fail to run in their destination environment and vice versa due to the fact that they download heir dependencies on the fly.

There may be workarounds and I know nothing of this feature so investigate yourself if you must.

My two cents.

zahlmanlast Tuesday at 3:02 PM

This isn't really "alternatively"; it's pointing out that in addition to the shebang you can add a PEP 723 dependency specification that `uv run` (like pipx, and some other tools) can take into account.

rjzzleepyesterday at 5:02 AM

I'm actually a bit annoyed that uv won. I found pdm to be a really nice solution that fixed a lot of the issues poetry had without the hard ideological stance behind it, while fixing most of its problems. But maybe that ideology was partly what drove it's adoption.