uv icon indicating copy to clipboard operation
uv copied to clipboard

Pipe input directly in `uv run` command

Open Aditya-PS-05 opened this issue 1 year ago • 9 comments

closes #6529

Summary

Locally tested, the expected behavior works but some tests are being failed.

Aditya-PS-05 avatar Oct 17 '24 18:10 Aditya-PS-05

Can you title the pull request as a description of the user-facing change? (i.e., as things appear in our changelog)

zanieb avatar Oct 17 '24 19:10 zanieb

@zanieb , Title changed and please review it.

Aditya-PS-05 avatar Oct 18 '24 13:10 Aditya-PS-05

I'm hesitant to make this change because we still have to read the entire file ourselves in order to find the PEP 723 metadata from the script (which can appear anywhere in the script).

charliermarsh avatar Oct 22 '24 02:10 charliermarsh

@charliermarsh , Can you suggest an alternate good method to be implemented?

Aditya-PS-05 avatar Oct 22 '24 05:10 Aditya-PS-05

I'm not sure I agree @charliermarsh, I think it'll be very rare for the metadata to not be at the head of the file and I think it's far more likely that we read the whole file into memory unnecessarily and degrade performance in that way. It's possible the additional complexity here isn't justified, as nobody as complained yet — but I don't think "we could need to read the whole file anyway" is a particularly compelling point against implementing this.

zanieb avatar Oct 22 '24 11:10 zanieb

It’s not that we could need to read the whole file into memory. It’s that we have to scan the whole file, every time, unless it’s actually a PEP 723 script with a comment at the top. Otherwise, we can’t know that the file isn’t a PEP 723 script until we’ve read the whole thing, and we can’t execute it until we know whether it’s a PEP 723 script.

charliermarsh avatar Oct 22 '24 11:10 charliermarsh

Ah I see. That's a great point. We could just say we don't support inferring that something is a PEP 723 script if it's not in the header, but I see why that's also not appealing given that nobody is complaining about us reading the script into memory today.

zanieb avatar Oct 22 '24 11:10 zanieb

You’re totally right though that if the file is a PEP 723 script and the comment is near the top, we can just buffer until we see it, then steam the rest (and avoid reading the file into memory). So if a lot of the usages here are PEP 723 scripts (which almost certainly have the header near the top), then it would make a difference.

charliermarsh avatar Oct 22 '24 11:10 charliermarsh

In that light, I guess I’m not objecting to the behavior in principle, more that it will be complex :)

charliermarsh avatar Oct 22 '24 11:10 charliermarsh