sys.modules.items

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

199 Examples 7

Example 1

Project: pymo
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 2

Project: mavelous
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 3

Project: HTPC-Manager
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 4

Project: pyqtgraph
Source File: debug.py
View license
def listRedundantModules():
    """List modules that have been imported more than once via different paths."""
    mods = {}
    for name, mod in sys.modules.items():
        if not hasattr(mod, '__file__'):
            continue
        mfile = os.path.abspath(mod.__file__)
        if mfile[-1] == 'c':
            mfile = mfile[:-1]
        if mfile in mods:
            print("module at %s has 2 names: %s, %s" % (mfile, name, mods[mfile]))
        else:
            mods[mfile] = name

Example 5

Project: gourmet
Source File: ipython_view.py
View license
  def __update_namespace(self):
    '''
    Update self.IP namespace for autocompletion with sys.modules
    '''
    for k,v in sys.modules.items():
        if not '.' in k:
          self.IP.user_ns.update({k:v})

Example 6

Project: lymph
Source File: autoreload.py
View license
def watch_modules(callback):
    modules = {}
    while True:
        for name, module in list(sys.modules.items()):
            if module is None or not hasattr(module, '__file__'):
                continue
            module_source_path = os.path.abspath(module.__file__).rstrip('c')
            try:
                stat = os.stat(module_source_path)
            except OSError:
                continue
            mtime = stat.st_mtime
            if name in modules and modules[name] != mtime:
                callback()
            modules[name] = mtime
        gevent.sleep(1)

Example 7

Project: qgisSpaceSyntaxToolkit
Source File: debug.py
View license
def listRedundantModules():
    """List modules that have been imported more than once via different paths."""
    mods = {}
    for name, mod in sys.modules.items():
        if not hasattr(mod, '__file__'):
            continue
        mfile = os.path.abspath(mod.__file__)
        if mfile[-1] == 'c':
            mfile = mfile[:-1]
        if mfile in mods:
            print("module at %s has 2 names: %s, %s" % (mfile, name, mods[mfile]))
        else:
            mods[mfile] = name

Example 8

Project: canape
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 9

Project: PythonScript
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 10

Project: PythonScript
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 11

Project: scikit-learn
Source File: testing.py
View license
def clean_warning_registry():
    """Safe way to reset warnings."""
    warnings.resetwarnings()
    reg = "__warningregistry__"
    for mod_name, mod in list(sys.modules.items()):
        if 'six.moves' in mod_name:
            continue
        if hasattr(mod, reg):
            getattr(mod, reg).clear()

Example 12

Project: WAPT
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 13

Project: pyp2rpm
Source File: pytester.py
View license
    def finalize(self):
        for p in self._syspathremove:
            py.std.sys.path.remove(p)
        if hasattr(self, '_olddir'):
            self._olddir.chdir()
        # delete modules that have been loaded from tmpdir
        for name, mod in list(sys.modules.items()):
            if mod:
                fn = getattr(mod, '__file__', None)
                if fn and fn.startswith(str(self.tmpdir)):
                    del sys.modules[name]

Example 14

Project: GitSavvy
Source File: reload.py
View license
def reload_plugin():
    """Reload the GitSavvy plugin among with all its modules."""
    from GitSavvy import git_savvy
    dprint("begin", fill='═')

    modules = {name: module for name, module in sys.modules.items()
               if name.startswith("GitSavvy.")}
    try:
        reload_modules(git_savvy, modules)
    except:
        dprint("ERROR", fill='─')
        reload_modules(git_savvy, modules, perform_reload=False)
        raise
    finally:
        ensure_loaded(git_savvy, modules)

    dprint("end", fill='━')

Example 15

Project: exaile
Source File: ipython_view.py
View license
  def __update_namespace(self):
    '''
    Update self.IP namespace for autocompletion with sys.modules
    '''
    for k, v in list(sys.modules.items()):
        if not '.' in k:
          self.IP.user_ns.update({k:v})

Example 16

Project: Python-mode-klen
Source File: modutils.py
View license
def cleanup_sys_modules(directories):
    """remove submodules of `directories` from `sys.modules`"""
    for modname, module in sys.modules.items():
        modfile = getattr(module, '__file__', None)
        if modfile:
            for directory in directories:
                if modfile.startswith(directory):
                    del sys.modules[modname]
                    break

