-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to lock dependencies in a script #6318
Comments
This is really cool. We can write it under |
I think this should be opt-in (something in the script's |
Is anyone working on it? |
No, we need to design it. Are you interested in helping with that? |
Hi, @zanieb I do not see the information about the compiled_dependencies in https://packaging.python.org/en/latest/specifications/inline-script-metadata/#inline-script-metadata Where can I search more information? |
PEP 723 has a sentence on this
I do not interpret this as a recommendation, but it's definitely thought of when this was designed. For me, this solution isn't as useful as I like it to be in the use case of "a repository of python scripts (not packaged)". Adopting inline script metadata is still very difficult as not many of my of my users use |
https://peps.python.org/pep-0723/#how-to-teach-this It also mentions that tool blocks are allowed. If we dumped the lock file contents into some tool.uv.xxx property there, I guess the benefit would be 2-fold; it gives non-uv-users a hint that their life would be easier with UV, gives us free reign to decide the name and number of properties we need to accomplish this |
I think https://docs.astral.sh/uv/pip/compile/ It mentions that uv allows dependencies to be locked in the I think it is confused for the users to manually modify the locked environments if uv creates both the |
The point is that the dependencies are defined in the script per PEP 723 — I don't think we'd support other things here. |
I think using |
The only problem with this is that the lockfile is quite long, so we probably don't want it at the top of the script. |
I am in support of this. How do you see it integrate with |
|
Which one will |
I just want to add a voice against having another file next to the script, since if you're going to do that, why not make it a The whole benefit of PEP 723 is keeping the script self-contained, in my opinion. I'll voice something that happens with other tools that embed metadata is it is appended. What I'm thinking about here is signing of, e.g., PowerShell scripts where the signature is attached at the end. I don't have knowledge of how To get this behavior today, I've been using |
I'm sort of all for just having a way to write this metadata at the bottom. We're sort of in a tough place w.r.t. the specification though. It says things like:
These feel relatively prohibitive towards embedding the lockfile in the bottom, though I don't think it's a firm blocker. I think there's some benefit to locking scripts in projects without embedding the metadata so we can improve resolve / execute times for scripts and have consistent dependencies — but that's sort of a separate idea. |
Maybe |
If you want like 90% of the benefits of a lock file in a PEP 723 script in a way that is also extremely concise, you can use https://docs.astral.sh/uv/guides/scripts/#improving-reproducibility |
I think rewriting the There are caveats to |
@Halkcyon You would have to make sure all scripts' dependencies are cross-compatible. That's a big sacrifice from PEP-723 & uv where I can run each script in its separate virtual environment. |
@zanieb -- What about...
|
I'm into that interface, yeah. What about |
+1 to this feature! Was surprised it wasn't already there. I would recommend As a convention so you 1) per-script lock specifications and 2) don't super long lock specifications inline within a file. If you want a single file I think https://docs.astral.sh/uv/guides/scripts/#improving-reproducibility is sufficient and the full lock files should be an advanced feature. |
There's also a case for putting them in
This is pretty fair. |
I think what was wrong with my original suggestion was the leading And thank for all your work on this spectacular tool! |
It sounded like the conversation here was leaning towards including the lockfile at the bottom, but the current implementation produces a separate lockfile (with no option to generate the lockfile inline afaict). Is the goal still to also have the option/change the behavior to inject the lockfile at the bottom of the script or is this the current implementation final? My two cents is that having a single file for a script would be very advantageous, and coupling this with a |
It was easier to put it elsewhere — but I'm generally in favor of support an embedded lockfile too. |
I personally think the embedded lockfile is somewhat impractical -- just way too big. But we can probably support it. |
Let's discuss further in #11064 |
Uv's script support is amazing for creating self-contained scripts that can be written once and then executed by anyone with uv months later, as long as the upper boundaries for dependencies were specified.
Being able to lock the dependencies for a script would be a huge boon in script preservation, all the same arguments that apply to
uv lock
andpip-tools compile
apply here.Preserving original requirement specifications would be beneficial, so after running
uv add --script example.py 'requests<3' 'rich'
anduv lock --script example.py
theexample.py
will contain something like (which is basically the result of extracting dependencies into requirements.txt, running uv pip compile and pasting the result back into the script):The text was updated successfully, but these errors were encountered: