本文整理汇总了Python中modulefinder.Module方法的典型用法代码示例。如果您正苦于以下问题:Python modulefinder.Module方法的具体用法?Python modulefinder.Module怎么用?Python modulefinder.Module使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modulefinder
的用法示例。
在下文中一共展示了modulefinder.Module方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_hook
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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
)
示例2: _get_modules
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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
示例3: import_module
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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
示例4: _has_file
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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
示例5: _module_filepath
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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
示例6: copy_extensions
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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)
示例7: copy_extensions
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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)
示例8: copy_extensions
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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)
示例9: _produce_graph
# 需要导入模块: import modulefinder [as 别名]
# 或者: from modulefinder import Module [as 别名]
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