Example 17

Project: headphones
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in list(sys.modules.items()):
            if re.match(self.match, k):
                if (
                    hasattr(m, '__loader__') and
                    hasattr(m.__loader__, 'archive')
                ):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app
                        # doesn't break me
                        f = os.path.normpath(
                            os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 18

Project: Sick-Beard
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of filenames which the Autoreloader will monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 19

Project: databus
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 20

Project: Sick-Beard-TPB
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of filenames which the Autoreloader will monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 21

Project: cgstudiomap
Source File: server.py
View license
def load_test_file_py(registry, test_file):
    # Locate python module based on its filename and run the tests
    test_path, _ = os.path.splitext(os.path.abspath(test_file))
    for mod_name, mod_mod in sys.modules.items():
        if mod_mod:
            mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', ''))
            if test_path == mod_path:
                suite = unittest2.TestSuite()
                for t in unittest2.TestLoader().loadTestsFromModule(mod_mod):
                    suite.addTest(t)
                _logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__)
                stream = openerp.modules.module.TestStream()
                result = unittest2.TextTestRunner(verbosity=2, stream=stream).run(suite)
                success = result.wasSuccessful()
                if hasattr(registry._assertion_report,'report_result'):
                    registry._assertion_report.report_result(success)
                if not success:
                    _logger.error('%s: at least one error occurred in a test', test_file)

Example 22

Project: GoAtThrottleUp
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 23

Project: chipsec
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 24

Project: rpyc
Source File: splitbrain.py
View license
def disable_splitbrain():
    """Disables (deactivates) the Splitbrain machinery"""
    global _enabled
    if not _enabled:
        return
    _enabled = False
    for funcname, origfunc in _prev_builtins.items():
        setattr(builtins, funcname, origfunc)
    for modname, mod in sys.modules.items():
        if isinstance(mod, RoutedModule):
            sys.modules[modname] = mod.__realmod__
            for ref in gc.get_referrers(mod):
                if isinstance(ref, dict) and "__name__" in ref and ref.get("__file__") is not None:
                    for k, v in ref.items():
                        if v is mod:
                            ref[k] = mod.__realmod__
    sys.modules["sys"] = sys
    builtins.__import__ = _orig_import

Example 25

