98100abde55f1fb0ab455f95b9259c3adcdbab2c,PyInstaller/building/imphook.py,ImportHook,_process_excludedimports,#ImportHook#Any#,267

Before Change


        not_allowed_references = set(self._module.excludedimports)
        // Remove references between module nodes, as if they are not imported from "name"
        for item in not_allowed_references:
            try:
                excluded_node = mod_graph.findNode(item)
                if excluded_node is not None:
                    logger.info("Excluding import "%s"" % item)

                    safe_to_remove = self._remove_module_references(excluded_node, mod_graph,
                                                                    mod_filter=not_allowed_references)
                    // If no other modules reference the excluded_node then it is safe to remove
                    // all references to excluded_node and its all submodules.
                    // NOTE: Removing references from graph will keep some dead branches that
                    //       are not reachable from the top-level script. But import hoosks
                    //       for modules in dead branches will get processed!
                    // TODO Find out a way to remove unreachable branches in the graph. - Create a new graph object that will be constructed just from the top-level script?
                    if safe_to_remove:
                        submodule_list = set()
                        // First find submodules.
                        for subnode in mod_graph.nodes():
                            if subnode.identifier.startswith(excluded_node.identifier + "."):
                                submodule_list.add(subnode)
                        // Then remove references to those submodules.
                        for mod in submodule_list:
                            mod_referers = mod_graph.getReferers(mod)
                            for mod_ref in mod_referers:
                                mod_graph.removeReference(mod_ref, mod)
                            logger.warn("  Removing import "%s"" % mod.identifier)
                            mod_graph.removeNode(mod)
                        // Remove the parent node itself.
                        logger.warn("  Removing import "%s"" % item)
                        mod_graph.removeNode(excluded_node)

                else:
                    logger.info("Excluded import "%s" not found" % item)
            except ImportError:
                // excludedimport could not be found.
                // modulegraph raises ImporError when a module is not found.
                logger.info("Excluded import "%s" not found" % item)

    def _process_datas(self, mod_graph):
        
        "datas" is a list of globs of files or
        directories to bundle as datafiles. For each

After Change


        targets_to_remove = []
        for item in not_allowed_references:
            excluded_node = mod_graph.findNode(item, create_nspkg=False)
            if excluded_node is None:
                logger.info("Import to be excluded not found: %r", item)
                continue
            logger.info("Excluding import %r", item)
            targets_to_remove.extend(find_all_package_nodes(item))

        // Remove references between module nodes, as though they would
        // not be imported from "name".
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: pyinstaller/pyinstaller
Commit Name: 98100abde55f1fb0ab455f95b9259c3adcdbab2c
Time: 2015-10-19
Author: h.goebel@crazy-compilers.com
File Name: PyInstaller/building/imphook.py
Class Name: ImportHook
Method Name: _process_excludedimports


Project Name: tensorflow/tensorboard
Commit Name: 65f7aa962741a11aa2db3c77ce77efacb1219418
Time: 2018-03-15
Author: nfelt@users.noreply.github.com
File Name: tensorboard/plugins/beholder/beholder.py
Class Name: Beholder
Method Name: _update_recording


Project Name: pantsbuild/pants
Commit Name: fd1456ac36e0a1ebfb800c9593f1540858ca7bea
Time: 2015-07-17
Author: kwilson@twopensource.com
File Name: src/python/pants/backend/core/tasks/reporting_server.py
Class Name: KillServer
Method Name: execute