This has come up a LOT on HN in the past few months, some other recent examples: https://news.ycombinator.com/item?id=43500124 https://news.ycombinator.com/item?id=42463975 I like uv and all, but I take exception to the "self-contained" claim in two regards: 1) The script requires uv to already be installed. Arguably you could make it a shell script that checks if uv is already installed and then installs it via curl…
Self-contained Python scripts with uv
61–70 of 114 posts
Re: Self-contained Python scripts with uv
#62This has come up a LOT on HN in the past few months, some other recent examples: https://news.ycombinator.com/item?id=43500124 https://news.ycombinator.com/item?id=42463975 I like uv and all, but I take exception to the "self-contained" claim in two regards: 1) The script requires uv to already be installed. Arguably you could make it a shell script that checks if uv is already installed and then installs it via curl…
Another thing is that inline script metadata is a Python standard. When there is no uv on the system and uv isn't packaged but you have the right version of Python for the script, you can run the script with pipx: https://pipx.pypa.io/stable/examples/#pipx-run-examples. pipx is much more widely packaged: https://repology.org/project/pipx/versions.
Re: Self-contained Python scripts with uv
#63My pet peeve (in general, not specific to UV, which I genuinely appreciate) is using comment sections for controlling code execution. Using comments for linters and developer notes is perfectly acceptable. However, for configuration or execution-related data, a far superior pattern would be something like: UV_ENV = { "dependencies": { "requests": "2.32.3", "pandas": "2.2.3" } } This approach has clear advantages: - I…
This isn't a uv invention, uv is only using the standard PEP 723 like other tools. https://peps.python.org/pep-0723/
Re: Self-contained Python scripts with uv
#64We do the same with Nix, the shebang line looks like this: #! nix-shell -i python3 -p "python312.withPackages (pkgs: [ pkgs.boto3 pkgs.click ])" With this, the only requirement is Nix on the system, you don't even need Python to be installed!
Having Nih installed is much stronger requirement than having uv
Re: Self-contained Python scripts with uv
#65Re: Self-contained Python scripts with uv
#66[1] https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...
Re: Self-contained Python scripts with uv
#67Has anyone gotten this to work on Windows? I wanted to use this trick for some tooling for a game mod I'm working on but couldn't get the shebang trick to work.
Re: Self-contained Python scripts with uv
#68my approach is to use python build-in venv https://gist.github.com/Szpadel/43794d606d9924e7fea3e63fb800...
that way you can run scripts with external packages with only basic python installation
Re: Self-contained Python scripts with uv
#69Earlier quoted context omitted.
As I understand it, relicensing is possible when a project has a Contributor Licensing Agreement (CLA) which says that you're signing over your copyright to your contribution to the project's owners. (Who will eventually be bought out by the worst rich person you can think of - Yes, him.) I peeked in uv's contributing guide and issues and didn't see any CLA. In PyTorch the CLA was mentioned at the top of the contribu…
Not having a CLA prevents relicensing but open source licenses aren't revokable anyways.
Re: Self-contained Python scripts with uv
#70Earlier quoted context omitted.
I use this frequently on Windows and Linux. These are the steps I take: $> uv init --script .py $> uv add --script .py ... $> uv add --script .py --dev ... $> uv run .py Hope this helps :) Source: https://docs.astral.sh/uv/guides/scripts/
Unfortunately, `uv add --dev` doesn't work with `--script`: > uv -V uv 0.6.10 > uv add --script foo.py --dev ruff error: the argument '--script ' cannot be used with '--dev' Usage: uv add --script --link-mode > For more information, try '--help'. There is currently no mention of `uv add --script foo.py --dev ...` in https://docs.astral.sh/uv/guides/scripts/ . Inline script metadata in Python doesn't standardize devel…