Closed abravalheri closed 1 year ago
Hi @takluyver, I was wondering if you could review this PR (if you have the time) or share your thoughts about the issue.
I don't know if there would be time for a pyproject-hooks
release before pip
's next release (very unlikely, but who knows...).
@pradyunsg, I rebased the PR on top of the latest changes in main. Please let me know if any other changes are necessary.
Hello @pypa/pyproject-hooks-committers, I wonder if this direction for solving the issue is something that the project would be interested, or if it would be better for me to close the PR and assume that the issue would be handled with a different approach.
I always find it tough to understand the various bits of custom import machinery, so I don't relish trying to understand either the problem or the solution here (and I'm too tired to tackle it right now, when I happen to have a few minutes to look at it).
I see you've added tests, and @FFY00 was happy with it, so I'll give people a few more days to make any comments, and if there are none, I'll trust you and merge this. Feel free to ping me again in a week or so if I forget (which is all too possible :wink: )
Closes (potentially?) #45
This definitely closes that, no? I'll let you edit the description, but my reading is that it definitely does change this behaviour.
This definitely closes that, no? I'll let you edit the description, but my reading is that it definitely does change this behaviour.
Perfect, I updated the description. Thank you very much for the confirmation @pradyunsg.
I have updated the PR to take into consideration external feedback I received about PathFinder
(i.e. to avoid using PathFinder
with nested modules).
Luckily, importlib machinery is smart enough to find nested modules based on the parent's path.
I copied the if "." in fullname
trick from editables
.
Thanks @abravalheri! ^.^
Closes #164 Closes #45
My understanding is that these changes are worth implementing (to increase robustness) even if
pip
improves its environment isolation.Approach
Instead of changing
sys.path
and relying onimportlib.import_module
to do the right thing, this PR proposes to useimportlib.machinery.PathFinder.find_spec
to actively restrict the paths to be searched when looking for the backend.Other details
Since the description of
BackendUnavailable
[^1] seems more appropriate than the description forBackendInvalid
[^2] for the circumstances described in the #164, I modified (in a backwards compatible way) how the errors are reported. I think this makes sense with the rest of the alterations...[^1]: docstring:
Will be raised if the backend cannot be imported in the hook process.
[^2]: docstring:Will be raised if the backend is invalid.