Here are the examples of the python api sys.path_hooks.append taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
3
Example 1
@classmethod
def _install_hook(cls):
"""Installs this loader as a ``path_hook``."""
if hasattr(cls, "_hook_installed"):
return
sys.path_hooks.append(cls)
cls._hook_installed = True
3
Example 2
Project: Ivoire Source File: transform.py
@classmethod
def register(cls):
"""
Register the path hook.
"""
cls._finder = FileFinder.path_hook((cls, [cls.suffix]))
sys.path_hooks.append(cls._finder)
0
Example 3
def testPathHook(self):
sys.path_hooks.append(PathImporter)
sys.path.append(test_path)
self.doTestImports()
0
Example 4
def test_parallel_path_hooks(self):
# Here the Finder instance is only used to check concurrent calls
# to path_hook().
finder = Finder()
# In order for our path hook to be called at each import, we need
# to flush the path_importer_cache, which we do by registering a
# dedicated meta_path entry.
flushing_finder = FlushingFinder()
def path_hook(path):
finder.find_module('')
raise ImportError
sys.path_hooks.append(path_hook)
sys.meta_path.append(flushing_finder)
try:
# Flush the cache a first time
flushing_finder.find_module('')
numtests = self.check_parallel_module_init()
self.assertGreater(finder.numcalls, 0)
self.assertEqual(finder.x, finder.numcalls)
finally:
sys.meta_path.remove(flushing_finder)
sys.path_hooks.remove(path_hook)
0
Example 5
def install_hook():
sys.path_hooks.append(GithubImporter)
0
Example 6
def setup_module():
sys.path_hooks.append(GitImporter)
sys.path.append('{}/config'.format(PATH_PREFIX))
0
Example 7
@classmethod
def register(cls):
sys.path_hooks.append(cls)
sys.path.append(cls.trigger_url())