Skip to content
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

Preload script wrappers at import time #215

Merged
merged 2 commits into from
May 3, 2024
Merged

Conversation

pfmoore
Copy link
Member

@pfmoore pfmoore commented May 2, 2024

Pip encountered an issue (pypa/pip#12666) where we can't find the script wrappers because we've uninstalled the running version of pip. Pre-loading the wrapper code into memory when importing distlib.scripts avoids this problem.

We can patch this locally, but would it be acceptable as a change here instead?

@notatallshaw
Copy link
Member

macos-latest 3.7 is failing because macos-latest has moved from macos-12 to macos-14, and macos-14 does not have Python 3.7 on it.

Given macos-12 is x86 and macos-14 is ARM and distlib tests run so quickly, I would reccomend running against both and excluding Python 3.7 for macos-14/latest, a little like in https://github.com/pypa/pip/pull/12593/files

Copy link
Collaborator

@vsajip vsajip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRAPPERS is only used when os.name == 'nt' or (os.name == 'java' and os._name == 'nt'), so this computation suite could also be done only when the above condition is true, right?

@pfmoore
Copy link
Member Author

pfmoore commented May 2, 2024

Good catch - fixed.

@vsajip vsajip merged commit 888c48b into pypa:master May 3, 2024
@vsajip
Copy link
Collaborator

vsajip commented May 3, 2024

@pfmoore do you need an imminent release with this change? Otherwise I would normally do a release mid-year-ish (unless an urgent issue needs fixing).

@pfmoore pfmoore deleted the preload_wrappers branch May 3, 2024 08:45
@pfmoore
Copy link
Member Author

pfmoore commented May 3, 2024

I don't think it's needed. The pip issue isn't urgent, and we can patch locally in the interim. It's not worth making you do the extra work IMO.

@gaborbernat
Copy link

This broke virtualenv Windows zipapps #235

@pfmoore
Copy link
Member Author

pfmoore commented Oct 18, 2024

Hmm, sorry about that. I thought that registered finders needed to be compatible with the ResourceFinder class. The docs should probably be clearer on what's required - PEP 302 is extremely out of date these days, but unfortunately the importlib.resources API, which is the stdlib analogue of the distlib resources API, is still pretty unstable and not something I think we should reference 🙁

Maybe we should say that all registered finders must implement the ResourceFinder interface? @vsajip what do you think? I can update the docs if that seems reasonable to you.

@vsajip
Copy link
Collaborator

vsajip commented Oct 19, 2024

what do you think

That seems reasonable to me, but what fix do you propose to the changes in this PR? I mean, it looks like Gabor's worked around it, but isn't it better to sort it at source?

@pfmoore
Copy link
Member Author

pfmoore commented Oct 19, 2024

TBH, I'd assumed it wasn't (easily) fixable at source. Isn't the problem here that virtualenv loads distlib from a location that's registered with a finder that doesn't support iterating over resources?

In this code, virtualenv registers a custom finder, but it's not clear that the registration satisfies the necessary contract, which says that the finder maker "must return a finder for that package". What constitutes a "finder" isn't clear (and the reference to PEP 302 in that section of the docs further muddies the water) but I'd assume it means a ResourceFinder (or at least something that provides the interface that ResourceFinder does).

My proposal was simply to make that clearer. In theory, virtualenv is still incorrect, as it doesn't implement methods like is_container, or get_stream, but I would consider that a practical decision on virtualenv's part, to only implement as much of the interface as it needs to. We could go further and make ResourceFinder subclassable, and make register_finder require that the finder_maker returns a ResourceFinder subclass, but that's a bigger change than I feel comfortable proposing (or making!)

If, on the other hand, you have a suggestion of how we can find the wrappers using a finder that only implements find, I'm happy to have a go at implementing that. But I can't think of a way myself that doesn't require hard coding the names of the wrapper executables.

@gaborbernat
Copy link

Yes, my primary complaint I made here is about the documentation not being clear what it actually required And I had to reverse engineer the interface I needed to implement.

@pfmoore
Copy link
Member Author

pfmoore commented Oct 19, 2024

@gaborbernat @vsajip is #236 sufficient?

@vsajip
Copy link
Collaborator

vsajip commented Oct 19, 2024

Thank you, Paul, I've merged it. @gaborbernat let us know if you think more is needed.

@gaborbernat
Copy link

yeah, that sounds better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants