class importlib.machinery.FileFinder(path, *loader_details)
A concrete implementation of importlib.abc.PathEntryFinder
which caches results from the file system.
The path argument is the directory for which the finder is in charge of searching.
The loader_details argument is a variable number of 2-item tuples each containing a loader and a sequence of file suffixes the loader recognizes. The loaders are expected to be callables which accept two arguments of the module’s name and the path to the file found.
The finder will cache the directory contents as necessary, making stat calls for each module search to verify the cache is not outdated. Because cache staleness relies upon the granularity of the operating system’s state information of the file system, there is a potential race condition of searching for a module, creating a new file, and then searching for the module the new file represents. If the operations happen fast enough to fit within the granularity of stat calls, then the module search will fail. To prevent this from happening, when you create a module dynamically, make sure to call importlib.invalidate_caches()
.
New in version 3.3.
-
path
-
The path the finder will search in.
-
find_spec(fullname, target=None)
-
Attempt to find the spec to handle fullname within
path
.New in version 3.4.
-
find_loader(fullname)
-
Attempt to find the loader to handle fullname within
path
.
-
invalidate_caches()
-
Clear out the internal cache.
-
classmethod path_hook(*loader_details)
-
A class method which returns a closure for use on
sys.path_hooks
. An instance ofFileFinder
is returned by the closure using the path argument given to the closure directly and loader_details indirectly.If the argument to the closure is not an existing directory,
ImportError
is raised.
Please login to continue.