View license
    def sysfiles(self):
        """Return a Set of filenames which the Autoreloader will monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 26

Project: gplearn
Source File: testing.py
View license
def clean_warning_registry():
    """Safe way to reset warnings """
    warnings.resetwarnings()
    reg = "__warningregistry__"
    for mod_name, mod in list(sys.modules.items()):
        if 'six.moves' in mod_name:
            continue
        if hasattr(mod, reg):
            getattr(mod, reg).clear()

Example 27

Project: PokemonGo-Bot-Desktop
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 28

Project: datafari
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 29

Project: feat
Source File: applications.py
View license
    def unload(self):
        self.info("Unloading application %s", self.name)
        self._restorators.application_cleanup(self)
        self._agents.application_cleanup(self)
        self._views.application_cleanup(self)
        self._initial_data.application_cleanup(self)
        self._models.application_cleanup(self)
        self._migrations.application_cleanup(self)
        self.unload_adapters()
        del(self._adapters)

        for canonical_name, module in sys.modules.items():
            if not self._should_be_unloaded(canonical_name):
                continue
            self.info("Removing module %s from sys.modules", canonical_name)
            m = sys.modules[canonical_name]
            del(sys.modules[canonical_name])
            del(m)

Example 30

Project: moul-scripts
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 31

Project: bh2014
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 32

View license
    def get_module_names(self):
        res = []
        for name, module in sys.modules.items():
            try:
                if name != 'visualstudio_py_repl' and name != '$visualstudio_py_debugger':
                    if sys.platform == 'cli' and type(module) is NamespaceType:
                        self.get_namespaces(name, module, res)
                    else:
                        filename = getattr(module, '__file__', '') or ''
                        res.append((name, filename))

            except:
                pass
        return res

Example 33

Project: oleviewdotnet
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 34

Project: openwrt-mt7620
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 35

Project: TACTIC
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of filenames which the Autoreloader will monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 36

Project: odoo
Source File: server.py
View license
def load_test_file_py(registry, test_file):
    # Locate python module based on its filename and run the tests
    test_path, _ = os.path.splitext(os.path.abspath(test_file))
    for mod_name, mod_mod in sys.modules.items():
        if mod_mod:
            mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', ''))
            if test_path == mod_path:
                suite = unittest2.TestSuite()
                for t in unittest2.TestLoader().loadTestsFromModule(mod_mod):
                    suite.addTest(t)
                _logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__)
                stream = openerp.modules.module.TestStream()
                result = unittest2.TextTestRunner(verbosity=2, stream=stream).run(suite)
                success = result.wasSuccessful()
                if hasattr(registry._assertion_report,'report_result'):
                    registry._assertion_report.report_result(success)
                if not success:
                    _logger.error('%s: at least one error occurred in a test', test_file)

Example 37

Project: gxf
Source File: reload.py
View license
    def run(self, args):
        toreload, toremove = set(), set()
        packages = [(p, p.split('.')) for p in args.package]
        for name, module in sys.modules.items():
            path = name.split('.')
            for p, ps in packages:
                if p == name:
                    toreload.add(name)
                elif ps == path[:len(ps)]:
                    toremove.add(name)

        for name in toremove:
            if name not in toreload:
                del sys.modules[name]

        for name in sorted(toreload):
            importlib.reload(sys.modules[name])

Example 38

Project: cylc
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in list(sys.modules.items()):
            if re.match(self.match, k):
                if (
                    hasattr(m, '__loader__') and
                    hasattr(m.__loader__, 'archive')
                ):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app
                        # doesn't break me
                        f = os.path.normpath(
                            os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 39

Project: WeCase
Source File: debug.py
View license
def listRedundantModules():
    """List modules that have been imported more than once via different paths."""
    mods = {}
    for name, mod in sys.modules.items():
        if not hasattr(mod, '__file__'):
            continue
        mfile = os.path.abspath(mod.__file__)
        if mfile[-1] == 'c':
            mfile = mfile[:-1]
        if mfile in mods:
            print("module at %s has 2 names: %s, %s" % (mfile, name, mods[mfile]))
        else:
            mods[mfile] = name

Example 40

Project: CouchPotatoV1
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 41

View license
    def remove_cached_mods(self):
        """Remove all the script modules from the system cache."""
        paths, files = self.get_paths()
        for mod_name, mod in list(sys.modules.items()):
            if hasattr(mod, '__file__') and os.path.dirname(mod.__file__) in paths:
                del sys.modules[mod_name]

Example 42

Project: openwrt-mt7620
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 43

Project: BlackbodyMaya
Source File: __init__.py
View license
def __get_modules(filepath):
	path, file = os.path.split(__normpath(filepath))
	mdict = {}
	for mname, mod in sys.modules.items():
		if '__file__' not in dir(mod):
			continue
		if re.match('%s.*' % path, __normpath(mod.__file__)):
			mdict[mname] = mod
	return mdict

Example 44

Project: brython
Source File: test_api.py
View license
    def test_everyone_has___loader__(self):
        # Issue #17098: all modules should have __loader__ defined.
        for name, module in sys.modules.items():
            if isinstance(module, types.ModuleType):
                if name in sys.builtin_module_names:
                    self.assertEqual(importlib.machinery.BuiltinImporter,
                                     module.__loader__)
                elif imp.is_frozen(name):
                    self.assertEqual(importlib.machinery.FrozenImporter,
                                     module.__loader__)

Example 45

Project: LazyLibrarian
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 46

Project: openwrt-mt7620
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'

Example 47

Project: pattern
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 48

Project: zstack-utility
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 49

Project: moviegrabber
Source File: plugins.py
View license
    def sysfiles(self):
        """Return a Set of sys.modules filenames to monitor."""
        files = set()
        for k, m in sys.modules.items():
            if re.match(self.match, k):
                if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
                    f = m.__loader__.archive
                else:
                    f = getattr(m, '__file__', None)
                    if f is not None and not os.path.isabs(f):
                        # ensure absolute paths so a os.chdir() in the app doesn't break me
                        f = os.path.normpath(os.path.join(_module__file__base, f))
                files.add(f)
        return files

Example 50

Project: pyjs
Source File: imputil.py
View license
def _print_importers():
    items = sys.modules.items()
    items.sort()
    for name, module in items:
        if module:
            print name, module.__dict__.get('__importer__', '-- no importer')
        else:
            print name, '-- non-existent module'