sys.meta_path.append

Here are the examples of the python api sys.meta_path.append taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

74 Examples 7

Example 1

Project: itools
Source File: css.py
View license
    @classmethod
    def install(cls):
        """
        Installs the import hook so that CSS files can be imported using the
        'import' command."""
        sys.meta_path.append(cls())

Example 2

Project: conary
Source File: importer.py
View license
def install():
    if hasattr(sys, 'pypy_version_info'):
        # The lazy importer doesn't work on PyPy right now, but it could be
        # made to.
        return
    sys.meta_path.append(OnDemandImporter())

Example 3

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 4

Project: TrustRouter
Source File: test_threaded_import.py
View license
    def test_parallel_meta_path(self):
        finder = Finder()
        sys.meta_path.append(finder)
        try:
            self.check_parallel_module_init()
            self.assertGreater(finder.numcalls, 0)
            self.assertEqual(finder.x, finder.numcalls)
        finally:
            sys.meta_path.remove(finder)

Example 5

Project: tvb-library
Source File: profile_settings.py
View license
    def initialize_profile(self):
        """
        Make sure some warning are thrown when trying to import from framework.
        """
        super(LibrarySettingsProfile, self).initialize_profile()
        sys.meta_path.append(LibraryModulesFinder())

Example 6

Project: Git-Auto-Deploy
Source File: utils.py
View license
    def setUp(self):
        import sys

        # Use our custom importer to replace certain modules with stub modules to
        # enable testing of other parts of GAD
        sys.meta_path.append(StubImporter())

Example 7

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 8

