Del user modules to force Python to deeply reload them

        Do not del modules which are considered as system modules, i.e.
        modules installed in subdirectories of Python interpreter's binary
        Do not del C modules
332475
def run(self, verbose=False):
        
        log = []
        modules_copy = dict(sys.modules)
        for modname, module in modules_copy.items():
            if modname == 'aaaaa':
                print(modname, module)
                print(self.previous_modules)
            if modname not in self.previous_modules:
                modpath = getattr(module, '__file__', None)
                if modpath is None:
                    # *module* is a C module that is statically linked into the
                    # interpreter. There is no way to know its path, so we
                    # choose to ignore it.
                    continue
                if not self.is_module_blacklisted(modname, modpath):
                    log.append(modname)
                    del sys.modules[modname]
        if verbose and log:
            print("\x1b[4;33m%s\x1b[24m%s\x1b[0m" % ("UMD has deleted",
                                                     ": " + ", ".join(log)))
760393
def reload_libraries(library_directories: list = None):
    
    directories = library_directories or []
    project = cauldron.project.get_internal_project()
    if project:
        directories += project.library_directories

    if not directories:
        return

    def reload_module(path: str, library_directory: str):
        path = os.path.dirname(path) if path.endswith('__init__.py') else path
        start_index = len(library_directory) + 1
        end_index = -3 if path.endswith('.py') else None
        package_path = path[start_index:end_index]

        module = sys.modules.get(package_path.replace(os.sep, '.'))
        return importlib.reload(module) if module is not None else None

    def reload_library(directory: str) -> list:
        if not add_library_path(directory):
            # If the library wasn't added because it doesn't exist, remove it
            # in case the directory has recently been deleted and then return
            # an empty result
            remove_library_path(directory)
            return []

        glob_path = os.path.join(directory, '**', '*.py')
        return [
            reload_module(path, directory)
            for path in glob.glob(glob_path, recursive=True)
        ]

    return [
        reloaded_module
        for directory in directories
        for reloaded_module in reload_library(directory)
        if reload_module is not None
    ]
698306
def rmmod(module, force=False):
    """"""
    cmd = ['rmmod']
    if force:
        cmd.append('-f')
    cmd.append(module)
    log('Removing kernel module %s' % module, level=INFO)
    return subprocess.check_call(cmd)
1138188
def restore(self):
        
        try:
            for modname, mod in self._saved.items():
                if mod is not None:
                    sys.modules[modname] = mod
                else:
                    try:
                        del sys.modules[modname]
                    except KeyError:
                        pass
        finally:
            imp.release_lock()
1360508
def _check_and_install_python(ret, python, default=False, user=None):
    '''
    
    '''
    ret = _python_installed(ret, python, user=user)
    if not ret['result']:
        if __salt__['pyenv.install_python'](python, runas=user):
            ret['result'] = True
            ret['changes'][python] = 'Installed'
            ret['comment'] = 'Successfully installed python'
            ret['default'] = default
        else:
            ret['result'] = False
            ret['comment'] = 'Could not install python.'
            return ret

    if default:
        __salt__['pyenv.default'](python, runas=user)

    return ret
1335484
def ispymodule(self):
        ''''''
        if self.isdir():
            return os.path.isfile(os.path.join(self, '__init__.py'))
        elif self.isfile():
            return self.endswith('.py')
879821
def reload_including_local(module):
    
    try:
        reload(module)
    except ImportError:
        # This can happen if the module was loaded in the immediate script
        # directory.  Add the service path and try again.
        if not hasattr(cherrypy.thread_data, "modulepath"):
            raise
        path = os.path.abspath(cherrypy.thread_data.modulepath)
        root = os.path.abspath(cherrypy.config.get("webroot"))
        if path not in sys.path and (path == root or path.startswith(root + os.path.sep)):
            oldpath = sys.path
            try:
                sys.path = [path] + sys.path
                reload(module)
            finally:
                sys.path = oldpath
        else:
            raise
