当前位置: 首页>>代码示例>>Python>>正文


Python ModuleFinder.run_script方法代码示例

本文整理汇总了Python中modulefinder.ModuleFinder.run_script方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleFinder.run_script方法的具体用法?Python ModuleFinder.run_script怎么用?Python ModuleFinder.run_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在modulefinder.ModuleFinder的用法示例。


在下文中一共展示了ModuleFinder.run_script方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: basic_module_find

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:9,代码来源:pyalone.py

示例2: GetImports

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
    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,代码行数:27,代码来源:module_finder.py

示例3: spider

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
    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,代码行数:35,代码来源:importspider.py

示例4: find_failed_imports

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:9,代码来源:gather.py

示例5: add_mocks

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:37,代码来源:module_args.py

示例6: get_python_module_partials

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:61,代码来源:__init__.py

示例7: zip_std_lib

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:59,代码来源:compile.py

示例8: find_failed_imports_by_directory

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:11,代码来源:gather.py

示例9: get_modules

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:12,代码来源:import_parser.py

示例10: patched

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
    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,代码行数:13,代码来源:python.py

示例11: patched

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
 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,代码行数:13,代码来源:python.py

示例12: main

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:14,代码来源:importList.py

示例13: get_dependencies

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
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,代码行数:15,代码来源:reflect.py

示例14: myMethod

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
 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,代码行数:53,代码来源:sandBox.py

示例15: read_config

# 需要导入模块: from modulefinder import ModuleFinder [as 别名]
# 或者: from modulefinder.ModuleFinder import run_script [as 别名]
    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,代码行数:52,代码来源:flow_table_controller.py


注:本文中的modulefinder.ModuleFinder.run_script方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。