本文整理汇总了Python中modulefinder.ModuleFinder类的典型用法代码示例。如果您正苦于以下问题:Python ModuleFinder类的具体用法?Python ModuleFinder怎么用?Python ModuleFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModuleFinder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_mocks
def add_mocks(filename):
gp = mock.patch('ansible.module_utils.basic.get_platform').start()
gp.return_value = 'linux'
module_mock = mock.MagicMock()
mocks = []
for module_class in MODULE_CLASSES:
mocks.append(
mock.patch('ansible.module_utils.basic.AnsibleModule',
new=module_mock)
)
for m in mocks:
p = m.start()
p.side_effect = AnsibleModuleCallError()
finder = ModuleFinder()
try:
finder.run_script(filename)
except:
pass
sys_mock = mock.MagicMock()
sys_mock.__version__ = '0.0.0'
sys_mocks = []
for module, sources in finder.badmodules.items():
if module in sys.modules:
continue
if [s for s in sources if s[:7] in ['ansible', '__main_']]:
parts = module.split('.')
for i in range(len(parts)):
dotted = '.'.join(parts[:i+1])
sys.modules[dotted] = sys_mock
sys_mocks.append(dotted)
return module_mock, mocks, sys_mocks
开发者ID:2-B,项目名称:ansible-testing,代码行数:35,代码来源:module_args.py
示例2: basic_module_find
def basic_module_find(files):
'''Do a basic module find on all files'''
mf = ModuleFinder()
for fname in files:
mf.run_script(fname)
return mf
开发者ID:BackupTheBerlios,项目名称:pyalone-svn,代码行数:7,代码来源:pyalone.py
示例3: __init__
def __init__(self, path=None, debug=0, excludes=[], replace_paths=[], **kwargs):
ModuleFinder.__init__(self, path, debug, excludes, replace_paths)
self.loadedModules = []
self.moduleTypes = kwargs.pop("types", (imp.PY_SOURCE, imp.PY_COMPILED))
开发者ID:sebcourtois,项目名称:pypeline-tool-devkit,代码行数:7,代码来源:sysutils.py
示例4: spider
def spider(self):
print '-' * 40
while len(self.full_path) != 0:
full_path = self.full_path.pop()
self.full_path_discard.append(full_path)
finder = ModuleFinder()
finder.run_script(full_path)
for name, mod in finder.modules.iteritems():
full_path = str(mod.__file__).replace('.', '/')
if full_path not in self.full_path_discard:
if full_path.startswith('/home/alfred/pipline/code/'):
self.result.append(name.replace('.', '/'))
if not full_path.startswith('/home/alfred/pipline/code/U'):
self.full_path.append(full_path)
else:
self.full_path_discard.append(full_path)
names = finder.any_missing()
for name in names:
for folder in self.all_path:
try:
full_path = folder + name + '.py'
if os.path.isfile(full_path):
if full_path not in self.full_path_discard:
self.full_path.append(full_path)
self.result.append(full_path)
except:
pass
for item in sorted(set(self.result)):
print item
print '='*100
开发者ID:ranmx,项目名称:Learning_Python,代码行数:33,代码来源:importspider.py
示例5: GetImports
def GetImports(cls, directory, out_filters=[]):
'''
Lists imports made by python files found in the given directory.
Directory will be scanned recursively
:param str directory:
Path to a directory
:param list(str) out_filters:
List of filename filters
.. see:: FindFiles
:rtype: list(str)
:returns:
List of module imported by python
'''
from ben10.filesystem import FindFiles
from modulefinder import ModuleFinder as Finder
finder = Finder(directory)
for py_filename in FindFiles(directory, in_filters='*.py', out_filters=out_filters):
finder.run_script(py_filename)
return sorted(finder.modules.keys() + finder.badmodules.keys())
开发者ID:nicoddemus,项目名称:ben10,代码行数:25,代码来源:module_finder.py
示例6: find_failed_imports
def find_failed_imports(module_path):
"""Returns all modules that failed to import when loading a particular
module."""
finder = ModuleFinder()
finder.run_script(module_path)
bad_modules = dict(finder.badmodules)
return return_missing_base_modules(bad_modules)
开发者ID:striglia,项目名称:ipyimport,代码行数:7,代码来源:gather.py
示例7: get_python_module_partials
def get_python_module_partials(
pathToModuleFile,
log):
"""
*Get the names of the _partials imported into dryx python modules.*
**Key Arguments:**
- ``pathToModuleFile`` -- the path to the python module we wish to extract the _partial names for
- ``log`` -- logger
**Return:**
- ``partialsDictionary`` -- a dictionary of the _partial names imported into the dryx python module, and a list of their functions
.. todo::
- [ ] when complete, clean get_python_module_partials function & add logging
"""
################ > IMPORTS ################
## STANDARD LIB ##
from modulefinder import ModuleFinder
import re
import os
import sys
## THIRD PARTY ##
## LOCAL APPLICATION ##
log.debug('starting the ``get_python_module_partials`` function')
## VARIABLES ##
partialsDictionary = {}
finder = ModuleFinder()
finder.run_script(pathToModuleFile)
baseName = os.path.basename(pathToModuleFile).replace(".py", "")
if baseName == "__init__":
pathToModuleFile = pathToModuleFile.replace("__init__.py", "")
baseName = os.path.basename(pathToModuleFile)
reBaseName = re.compile(r"%s" % (baseName,))
for name, mod in finder.modules.iteritems():
if reBaseName.search(name):
importList = []
for key in mod.globalnames.keys():
# if ("/Library/Frameworks/Python.framework/" in mod.__file__ or
# "macports" in mod.__file__) and "site-packages" not in
# mod.__file__:
if "/Users/" not in mod.__file__:
# print "skipping %s" % (mod.__file__,)
continue
importList.append(key)
if len(importList):
# print mod.__file__, importList
partialsDictionary[name] = importList
log.debug('completed the ``get_python_module_partials`` function')
return partialsDictionary
开发者ID:thespacedoctor,项目名称:dryxPython,代码行数:59,代码来源:__init__.py
示例8: zip_std_lib
def zip_std_lib(src_module, dst_file):
"""Compiles the Python standard library modules used by the source module
and outputs to zip file."""
finder = ModuleFinder()
finder.run_script(src_module)
modules = set()
print('Writing dependencies to "%s"...' % DEP_OUT)
with open(DEP_OUT, "w") as f:
for name, mod in finder.modules.items():
print("%s: " % name, end="", file=f)
print(mod.__file__, file=f)
if mod.__file__ is None:
continue
path = os.path.realpath(mod.__file__)
if not path.startswith(os.path.normpath(STD_LIB)):
continue
while os.path.dirname(path) != os.path.normpath(STD_LIB):
path = os.path.dirname(path)
if os.path.isfile(path):
modules.add(path)
elif os.path.isdir(path):
for root, dirs, files in os.walk(path):
for i in files:
modules.add(os.path.join(root, i))
print("-" * 50, file=f)
print("### Modules NOT imported ###", file=f)
print("\n".join(finder.badmodules.keys()), file=f)
modules = sorted(
[i for i in modules if i.endswith((".py", ".pyc")) and not os.path.dirname(i).endswith("__pycache__")]
)
print('Writing standard library to "%s"...' % dst_file)
with zipfile.ZipFile(dst_file, "w", compression=zipfile.ZIP_DEFLATED) as z:
for i in modules:
root, ext = os.path.splitext(i)
if ext == ".py":
arcname = os.path.relpath(root, STD_LIB) + ".pyc"
pyc = create_pyc(i)
else:
arcname = os.path.relpath(i, STD_LIB)
with open(i, "rb") as f:
pyc = f.read()
z.writestr(arcname, pyc)
开发者ID:ubuverse,项目名称:embedPython,代码行数:57,代码来源:compile.py
示例9: find_failed_imports_by_directory
def find_failed_imports_by_directory(directory):
"""Returns all modules that failed to import when loading all modules below
a directory."""
finder = ModuleFinder()
py_files = _find_all_python_modules(directory)
for f in py_files:
finder.run_script(f)
bad_modules = dict(finder.badmodules)
return return_missing_base_modules(bad_modules)
开发者ID:striglia,项目名称:ipyimport,代码行数:9,代码来源:gather.py
示例10: get_modules
def get_modules(filename):
finder = ModuleFinder()
finder.run_script(filename)
list_modules = {}
for name,mod in finder.modules.iteritems():
print name,mod
return list_modules
开发者ID:anvisha,项目名称:codelet,代码行数:10,代码来源:import_parser.py
示例11: patched
def patched(self, project_dir, spec, sack):
files = list(project_dir.glob('*.py'))
files.extend(list(project_dir.glob('*/*.py')))
mod = ModuleFinder()
for item in files:
mod.run_script(str(item))
for _, mod in mod.modules.items():
if mod.__file__ and mod.__file__.startswith("/usr/lib"):
spec.required_files.add(mod.__file__)
开发者ID:FLuptak,项目名称:rpg,代码行数:11,代码来源:python.py
示例12: patched
def patched(self, project_dir, spec, sack):
mod = ModuleFinder()
for item in list(project_dir.glob('**/*.py')):
try:
mod.run_script(str(item))
for _, mod in mod.modules.items():
if mod.__file__ and mod.__file__.startswith("/usr/lib"):
spec.required_files.add(mod.__file__)
except ImportError as ie:
logging.warn("Exception was raised by ModuleFinder:\n" +
str(ie) + "\nOn file: " + str(item))
开发者ID:pan0007,项目名称:test,代码行数:11,代码来源:python.py
示例13: main
def main(argv):
path = sys.path[:]
path[0] = os.path.dirname(argv[0])
mf = ModuleFinder(path)
for f in argv:
mf.run_script(f)
paths = sorted(list(set([os.path.abspath(x.__file__) for x in mf.modules.values() if x.__file__])))
cwd = os.getcwd()
paths = [x for x in paths if x.startswith(cwd)]
m = len(cwd) + 1
paths = argv + [x[m:] for x in paths]
print ' '.join(paths)
开发者ID:AwelEshetu,项目名称:cwm,代码行数:12,代码来源:importList.py
示例14: get_dependencies
def get_dependencies(module):
from modulefinder import ModuleFinder
import os
finder = ModuleFinder()
finder.run_script(module)
all_module_paths = [os.path.abspath(m.__file__) for
m in finder.modules.values() if m.__file__ is not None]
def is_in_same_path(p):
return p and os.path.dirname(p).startswith(os.path.dirname(module))
return [x for x in all_module_paths if is_in_same_path(x) and x != module]
开发者ID:atilaneves,项目名称:reggae-python,代码行数:13,代码来源:reflect.py
示例15: myMethod
def myMethod(self):
finder = ModuleFinder()
myDrive = "g:\\"
mySrcPath = "git\\6700Spring16\\CA05\\submissions\\danieljames_1246453_74826857_jhd0008\\softwareProcess\\SoftwareProcess\\Assignment\\prod"
myPath = "git\\6700Spring16\\CA05\\submissions\\danieljames_1246453_74826857_jhd0008\\softwareProcess\\SoftwareProcess\\Assignment\\test"
#myPath = "git\\6700Spring16\\CA05\\submissions"
scriptname = myDrive+myPath+'\\FixTest.py'
with io.open(scriptname) as scriptfile:
code = compile(scriptfile.readall(),scriptname,'exec')
mod = importlib.import_module('FixTest',package="Assignment")
print 'Inspect output:'
for i in inspect.getmembers((mod, inspect.ismodule)):
print i[0]
for root, myDir, files in os.walk(myDrive + myPath):
for myFile in files:
print myFile
sys.path.insert(0,os.path.join(myDrive+myPath))
print sys.path
finder.run_script(os.path.join(myDrive+mySrcPath+'\\Fix.py'))
print 'Loaded modules:'
for name, mod in finder.modules.iteritems():
print '%s: ' % name,
print ','.join(mod.globalnames.keys()[:3])
runpy.run_path(os.path.join(myDrive,myPath,'FixTest.py'))
__all__ = []
module_name = None
for loader, module_name, is_pkg in pkgutil.walk_packages("g:\\"):
print 'in for loop'
#__all__.append(module_name)
#module = loader.find_module(module_name).load_module(module_name)
print 'Found submodule %s ' % module_name
print module_name
'''
src_data = pkgutil.get_data('Assignment.prod',"Fix.py")
if src_data == None:
print "No source data"
else:
print src_data
#mod = loader.load_module(myDrive+myPath+"Fix.py")
myString = "diff --git a/rtb0006/CA01/prod/__init__.pyc b/rtb0006/CA01/prod/__init__.pyc"
testSuite = TestLoader().discover("g:\\git\\6700Spring16\\CA05\\submissions\\danieljames_1246453_74826857_jhd0008\\softwareProcess\\SoftwareProcess\\Assignment\\test", pattern="*.py")
ImpImporter("g:\\git\\6700Spring16\\CA05\\submissions\\danieljames_1246453_74826857_jhd00085\\softwareProcess\\SoftwareProcess\\Assignment\\prod")
print testSuite.countTestCases()
for p in sys.path:
print p
result = TextTestRunner().run(testSuite)
print result.testsRun
'''
'''
开发者ID:sah0017,项目名称:TDDGitLogAnalysisCode,代码行数:51,代码来源:sandBox.py
示例16: read_config
def read_config(self):
"""
We have to split modules by apps.
We use ModuleFinder to get all imports from module.
Than we select those not starting with "/usr".
"""
self.apps = {}
self.apps_rev = {}
if (self.config is None or
not isinstance(self.config, basestring)):
return
finder = ModuleFinder()
# map: app -> modules
apps = None
with open(self.config, 'r') as f:
apps = json.load(f)
if apps is None:
log.debug("Apps are empty. Try setting modules in config: %s" % (
self.config))
f.close()
i = 0
if not isinstance(apps, list):
return
for t in apps:
if not isinstance(t, list):
continue
self.apps[i] = set()
for module in t:
if not isinstance(module, basestring):
continue
self.apps[i].add(module)
try:
finder.run_script(module)
modules = [m.__file__.replace('.pyo', '.py')
for m in finder.modules.values()
if (hasattr(m, "__file__") and
isinstance(m.__file__, basestring) and
not m.__file__.startswith('/usr'))]
self.apps[i].update(modules)
except Exception as e:
log.debug(str(e))
i += 1
# Reverse map: module -> apps
for i, modules in self.apps.items():
for module in modules:
if module not in self.apps_rev:
self.apps_rev[module] = set()
self.apps_rev[module].add(i)
开发者ID:ARCCN,项目名称:elt,代码行数:50,代码来源:flow_table_controller.py
示例17: get_submodules
def get_submodules(package):
"""Find names of all modules in `package`
Parameters
----------
package : imported Python package
Returns
-------
list
Sorted list of fully-qualified module names
"""
mf = ModuleFinder()
modules = sorted(["%s.%s" % (package.__name__,X) for X in mf.find_all_submodules(package) if X != "__init__"])
return modules
开发者ID:Lemma1,项目名称:MINAMI,代码行数:16,代码来源:make_table.py
示例18: _analyze_file_deps
def _analyze_file_deps(build_zip_descriptor, file_to_analyze):
"""
Returns a path normalized list of files a file given by file_to_analyze
depends upon.
"""
mf = ModuleFinder(excludes=build_zip_descriptor.exclude_modules)
mf.run_script(file_to_analyze)
file_list = [ ]
for module_name in mf.modules.keys():
module_file = mf.modules[module_name].__file__
if not module_file:
continue
file_list.append(os.path.abspath(module_file))
return file_list
开发者ID:digidotcom,项目名称:xbgw-app,代码行数:16,代码来源:build_zip.py
示例19: main
def main():
description="Convenience script to generate HTML documentation using pydoc"
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--out', required=True, metavar="PATH",
help="Directory in which to write HTML output files.")
parser.add_argument('--recursive', action='store_true', default=False,
help="Recursively import documentation for dependencies. If not recursive, zcall documents will contain broken links to standard modules. Recursive mode generates approximately 180 HTML files comprising 6 MB of data.")
parser.add_argument('--verbose', action='store_true', default=False,
help="Write pydoc information to stdout.")
args = vars(parser.parse_args())
recursive = args['recursive']
verbose = args['verbose']
if not verbose: # suppress stdout chatter from pydoc.writedoc
sys.stdout = open('/dev/null', 'w')
localDir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.abspath(localDir+"/..")) # import from zcall dir
zcallDir = os.path.abspath(localDir+"/../zcall")
outDir = os.path.abspath(args['out'])
if not (os.access(outDir, os.W_OK) and os.path.isdir(outDir)):
msg = "ERROR: Output path "+outDir+" is not a writable directory.\n"
sys.stderr.write(msg)
sys.exit(1)
os.chdir(outDir)
import zcall
pydoc.writedoc(zcall)
modules = set()
zcall = set()
scripts = []
mf = ModuleFinder()
for script in os.listdir(zcallDir):
if re.search("\.py$", script) and script!="__init__.py":
words = re.split("\.", script)
words.pop()
scriptName = (".".join(words)) # name without .py suffix
modules.add("zcall."+scriptName)
zcall.add(scriptName)
scripts.append(script)
if recursive:
for script in scripts:
mf.run_script(os.path.join(zcallDir, script))
for name, mod in mf.modules.iteritems():
if name not in zcall: modules.add(name)
for module in modules:
pydoc.writedoc(import_module(module))
开发者ID:wtsi-npg,项目名称:zCall,代码行数:46,代码来源:createDocs.py
示例20: import_module
def import_module( self, partnam, fqname, parent ):
depth = self._depth
if depth is None or len( self._callerStack ) <= depth:
r = ModuleFinder.import_module( self, partnam, fqname, parent )
if r is not None:
self._depNode.addDepedency( self._callerStack +[ r.__file__ ] )
return r
开发者ID:BGCX261,项目名称:zootoolbox-svn-to-git,代码行数:8,代码来源:dependencies.py
注:本文中的modulefinder.ModuleFinder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论