Issue 27059: find_spec and find_loader ignore package/path argument (original) (raw)
Created on 2016-05-19 18:49 by Wrzlprmft, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (4)
Author: Gerrit Ansmann (Wrzlprmft)
Date: 2016-05-19 18:49
According to my understanding, the package
/path
argument of the find_loader
/find_spec
command should enable it to find modules in other directories than the current one. Instead, these arguments seem to be ignored and even changing the working directory from within Python (using os.chdir) does not yield the expected results with find_spec
.
I append a script with several test cases that should succeed in my understanding, but some of which don’t.
Python version: 3.4.3. OS: Ubuntu 14.04.4 Pertinent Stack Overflow question: http://stackoverflow.com/a/37260391/2127008
Author: Brett Cannon (brett.cannon) *
Date: 2016-05-19 19:33
So there are 2 problems with your example. One, importlib.util.find_spec() doesn't take a path argument but a package argument which is a package name and not a file system location (https://docs.python.org/3/library/importlib.html#importlib.util.find_spec). Two, importlib.find_loader() takes a "path" as in "a package's path" which means path. What this means it is it expected to be an iterable of directories and not a string as it's iterated over (https://docs.python.org/3/library/importlib.html#importlib.find_loader).
If you think the docs aren't clear enough then please feel free to submit a patch to make them a bit clearer.
Author: Gerrit Ansmann (Wrzlprmft)
Date: 2016-05-21 05:11
If you think the docs aren't clear enough then please feel free to submit a patch to make them a bit clearer.
I intend to do that. However, before I do so: Given that find_loader
shall be superseded by find_spec
, how would I use the latter to find the specs of a module that is not located in the current path, i.e., what is the current, non-deprecated way of doing find_loader("spam", ["/foo/bar/"])
?
Author: Brett Cannon (brett.cannon) *
Date: 2016-05-24 18:08
https://docs.python.org/3.6/library/importlib.html#examples has an Examples section that's new to the Python 3.6 docs which covers your use-case.
History
Date
User
Action
Args
2022-04-11 14:58:31
admin
set
github: 71246
2016-05-24 18:08:54
brett.cannon
set
messages: +
2016-05-21 05:11:04
Wrzlprmft
set
messages: +
2016-05-19 19:33:10
brett.cannon
set
status: open -> closed
resolution: not a bug
messages: +
2016-05-19 18:49:53
Wrzlprmft
create