sys.modules.keys

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

169 Examples 7

Example 151

Project: pgi
Source File: setup.py
View license
    def run(self):
        set_test_environ()

        # Wipe existing modules, to make sure coverage data is properly
        # generated for them.
        for key in list(sys.modules.keys()):
            if key.startswith('pgi'):
                del(sys.modules[key])

        try:
            from coverage import coverage
        except ImportError:
            print("Missing 'coverage' module. See "
                  "https://pypi.python.org/pypi/coverage or try "
                  "`apt-get install python-coverage`")
            return

        cov = coverage()
        cov.start()

        import tests
        tests.test(False, "cffi")

        dest = os.path.join(os.getcwd(), "coverage")

        cov.stop()
        cov.html_report(
            directory=dest,
            ignore_errors=True,
            include=["pgi/*"])

        print("Coverage summary: file://%s/index.html" % dest)

Example 152

Project: pgi
Source File: setup.py
View license
    def run(self):
        set_test_environ()

        # Wipe existing modules, to make sure coverage data is properly
        # generated for them.
        for key in list(sys.modules.keys()):
            if key.startswith('pgi'):
                del(sys.modules[key])

        try:
            from coverage import coverage
        except ImportError:
            print("Missing 'coverage' module. See "
                  "https://pypi.python.org/pypi/coverage or try "
                  "`apt-get install python-coverage`")
            return

        cov = coverage()
        cov.start()

        import tests
        tests.test(False, "cffi")

        dest = os.path.join(os.getcwd(), "coverage")

        cov.stop()
        cov.html_report(
            directory=dest,
            ignore_errors=True,
            include=["pgi/*"])

        print("Coverage summary: file://%s/index.html" % dest)

Example 153

Project: connectomeviewer
Source File: build_helpers.py
View license
    def run(self):
        """ build and install nipy in a temporary location. """
        install = self.distribution.get_command_obj('install')
        install.install_scripts = self.temp_install_dir
        install.install_base    = self.temp_install_dir
        install.install_platlib = self.temp_install_dir 
        install.install_purelib = self.temp_install_dir 
        install.install_data    = self.temp_install_dir 
        install.install_lib     = self.temp_install_dir 
        install.install_headers = self.temp_install_dir 
        install.run()

        # Horrible trick to reload nipy with our temporary instal
        for key in sys.modules.keys():
            if key.startswith('nipy'):
                sys.modules.pop(key, None)
        sys.path.append(os.path.abspath(self.temp_install_dir))
        # Pop the cwd
        sys.path.pop(0)
        import nipy

Example 154

Project: connectomeviewer
Source File: build_helpers.py
View license
    def run(self):
        """ build and install nipy in a temporary location. """
        install = self.distribution.get_command_obj('install')
        install.install_scripts = self.temp_install_dir
        install.install_base    = self.temp_install_dir
        install.install_platlib = self.temp_install_dir 
        install.install_purelib = self.temp_install_dir 
        install.install_data    = self.temp_install_dir 
        install.install_lib     = self.temp_install_dir 
        install.install_headers = self.temp_install_dir 
        install.run()

        # Horrible trick to reload nipy with our temporary instal
        for key in sys.modules.keys():
            if key.startswith('nipy'):
                sys.modules.pop(key, None)
        sys.path.append(os.path.abspath(self.temp_install_dir))
        # Pop the cwd
        sys.path.pop(0)
        import nipy

Example 155

Project: spiderosm
Source File: misc.py
View license
def module_loaded_q(mod_name):
    return mod_name in sys.modules.keys()

Example 156

Project: spiderosm
Source File: misc.py
View license
def module_loaded_q(mod_name):
    return mod_name in sys.modules.keys()

Example 157

Project: pythoscope
Source File: tracer.py
View license
    def setup(self, code):
        self.top_level_function = make_callable(code)
        self.sys_modules = sys.modules.keys()

Example 158

Project: pythoscope
Source File: tracer.py
View license
    def setup(self, code):
        self.top_level_function = make_callable(code)
        self.sys_modules = sys.modules.keys()

Example 159

View license
def mpl_style_cb(key):
    warnings.warn(pc_mpl_style_deprecation_warning, FutureWarning,
                  stacklevel=5)

    import sys
    from pandas.tools.plotting import mpl_stylesheet
    global style_backup

    val = cf.get_option(key)

    if 'matplotlib' not in sys.modules.keys():
        if not val:  # starting up, we get reset to None
            return val
        raise Exception("matplotlib has not been imported. aborting")

    import matplotlib.pyplot as plt

    if val == 'default':
        style_backup = dict([(k, plt.rcParams[k]) for k in mpl_stylesheet])
        plt.rcParams.update(mpl_stylesheet)
    elif not val:
        if style_backup:
            plt.rcParams.update(style_backup)

    return val

Example 160

