More changes.

This commit is contained in:
Elf M. Sternberg 2016-07-09 10:52:30 -07:00
parent 631f31c688
commit 4eee86b2bc
1 changed files with 16 additions and 14 deletions

View File

@ -171,35 +171,37 @@ class PolyFileFinder(FileFinder):
after initialization. That's pretty much the whole point of the after initialization. That's pretty much the whole point of the
PolyLoader mechanism.''' PolyLoader mechanism.'''
_loaders = [] _native_loaders = []
_custom_loaders = []
_installed = False _installed = False
def __init__(self, path, *loader_details = []): def __init__(self, path):
self._loaders = [(suffix, loader)
for (loader, suffixes) in loader_details
for suffix in suffixes]
for loader, suffixes in loader_details:
loaders.extend((suffix, loader) for suffix in suffixes)
self._loaders = loaders
# Base (directory) path # Base (directory) path
self.path = path or '.' self.path = path or '.'
self._path_mtime = -1 self._path_mtime = -1
self._path_cache = set() self._path_cache = set()
self._relaxed_path_cache = set() self._relaxed_path_cache = set()
@property
def _loaders(self):
return cls._native_loaders + cls._custom_loaders
@classmethod
def path_hook(cls):
if not _path_isdir(path):
# By now, we've exhausted every loader except this one, so...
raise ImportError("only directories are supported", path=path)
return cls(path)
def install(compiler, suffixes): def install(compiler, suffixes):
if not PolyFileFinder._installed: if not PolyFileFinder._installed:
native_loaders = machinery._get_supported_file_loaders() PolyFileFinder._native_loaders = machinery._get_supported_file_loaders()
filefinder = [(f, i) for i, f in enumerate(sys.path_hooks) filefinder = [(f, i) for i, f in enumerate(sys.path_hooks)
if repr(f).find('.path_hook_for_FileFinder') != -1] if repr(f).find('.path_hook_for_FileFinder') != -1]
if filefinder: if filefinder:
filefinder, fpos = filefinder[0] filefinder, fpos = filefinder[0]
sys.path_hooks[fpos] = PolyFileFinder.path_hook(*native_loaders) sys.path_hooks[fpos] = PolyFileFinder.path_hook
else: else:
sys.path_hooks.extend([PolyFileFinder.path_hook(*native_loaders) sys.path_hooks.extend([PolyFileFinder.path_hook])
PolyFileFinder._installed = True PolyFileFinder._installed = True
PolyFileFinder._install(compiler, suffixes) PolyFileFinder._install(compiler, suffixes)