61483
def remove_library_from_file_system(self, library_path, library_name):
        """"""
        library_file_system_path = self.get_os_path_to_library(library_path, library_name)[0]
        shutil.rmtree(library_file_system_path)
        self.refresh_libraries()
1092826
def mark_module_reloadable(self, module_name):
        """"""
        try:
            del self.skip_modules[module_name]
        except KeyError:
            pass
        self.modules[module_name] = True
1080097
def unregisterAddonModule(cls, module):
        
        prop = '_{0}__addon_modules'.format(cls.__name__)
        mods = getattr(cls, prop, set())
        try:
            mods.remove(module)
        except KeyError:
            pass
1039385
def clean_python(ctx, dry_run=False):
    """"""
    # MAYBE NOT: "**/__pycache__"
    cleanup_dirs(["build", "dist", "*.egg-info", "**/__pycache__"],
                 dry_run=dry_run)
    if not dry_run:
        ctx.run("py.cleanup")
    cleanup_files(["**/*.pyc", "**/*.pyo", "**/*$py.class"], dry_run=dry_run)
576894
def make_module_reload_func(module_name=None, module_prefix='[???]', module=None):
    
    module = _get_module(module_name, module, register=False)
    if module_name is None:
        module_name = str(module.__name__)
    def rrr(verbose=True):
        """ Dynamic module reloading """
        if not __RELOAD_OK__:
            raise Exception('Reloading has been forced off')
        try:
            import imp
            if verbose and not QUIET:
                builtins.print('RELOAD: ' + str(module_prefix) + ' __name__=' + module_name)
            imp.reload(module)
        except Exception as ex:
            print(ex)
            print('%s Failed to reload' % module_prefix)
            raise
    # this doesn't seem to set anything on import *
    #_inject_funcs(module, rrr)
    return rrr
725140
def restore(self):
        
        sys = set(self._sys_modules.keys())
        for mod_name in sys.difference(self._saved_modules):
            del self._sys_modules[mod_name]
856953
def demote(self):
    
    import sys  # Grab a hold of `sys` early since we'll be un-importing our module in this process.

    unimported_modules = []
    for name, module in reversed(sorted(sys.modules.items())):
      if self.imported_from_bootstrap(module):
        unimported_modules.append(sys.modules.pop(name))

    sys.path[:] = [path for path in sys.path if os.path.realpath(path) != self._realpath]
    sys.path.append(self._sys_path_entry)

    return unimported_modules
686565
def unload_module(self, module_name):
        """"""
        module = self.loaded_modules.get(module_name)
        if not module:
            _log.warning("Ignoring request to unload non-existant module '%s'",
                         module_name)
            return False

        module.stop(reloading=False)
        del self.loaded_modules[module_name]
        self.module_ordering.remove(module_name)
        return True
162345
def _reload_if_necessary(self, env):
        
        try:
            mod = sys.modules[self.provider_module_name]
        except KeyError:
            mod = None
        if (mod is None or \
                mod.provmod_timestamp != os.path.getmtime(self.provid)):
            logger = env.get_logger()
            logger.log_debug("Need to reload provider at %s" % self.provid)

            #first unload the module
            if self.provmod and hasattr(self.provmod, "shutdown"):
                self.provmod.shutdown(env)
            #now reload and reinit module
            try:
                del sys.modules[self.provider_module_name]
            except KeyError:
                pass
            try:
                self._load_provider_source(logger)
                self._init_provider(env)
            except IOError as exc:
                raise pywbem.CIMError(
                    pywbem.CIM_ERR_FAILED,
                    "Error loading provider %s: %s" % (provid, exc))
588238
function(){
		if(shuttingDown == true)
			return;
		modules.logger.log("startup","ISNode System > Loading Non-Critical Modules...");
		var criticalModules = ["isnode-loader", "isnode-mod-daemon", "isnode-mod-logger", "isnode-mod-utilities", "isnode-mod-cli"];
		for (var name in package.dependencies) {
			var modSplit = name.split("-");
			if(criticalModules.indexOf(name) <= -1 && modSplit[2] != "interface" && name.startsWith('isnode')){
				loadModule(name);
			}
		}
		return true;
	}