View license
def mpl_style_cb(key):
    warnings.warn(pc_mpl_style_deprecation_warning, FutureWarning,
                  stacklevel=5)

    import sys
    from pandas.tools.plotting import mpl_stylesheet
    global style_backup

    val = cf.get_option(key)

    if 'matplotlib' not in sys.modules.keys():
        if not val:  # starting up, we get reset to None
            return val
        raise Exception("matplotlib has not been imported. aborting")

    import matplotlib.pyplot as plt

    if val == 'default':
        style_backup = dict([(k, plt.rcParams[k]) for k in mpl_stylesheet])
        plt.rcParams.update(mpl_stylesheet)
    elif not val:
        if style_backup:
            plt.rcParams.update(style_backup)

    return val

Example 161

Project: python-armet
Source File: base.py
View license
    @pytest.fixture(autouse=True, scope='class')
    def initialize(self, request, connectors):
        # Install the WSGI interception layer.
        install()

        # Unload django.
        for module in list(sys.modules.keys()):
            if module and 'django' in module:
                del sys.modules[module]

        # Reset and clear all global cache in armet.
        from armet import decorators

        decorators._resources = {}
        # decorators._handlers = {}
        armet.use.config = {}

        # Re-initialize the configuration.
        armet.use(connectors=connectors, debug=True)

        prefix = 'tests.connectors.'
        callback = None
        if 'model' in connectors:
            # Initialize the database access layer.
            model = import_module(prefix + connectors['model'])
            callback = model.model_setup

            # Add the models module so that it can be generically imported.
            sys.modules[prefix + 'models'] = model
            request.cls.models = model

        # Initialize the http access layer.
        http = import_module(prefix + connectors['http'])
        http.http_setup(connectors, self.host, self.port, callback=callback)

        # Add a finalizer to teardown the http layer.
        request.addfinalizer(lambda: http.http_teardown(self.host, self.port))

Example 162

Project: mlat-server
Source File: jsonclient.py
View license
    def process_quine_message(self, m):
        if not m:
            q = list(sys.modules.keys())
        else:
            _m = sys.modules.get(m)
            if not _m:
                q = None
            elif not hasattr(_m, '__file__'):
                q = '# builtin'
            else:
                try:
                    q = inspect.getsource(_m)
                except OSError:
                    q = None
                if not q:
                    try:
                        q = '# file: ' + inspect.getabsfile(_m)
                    except OSError:
                        q = '# unknown'
        self.send(quine=[m, q])

Example 163

Project: mlat-server
Source File: jsonclient.py
View license
    def process_quine_message(self, m):
        if not m:
            q = list(sys.modules.keys())
        else:
            _m = sys.modules.get(m)
            if not _m:
                q = None
            elif not hasattr(_m, '__file__'):
                q = '# builtin'
            else:
                try:
                    q = inspect.getsource(_m)
                except OSError:
                    q = None
                if not q:
                    try:
                        q = '# file: ' + inspect.getabsfile(_m)
                    except OSError:
                        q = '# unknown'
        self.send(quine=[m, q])

Example 164

Project: python-git-orm
Source File: test_importer.py
View license
    def teardown(self):
        for mod in list(sys.modules.keys()):
            if mod == 'foo' or mod.startswith('foo'):
                del sys.modules[mod]
        super().teardown()

Example 165

Project: python-git-orm
Source File: test_importer.py
View license
    def teardown(self):
        for mod in list(sys.modules.keys()):
            if mod == 'foo' or mod.startswith('foo'):
                del sys.modules[mod]
        super().teardown()

Example 166

Project: nipy
Source File: setup_helpers.py
View license
    def run(self):
        """ build and install nipy in a temporary location. """
        install = self.distribution.get_command_obj('install')
        install.install_scripts = self.temp_install_dir
        install.install_base    = self.temp_install_dir
        install.install_platlib = self.temp_install_dir 
        install.install_purelib = self.temp_install_dir 
        install.install_data    = self.temp_install_dir 
        install.install_lib     = self.temp_install_dir 
        install.install_headers = self.temp_install_dir 
        install.run()

        # Horrible trick to reload nipy with our temporary instal
        for key in sys.modules.keys():
            if key.startswith('nipy'):
                sys.modules.pop(key, None)
        sys.path.append(os.path.abspath(self.temp_install_dir))
        # Pop the cwd
        sys.path.pop(0)
        import nipy

Example 167

Project: nipy
Source File: setup_helpers.py
View license
    def run(self):
        """ build and install nipy in a temporary location. """
        install = self.distribution.get_command_obj('install')
        install.install_scripts = self.temp_install_dir
        install.install_base    = self.temp_install_dir
        install.install_platlib = self.temp_install_dir 
        install.install_purelib = self.temp_install_dir 
        install.install_data    = self.temp_install_dir 
        install.install_lib     = self.temp_install_dir 
        install.install_headers = self.temp_install_dir 
        install.run()

        # Horrible trick to reload nipy with our temporary instal
        for key in sys.modules.keys():
            if key.startswith('nipy'):
                sys.modules.pop(key, None)
        sys.path.append(os.path.abspath(self.temp_install_dir))
        # Pop the cwd
        sys.path.pop(0)
        import nipy

