Self-contained Python scripts with uv
71–80 of 114 posts
Re: Self-contained Python scripts with uv
#72My 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…
I completely agree. Hope something like this is eventually standardized. Problem is that uv probably does not want to execute anything to find out dependencies, so it would have to be a very restrictive subset of python syntax. The fact that is is needed at all of course highlights a weakness in the language. The import statements themselves should be able to convey all information about dependencies
Re: Self-contained Python scripts with uv
#73Re: Self-contained Python scripts with uv
#74My 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…
I completely agree. Hope something like this is eventually standardized. Problem is that uv probably does not want to execute anything to find out dependencies, so it would have to be a very restrictive subset of python syntax. The fact that is is needed at all of course highlights a weakness in the language. The import statements themselves should be able to convey all information about dependencies
What languages convey the version of the dependencies in a script’s import statements?
Re: Self-contained Python scripts with uv
#75This 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…
> I can't find any assertion in the uv docs that these temporary virtual environments are ever automatically cleaned up. That’s a good point. I wonder if at least they are reused when you run the script several times.
It's not that the inline requirements make a new `.venv` directory or something, uv seems to link the packages to a central location and reuse them if already there.
Re: Self-contained Python scripts with uv
#76My 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…
It still -does- execute identically. Provided you install the same dependencies.
I don't see this as changing the semantics of the code itself, rather just changing the environment in which the code runs. In that respect it is no different from a `#!/bin/bash` comment at the top of a shell script.
Re: Self-contained Python scripts with uv
#77Re: Self-contained Python scripts with uv
#78Re: Self-contained Python scripts with uv
#79My 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…
I completely agree. Hope something like this is eventually standardized. Problem is that uv probably does not want to execute anything to find out dependencies, so it would have to be a very restrictive subset of python syntax. The fact that is is needed at all of course highlights a weakness in the language. The import statements themselves should be able to convey all information about dependencies
[1] https://peps.python.org/pep-0723/
[2] https://packaging.python.org/en/latest/specifications/inline...
Re: Self-contained Python scripts with uv
#80So how does this guarantee that it will never raise some libc error, or similar? Unfortunately I have become sceptical about "self contained" distribution methods.