本文整理汇总了Python中modulefinder.ModuleFinder.add_module方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleFinder.add_module方法的具体用法?Python ModuleFinder.add_module怎么用?Python ModuleFinder.add_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modulefinder.ModuleFinder
的用法示例。
在下文中一共展示了ModuleFinder.add_module方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: packModule
# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import add_module [as 别名]
def packModule(name):
importOrder = []
importOrder = []
finder = ModuleFinder()
old_addModule = finder.add_module
def addModule(fqname):
if fqname.startswith(name):
#print fqname
if fqname not in importOrder:
importOrder.append(fqname)
return old_addModule(fqname)
finder.add_module = addModule
finder.import_module(name, name, None)
# hack for yaml
importOrder = [
'yaml',
'yaml.error',
'yaml.tokens',
'yaml.events',
'yaml.nodes',
'yaml.reader',
'yaml.scanner',
'yaml.composer',
'yaml.constructor',
'yaml.resolver',
'yaml.parser',
'yaml.loader',
'yaml.emitter',
'yaml.serializer',
'yaml.representer',
'yaml.dumper',
]
global template
template += '{0}=types.ModuleType("{0}","None");'.format(name)
template += '{}.__dict__["__builtins__"]=__builtins__;'.format(name)
template += 'sys.modules["{0}"]={0};'.format(name)
for n in importOrder:
if not n.startswith(name):
continue
print 'packing {}'.format(n)
if n == name:
continue
filename = n.replace('.','/')+'.pyc'
modName = filename[len(name)+1:-4]#n.replace('.','_')
template += '{}=types.ModuleType("{}","None");'.format(modName,filename[len(name)+1:-4])
template += '{}.__dict__["__builtins__"]=__builtins__;'.format(modName)
template += '{}.__dict__["{}"]={};'.format(name, filename[len(name)+1:-4], modName)
template += 'sys.modules["{0}"]={0};'.format(modName)
with open(filename, 'rb') as f:
data = f.read()[8:]
template += 'exec marshal.loads({}) in {}.__dict__;'.format(repr(data), modName)
for n in importOrder:
filename = n.replace('.','/')+'.pyc'
modName = filename[len(name)+1:-4]#n.replace('.','_')
if len(modName)>0:
template += 'del {};'.format(modName)
with open(name+'/__init__.pyc', 'rb') as f:
data = f.read()[8:]
template += 'exec marshal.loads({}) in {}.__dict__;'.format(repr(data), name)