-
-
Notifications
You must be signed in to change notification settings - Fork 90
Allow direct resolution of Distribution from EntryPoint #266
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
Conversation
In this branch, I've ported the first commit from the upstream pull request, but it's causing flake8 checks to fail:
It seems that we've already identified a regression with the expectation that entry points are sortable. Probably we should fix that first. |
34134da
to
ad7c371
Compare
How do we carry |
Indeed, this implementation doesn't yet attempt to address that concern. Do we know if there's a use-case that would demand restoration of the dist? |
In 0d31cab, I illustrate how one might consider including the Distribution when pickling. I can imagine another scenario where the pickle resolves the name of the distribution, pickles that, and then I see the original request for pickleability was made by @asottile in #96. Anthony, can you elaborate on what use-case demands the pickleability of EntryPoint objects and whether retaining an attached |
flake8 forks multiprocessing workers and used to contain importlib-metadata objects in the object graph -- I no longer need it as we're working around it and passing along our own objects instead |
====== | ||
|
||
* #265: ``EntryPoint`` objects now expose a ``.dist`` object | ||
referencing the ``Distribution`` when constructed from a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When?
An entry point exists based on a distribution defining it right?
Or, in which case does an entrypoint exist without a distribution?
So, why when
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite in particular constructs EntryPoints without a distribution. I wouldn't expect library consumers to construct EntryPoints this way, so I'm not describing it here, and instead focusing on the use-case that users would expect to see.
Bear with me.
If we adopt a lazy approach, we only load a distribution instance when we actually need it. How bad would this approach be? Could I mean, if loading a distribution instance isn't a great penalty, then let's just avoid this lazy approach. The idea of getting bug reports that there's a noticeable performance penalty is what's triggering my Q's here. |
Gladly. I'm grateful for every bit of input.
I guess it depends. The Moreover, it's not necessarily the case that a distribution that was constructed a second ago would be constructed from the same name in the next second, if, for example, pip were to have uninstalled or upgraded that distribution in the meantime. It's also important to note that third-parties can implement their own Distribution subclasses and there's nothing in the protocol or spec that demands that they implement something that's pickleable or able to be reconstructed from the same name.
Perhaps not. And you bring up a good point - I'm not aware of what use-cases drive the demand for resolving a distribution from an entry point. I've asked in bpo-42382 for some clarification as to the requirement.
My primary motivation for keeping an instance is because that instance links directly to the object that created the EntryPoint. Also, because that instance already exists, it avoids complication around possible changes to the state. That is, it reflects the exact Distribution that was present when the EntryPoint was read.
I guess what I'm wondering is why bother resolving a Distribution to a name only to lazily resolve that name back to a Distribution? If the concern is pickleability, and we determine that users will in fact desire with reason for the Distribution object to also be pickled and restored, then I would recommend adding pickleability as a constraint on the Distribution interface. |
It's the path traversal that worries me.
Fair point.
Hmm, but if we add the
Replied.
Yeah, that's why I was setting
My personal use case does not require pickleability. But dropping support for that now seems counterintuitive. Deprecate it's support to see if there's an actual need these days? |
Well, the tests for pickleability continue to work - they just lose the Distribution object in the process, but my feeling is that gap is okay for now, especially considering that the sole known case for pickleability is no longer a need. I'd like to proceed with this approach for now, validate that it meets your needs, and defer the pickleability Distribution concern unless it's raised. |
Should I update the opened Python PR with these changes then? |
I'll do it, since it needs to incorporate the changes from 3.1 and 3.2 also. |
Backport of python/cpython#23334, Fixes #265.