Python modulefinder.Module() Examples

The following are 9 code examples of modulefinder.Module(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module modulefinder , or try the search function .
Example #1
Source File: reloader.py    From testplan with Apache License 2.0 6 votes vote down vote up
def import_hook(self, name, caller=None, *args, **kwargs):
        """
        Hook called when ``caller`` imports module ``name``. Store off the
        caller so we can use it later.

        :param name: Name of the module being imported.
        :type name: ``str``
        :param caller: Module object that is importing ``name``.
        :type caller: ``modulefinder.Module``
        :param args: Other args are passed down to
            ``modulefinder.ModuleFinder.import_hook``
        :param kwargs: Other kwargs are passed down to
            ``modulefinder.ModuleFinder.import_hook``
        :return: Return value from ``modulefinder.ModuleFinder.import_hook``
        """
        self._curr_caller = caller
        return modulefinder.ModuleFinder.import_hook(
            self, name, caller, *args, **kwargs
        ) 
Example #2
Source File: importfinder.py    From xed with Apache License 2.0 6 votes vote down vote up
def _get_modules(fn):
    finder = modulefinder.ModuleFinder()
    finder.run_script(fn)
    all = []
    for m in finder.modules.values():
        if not isinstance(m, modulefinder.Module):
            continue
        if not m.__file__:
            continue
        # skip shared object files
        if m.__file__.endswith('.so'):
            continue
        # skip mac system stuff...
        # FIXME: would need to augment with  other OS's system stuff
        if m.__file__.startswith('/Library/Frameworks'):
            continue
        all.append(m)
    return all 
Example #3
Source File: reloader.py    From testplan with Apache License 2.0 5 votes vote down vote up
def import_module(self, *args, **kwargs):
        """
        Called a bit further down the stack when a module is imported. Update
        the internal mapping of module dependencies.

        :param args: all args are passed down to
            ``modulefinder.ModuleFinder.import_module``
        :param kwargs: all kwargs are passed down to
            ``modulefinder.ModuleFinder.import_module``
        :return: Imported module object.
        :rtype: ``modulefinder.Module``
        """
        caller = self._curr_caller
        self._curr_caller = None
        mod = modulefinder.ModuleFinder.import_module(self, *args, **kwargs)

        if (
            (caller is not None)
            and (mod is not None)
            and _has_file(mod)
            and mod not in self._module_deps[caller]
        ):
            self.logger.debug(
                "Adding %(mod)s to %(caller)s's dependencies",
                {"mod": mod.__name__, "caller": caller.__name__},
            )
            self._module_deps[caller].append(mod)

        return mod 
Example #4
Source File: reloader.py    From testplan with Apache License 2.0 5 votes vote down vote up
def _has_file(mod):
    """
    :param mod: Module object. Can be any of the multiple types used to
        represent a module, we just check for a __file__ attribute.
    :type mod: ``Any``
    :return: If given module has a not None __file__ attribute.
    :rtype: ``bool``
    """
    return hasattr(mod, "__file__") and mod.__file__ is not None 
Example #5
Source File: reloader.py    From testplan with Apache License 2.0 5 votes vote down vote up
def _module_filepath(module):
    """
    :param module: Module object - either a module itself of its modulefinder
        proxy.
    :type module: ``Union[module, modulefinder.module]``
    :return: the normalised filepath to a module, or None if it has no __file__
        attribute.
    :rtype: ``Optional[str]``
    """
    if not _has_file(module):
        return None
    ret_path = path_utils.fix_home_prefix(os.path.abspath(module.__file__))
    if ret_path.endswith("c"):
        return ret_path[:-1]
    return ret_path 
Example #6
Source File: eduactiv82exe.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def copy_extensions(self, extensions):
        # Get pygame default font
        pygamedir = os.path.split(pygame.base.__file__)[0]
        pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())

        # Add font to list of extension to be copied
        extensions.append(Module("pygame.font", pygame_default_font))
        py2exe.build_exe.py2exe.copy_extensions(self, extensions) 
Example #7
Source File: pygame2exe.py    From universalSmashSystem with GNU General Public License v3.0 5 votes vote down vote up
def copy_extensions(self, _extensions):
        #Get pygame default font
        pygame_dir = os.path.split(pygame.base.__file__)[0]
        pygame_default_font = os.path.join(pygame_dir, pygame.font.get_default_font())
 
        #Add font to list of extension to be copied
        _extensions.append(Module("pygame.font", pygame_default_font))
        py2exe.build_exe.py2exe.copy_extensions(self, _extensions) 
Example #8
Source File: build.py    From games-in-pygame with GNU General Public License v3.0 5 votes vote down vote up
def copy_extensions(self, extensions):
        #Get pygame default font
        pygamedir = os.path.split(pygame.base.__file__)[0]
        pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())

        #Add font to list of extension to be copied
        extensions.append(Module("pygame.font", pygame_default_font))
        py2exe.build_exe.py2exe.copy_extensions(self, extensions) 
Example #9
Source File: reloader.py    From testplan with Apache License 2.0 4 votes vote down vote up
def _produce_graph(self, mod, processed):
        """
        Recursive function to build a graph of dependencies.

        :param mod: Module to use for the tree root.
        :type mod: ``modulefinder.Module``
        :param processed: List of modules processed so far in this branch, in
            order of processing. Used to avoid infinite recursion in the case
            of circular dependencies.
        :type processed: ``List[modulefinder.Module]``
        :raises RuntimeError: If ``mod`` is in ``processed`` - the calling
            function should ensure it is not asking to process a module that
            has already been processed.
        :return: Root node of dependency graph.
        :rtype: ``_ModuleNode``
        """
        self.logger.debug(
            "Creating node in dependency graph for module %s", mod.__name__
        )

        if mod in processed:
            raise RuntimeError(
                "Module {mod} has already been processed in this branch. "
                "Already processed = {processed}".format(
                    mod=mod.__name__, processed=processed
                )
            )

        # Create a new list of processed modules to avoid mutating the list
        # we were passed.
        new_processed = processed + [mod]

        # If this module has already been processed in another branch, we
        # can short circuit and return the existing node.
        if mod in self._module_nodes:
            return self._module_nodes[mod]

        # Now for the recursive step - produce a sub-graph of the dependencies
        # of each of our dependencies first, then attach each one to the set
        # of dependencies for the current node. Check that each dependency
        # has not already been processed in this branch to avoid circular
        # dependencies causing infinite recursion.
        dependencies = [
            self._produce_graph(mod=dep, processed=new_processed)
            for dep in self._module_deps[mod]
            if dep not in new_processed
        ]
        node = _ModuleNode(mod, dependencies)
        self._module_nodes[mod] = node
        return node