-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Improve/clarify importlib recipe for loading code from a source file path #121607
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
Comments
If we go the route of adding a new function to Any time I've seen someone use this snippet (or something similar) for source file importing, they've always used the trailing file name, minus the |
We're not for various reasons. If people want a function I think it should come from PyPI. |
…21519) Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
…ar (pythonGH-121519) (cherry picked from commit 3880917) Co-authored-by: Chris Barker <[email protected]> Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
…ar (pythonGH-121519) (cherry picked from commit 3880917) Co-authored-by: Chris Barker <[email protected]> Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
…ear (GH-121519) (#124080) gh-121607: Edited source file import recipe to make it more clear (GH-121519) (cherry picked from commit 3880917) Co-authored-by: Chris Barker <[email protected]> Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
…ear (GH-121519) (GH-124081) gh-121607: Edited source file import recipe to make it more clear (GH-121519) (cherry picked from commit 3880917) Co-authored-by: Chris Barker <[email protected]> Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
All backports are merged, so I'm closing this. Thanks, everyone! |
Ahh -- thanks -- I hadn't found that.
That looks to me like it's the non-deprecated way to do:
module = SourceFileLoader(name, path).load_module()
Is that correct -- will it do the same thing?
In which case, I propose that that recipe be added to
importlib
as a utility function along the lines of:I understand that it was a deliberate decision to put the recipe in the docs, rather than a utility function, though unless it's really something that is "not recommended" (in which case perhaps it should say so in the docs) -- then this is just complex enough that a utility function is called for -- particularly since
SourceFileLoader(name, path).load_module()
(now deprecated?) is advice readily found on the internet.Does this need another issue or PR?
Meanwhile, for the original issue:
I suggest that checking for
__fspath__
be added to the:FileLoader.__init__()
and perhaps a couple other places where file paths are initialized -- that is the "outer" parts of the importlib API.Though for my use-case the proposed utility function would solve the problem at hand.
Originally posted by @ChrisBarker-NOAA in #87005 (comment)
Linked PRs
The text was updated successfully, but these errors were encountered: