TIL: uv —script
I've known for a while that uv
can run Python scripts that declare inline dependencies.
I learned today that you can also use uv
to manage those dependencies.
I've known for a while that uv
can run Python scripts that declare inline dependencies.
I learned today that you can also use uv
to manage those dependencies.
(via epistasis on HN)
Semantic versioning is difficult. Not everyone has the same idea of what “breaking change” means, and depending on your language and tooling “breaking” changes can sneak in despite your best efforts.
One possible mitigation is to record when you resolved your dependencies and ignore anything published after that date. It's crude, and relies on package dependencies not monkeying with stuff that's already been published, but it's easy to understand and you can do it with uv
.
It's documented here.
Put a date in your pyproject.toml
file and subsequent invocations of uv
will ignore anything published after the cutoff:
[tool.uv]
exclude-newer = "2023-10-16T00:00:00Z"
You can also use it in the “inline metadata” format for scripting! From the uv
docs:
# /// script
# dependencies = [
# "requests",
# ]
# [tool.uv]
# exclude-newer = "2023-10-16T00:00:00Z"
# ///
import requests
print(requests.__version__)
This use case seems particularly valuable: if I write a quick script I probably care more about it not breaking than I care about it getting updated dependencies. It's nice that uv
offers a way to keep code running rather than forcing me to update it or throw it out.