Example 168

View license
    def test_namespacedPackages(self):
        """
        Duplicate packages are not yielded when iterating over namespace
        packages.
        """
        # Force pkgutil to be loaded already, since the probe package being
        # created depends on it, and the replaceSysPath call below will make
        # pretty much everything unimportable.
        __import__('pkgutil')

        namespaceBoilerplate = (
            'import pkgutil; '
            '__path__ = pkgutil.extend_path(__path__, __name__)')

        # Create two temporary directories with packages:
        #
        #   entry:
        #       test_package/
        #           __init__.py
        #           nested_package/
        #               __init__.py
        #               module.py
        #
        #   anotherEntry:
        #       test_package/
        #           __init__.py
        #           nested_package/
        #               __init__.py
        #               module2.py
        #
        # test_package and test_package.nested_package are namespace packages,
        # and when both of these are in sys.path, test_package.nested_package
        # should become a virtual package containing both "module" and
        # "module2"

        entry = self.pathEntryWithOnePackage()
        testPackagePath = entry.child('test_package')
        testPackagePath.child('__init__.py').setContent(namespaceBoilerplate)

        nestedEntry = testPackagePath.child('nested_package')
        nestedEntry.makedirs()
        nestedEntry.child('__init__.py').setContent(namespaceBoilerplate)
        nestedEntry.child('module.py').setContent('')

        anotherEntry = self.pathEntryWithOnePackage()
        anotherPackagePath = anotherEntry.child('test_package')
        anotherPackagePath.child('__init__.py').setContent(namespaceBoilerplate)

        anotherNestedEntry = anotherPackagePath.child('nested_package')
        anotherNestedEntry.makedirs()
        anotherNestedEntry.child('__init__.py').setContent(namespaceBoilerplate)
        anotherNestedEntry.child('module2.py').setContent('')

        self.replaceSysPath([entry.path, anotherEntry.path])

        module = modules.getModule('test_package')

        # We have to use importPackages=True in order to resolve the namespace
        # packages, so we remove the imported packages from sys.modules after
        # walking
        try:
            walkedNames = [
                mod.name for mod in module.walkModules(importPackages=True)]
        finally:
            for module in sys.modules.keys():
                if module.startswith('test_package'):
                    del sys.modules[module]

        expected = [
            'test_package',
            'test_package.nested_package',
            'test_package.nested_package.module',
            'test_package.nested_package.module2',
            ]

        self.assertEqual(walkedNames, expected)

Example 169

View license
    def test_namespacedPackages(self):
        """
        Duplicate packages are not yielded when iterating over namespace
        packages.
        """
        # Force pkgutil to be loaded already, since the probe package being
        # created depends on it, and the replaceSysPath call below will make
        # pretty much everything unimportable.
        __import__('pkgutil')

        namespaceBoilerplate = (
            'import pkgutil; '
            '__path__ = pkgutil.extend_path(__path__, __name__)')

        # Create two temporary directories with packages:
        #
        #   entry:
        #       test_package/
        #           __init__.py
        #           nested_package/
        #               __init__.py
        #               module.py
        #
        #   anotherEntry:
        #       test_package/
        #           __init__.py
        #           nested_package/
        #               __init__.py
        #               module2.py
        #
        # test_package and test_package.nested_package are namespace packages,
        # and when both of these are in sys.path, test_package.nested_package
        # should become a virtual package containing both "module" and
        # "module2"

        entry = self.pathEntryWithOnePackage()
        testPackagePath = entry.child('test_package')
        testPackagePath.child('__init__.py').setContent(namespaceBoilerplate)

        nestedEntry = testPackagePath.child('nested_package')
        nestedEntry.makedirs()
        nestedEntry.child('__init__.py').setContent(namespaceBoilerplate)
        nestedEntry.child('module.py').setContent('')

        anotherEntry = self.pathEntryWithOnePackage()
        anotherPackagePath = anotherEntry.child('test_package')
        anotherPackagePath.child('__init__.py').setContent(namespaceBoilerplate)

        anotherNestedEntry = anotherPackagePath.child('nested_package')
        anotherNestedEntry.makedirs()
        anotherNestedEntry.child('__init__.py').setContent(namespaceBoilerplate)
        anotherNestedEntry.child('module2.py').setContent('')

        self.replaceSysPath([entry.path, anotherEntry.path])

        module = modules.getModule('test_package')

        # We have to use importPackages=True in order to resolve the namespace
        # packages, so we remove the imported packages from sys.modules after
        # walking
        try:
            walkedNames = [
                mod.name for mod in module.walkModules(importPackages=True)]
        finally:
            for module in sys.modules.keys():
                if module.startswith('test_package'):
                    del sys.modules[module]

        expected = [
            'test_package',
            'test_package.nested_package',
            'test_package.nested_package.module',
            'test_package.nested_package.module2',
            ]

        self.assertEqual(walkedNames, expected)