Project: imagrium
Source File: test_importhooks.py
View license
    def doTestImpWrapper(self, globals_func=globals, locals_func=locals):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        mnames = ("colorsys", "urlparse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals_func(), locals_func(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 9

Project: archivczsk
Source File: contentprovider.py
View license
    def __set_resolving_provider(self):
        VideoAddonContentProvider.__resolving_provider = self
        VideoAddonContentProvider.__addon_sys.add_addon(self.video_addon)
        self.video_addon.include()
        self.resolve_dependencies()
        self.include_dependencies()
        sys.meta_path.append(self._sys_importer)

Example 10

Project: PyEMMA
Source File: shimmodule.py
View license
    def __init__(self, *args, **kwargs):
        self._mirror = kwargs.pop("mirror")
        self._from = self._mirror.split('.')
        src = kwargs.pop("src", None)
        if src:
            kwargs['name'] = src.rsplit('.', 1)[-1]
        super(ShimModule, self).__init__(*args, **kwargs)
        # add import hook for descendant modules
        if src:
            sys.meta_path.append(
                ShimImporter(src=src, mirror=self._mirror)
            )
        self.msg = kwargs.pop("msg", None)
        self.default_msg = "Access to a moved module '%s' detected!" \
                           " Please use '%s' in the future." % (src, self._mirror)

Example 11

Project: TrustRouter
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urllib.parse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in list(sys.modules):
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals(), locals(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 12

Project: chipsec
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 13

Project: flask
Source File: test_instance_config.py
View license
@pytest.mark.skipif(not PY2, reason='This only works under Python 2.')
def test_meta_path_loader_without_is_package(request, modules_tmpdir):
    app = modules_tmpdir.join('unimportable.py')
    app.write('import flask\napp = flask.Flask(__name__)')

    class Loader(object):
        def find_module(self, name, path=None):
            return self

    sys.meta_path.append(Loader())
    request.addfinalizer(sys.meta_path.pop)

    with pytest.raises(AttributeError):
        import unimportable

Example 14

Project: datafari
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 15

Project: neuroConstruct
Source File: test_importhooks.py
View license
    def doTestImpWrapper(self, globals_func=globals, locals_func=locals):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        mnames = ("colorsys", "urlparse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals_func(), locals_func(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 16

Project: pyspider
Source File: processor.py
View license
    def enable_projects_import(self):
        '''
        Enable import other project as module

        `from project import project_name`
        '''
        if six.PY2:
            sys.meta_path.append(ProjectFinder(self.projectdb))

Example 17

Project: synapse
Source File: mindmeld.py
View license
def addMindMeld(meld):
    '''
    Add a MindMeld instance to the current python import hooks.

    Example:

        addMindMeld(meld)

    '''
    sys.meta_path.append(meld)

Example 18

Project: pyfilesystem
Source File: test_importhook.py
View license
    def test_importer_on_meta_path(self):
        t = TempFS()
        self._init_modules(t)
        ih = FSImportHook(t)
        sys.meta_path.append(ih)
        try:
            self._check_imports_are_working()
        finally:
            sys.meta_path.remove(ih)
            t.close()

Example 19

Project: babble
Source File: test_importhooks.py
View license
    def doTestImpWrapper(self, globals_func=globals, locals_func=locals):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        mnames = ("colorsys", "urlparse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals_func(), locals_func(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 20

Project: brython
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.insert(0, ImpWrapper)
        mnames = (
            "colorsys", "urllib.parse", "distutils.core", "sys",
        )
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in list(sys.modules):
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals(), locals(), ["__dummy__"])
            # to make sure we actually handled the import
            self.assertTrue(hasattr(m, "__loader__"))

Example 21

Project: neuroConstruct
Source File: test_importhooks.py
View license
    def doTestImpWrapper(self, globals_func=globals, locals_func=locals):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        mnames = ("colorsys", "urlparse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals_func(), locals_func(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 22

Project: pymo
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 23

Project: medicare-demo
Source File: test_importhooks.py
View license
    def doTestImpWrapper(self, globals_func=globals, locals_func=locals):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        mnames = ("colorsys", "urlparse", "distutils.core")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        for mname in mnames:
            m = __import__(mname, globals_func(), locals_func(), ["__dummy__"])
            m.__loader__  # to make sure we actually handled the import

Example 24

Project: json-sempai
Source File: sempai.py
View license
@contextlib.contextmanager
def imports():
    try:
        sys.meta_path.append(SempaiLoader)
        yield
    finally:
        sys.meta_path.remove(SempaiLoader)

Example 25

Project: json-sempai
Source File: sempai.py
View license
@contextlib.contextmanager
def imports():
    try:
        sys.meta_path.append(SempaiLoader)
        yield
    finally:
        sys.meta_path.remove(SempaiLoader)

Example 26

Project: archivczsk
Source File: contentprovider.py
View license
    def __set_resolving_provider(self):
        VideoAddonContentProvider.__resolving_provider = self
        VideoAddonContentProvider.__addon_sys.add_addon(self.video_addon)
        self.video_addon.include()
        self.resolve_dependencies()
        self.include_dependencies()
        sys.meta_path.append(self._sys_importer)

Example 27

Project: pyload
Source File: PluginManager.py
View license
    def __init__(self, core):
        self.core = core

        #self.config = self.core.config
        self.log = core.log

        self.plugins = {}
        self.createIndex()

        #register for import hook
        sys.meta_path.append(self)

Example 28

Project: PyAutoC
Source File: test_importhooks.py
View license
    def testImpWrapper(self):
        i = ImpWrapper()
        sys.meta_path.append(i)
        sys.path_hooks.append(ImpWrapper)
        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
        for mname in mnames:
            parent = mname.split(".")[0]
            for n in sys.modules.keys():
                if n.startswith(parent):
                    del sys.modules[n]
        with test_support.check_warnings(("The compiler package is deprecated "
                                          "and removed", DeprecationWarning)):
            for mname in mnames:
                m = __import__(mname, globals(), locals(), ["__dummy__"])
                m.__loader__  # to make sure we actually handled the import

Example 29

Project: PyEMMA
Source File: shimmodule.py
View license
    def __init__(self, *args, **kwargs):
        self._mirror = kwargs.pop("mirror")
        self._from = self._mirror.split('.')
        src = kwargs.pop("src", None)
        if src:
            kwargs['name'] = src.rsplit('.', 1)[-1]
        super(ShimModule, self).__init__(*args, **kwargs)
        # add import hook for descendant modules
        if src:
            sys.meta_path.append(
                ShimImporter(src=src, mirror=self._mirror)
            )
        self.msg = kwargs.pop("msg", None)
        self.default_msg = "Access to a moved module '%s' detected!" \
                           " Please use '%s' in the future." % (src, self._mirror)

Example 30

Project: kippo-extra
Source File: loader.py
View license
def install_hook():
    # Extend kippo's commands
    import kippo.commands
    import kippo_extra.commands

    for command in kippo_extra.commands.__all__:
        module = "%s.%s" % (kippo_extra.commands.__name__, command)
        kippo.commands.__all__.append(module)

    # Add import interceptor
    sys.meta_path.append(KippoExtraLoader())

Example 31

Project: logan
Source File: importer.py
View license
def install(name, config_path, default_settings, **kwargs):
    global installed

    if installed:
        # TODO: reinstall
        return

    sys.meta_path.append(LoganImporter(name, config_path, default_settings, **kwargs))
    installed = True

Example 32

Project: py12306
Source File: pyi_importers.py
View license
def install():
    """
    Install FrozenImporter class and other classes into the import machinery.

    This class method (static method) installs the FrozenImporter class into
    the import machinery of the running process. The importer is added
    to sys.meta_path. It could be added to sys.path_hooks but sys.meta_path
    is processed by Python before looking at sys.path!

    The order of processing import hooks in sys.meta_path:

    1. built-in modules
    2. modules from the bundled ZIP archive
    3. C extension modules
    """
    # First look in the built-in modules and not bundled ZIP archive.
    sys.meta_path.append(BuiltinImporter())
    # Ensure Python looks in the bundled zip archive for modules before any
    # other places.
    sys.meta_path.append(FrozenImporter())
    # Import hook for the C extension modules.
    sys.meta_path.append(CExtensionImporter())

Example 33

Project: exetractor-clone
Source File: pyi_importers.py
View license
def install():
    """
    Install FrozenImporter class and other classes into the import machinery.

    This class method (static method) installs the FrozenImporter class into
    the import machinery of the running process. The importer is added
    to sys.meta_path. It could be added to sys.path_hooks but sys.meta_path
    is processed by Python before looking at sys.path!

    The order of processing import hooks in sys.meta_path:

    1. built-in modules
    2. modules from the bundled ZIP archive
    3. C extension modules
    """
    # First look in the built-in modules and not bundled ZIP archive.
    sys.meta_path.append(BuiltinImporter())
    # Ensure Python looks in the bundled zip archive for modules before any
    # other places.
    sys.meta_path.append(FrozenImporter())
    # Import hook for the C extension modules.
    sys.meta_path.append(CExtensionImporter())

Example 34

Project: exetractor-clone
Source File: pyi_importers.py
View license
def install():
    """
    Install FrozenImporter class and other classes into the import machinery.

    This class method (static method) installs the FrozenImporter class into
    the import machinery of the running process. The importer is added
    to sys.meta_path. It could be added to sys.path_hooks but sys.meta_path
    is processed by Python before looking at sys.path!

    The order of processing import hooks in sys.meta_path:

    1. built-in modules
    2. modules from the bundled ZIP archive
    3. C extension modules
    """
    # First look in the built-in modules and not bundled ZIP archive.
    sys.meta_path.append(BuiltinImporter())
    # Ensure Python looks in the bundled zip archive for modules before any
    # other places.
    sys.meta_path.append(FrozenImporter())
    # Import hook for the C extension modules.
    sys.meta_path.append(CExtensionImporter())

Example 35

Project: earwigbot
Source File: lazy.py
View license
    def __init__(self):
        self._modules = {}
        sys.meta_path.append(self)

Example 36

Project: gae-flask-todo
Source File: _backwards.py
View license
def import_redirect(old, new):
    sys.meta_path.append(ImportRedirect(old, new))

Example 37

Project: flask-admin
Source File: _backwards.py
View license
def import_redirect(old, new):
    sys.meta_path.append(ImportRedirect(old, new))

Example 38

Project: datafari
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 39

Project: datafari
Source File: test_importhooks.py
View license
    def testBlocker(self):
        mname = "exceptions"  # an arbitrary harmless builtin module
        test_support.unload(mname)
        sys.meta_path.append(ImportBlocker(mname))
        self.assertRaises(ImportError, __import__, mname)

Example 40

Project: pymo
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 41

Project: babble
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 42

Project: vivisect
Source File: dcode.py
View license
def addDcodeProxy(proxy):
    finder = DcodeFinder(proxy)
    sys.meta_path.append(finder)

Example 43

Project: sentry
Source File: importer.py
View license
def install(name, config_path, default_settings, callback=None):
    sys.meta_path.append(Importer(name, config_path, default_settings, callback))

Example 44

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 45

Project: pyspider
Source File: debug.py
View license
@app.before_first_request
def enable_projects_import():
    sys.meta_path.append(ProjectFinder(app.config['projectdb']))

Example 46

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testBlocker(self):
        mname = "exceptions"  # an arbitrary harmless builtin module
        test_support.unload(mname)
        sys.meta_path.append(ImportBlocker(mname))
        self.assertRaises(ImportError, __import__, mname)

Example 47

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 48

Project: pymo
Source File: test_importhooks.py
View license
    def testBlocker(self):
        mname = "exceptions"  # an arbitrary harmless builtin module
        test_support.unload(mname)
        sys.meta_path.append(ImportBlocker(mname))
        self.assertRaises(ImportError, __import__, mname)

Example 49

Project: brython
Source File: test_importhooks.py
View license
    def testMetaPath(self):
        i = MetaImporter()
        sys.meta_path.append(i)
        self.doTestImports(i)

Example 50

Project: openwrt-mt7620
Source File: test_importhooks.py
View license
    def testBlocker(self):
        mname = "exceptions"  # an arbitrary harmless builtin module
        test_support.unload(mname)
        sys.meta_path.append(ImportBlocker(mname))
        self.assertRaises(ImportError, __import__, mname)