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


Python ModuleAnalyzer.for_module方法代码示例

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


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

示例1: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self):
        app = import_object(self.arguments[0])
        for method, path, target in get_routes(app):
            endpoint = target.name or target.callback.__name__
            if self.endpoints and endpoint not in self.endpoints:
                continue
            if endpoint in self.undoc_endpoints:
                continue
            view = target.callback
            docstring = view.__doc__ or ''
            if not isinstance(docstring, six.text_type):
                analyzer = ModuleAnalyzer.for_module(view.__module__)
                docstring = force_decode(docstring, analyzer.encoding)
            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            docstring = prepare_docstring(docstring)
            for line in http_directive(method, path, docstring):
                yield line 
开发者ID:preems,项目名称:nltk-server,代码行数:20,代码来源:bottle.py

示例2: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self):
        app = import_object(self.arguments[0])
        for method, path, handler in get_routes(app):
            class_name = handler.__name__
            method_name = getattr(handler, method).__name__
            endpoint = '.'.join((class_name, method_name))

            if self.endpoints and endpoint not in self.endpoints:
                continue
            if endpoint in self.undoc_endpoints:
                continue

            docstring = getattr(handler, method).__doc__ or ''
            #if not isinstance(docstring, unicode):
            #    analyzer = ModuleAnalyzer.for_module(view.__module__)
            #    docstring = force_decode(docstring, analyzer.encoding)
            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            docstring = prepare_docstring(docstring)
            for line in http_directive(method, normalize_path(path), docstring):
                yield line 
开发者ID:preems,项目名称:nltk-server,代码行数:23,代码来源:tornado.py

示例3: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self):
        app = import_object(self.arguments[0])
        for method, path, endpoint in get_routes(app):
            try:
                blueprint, _, endpoint_internal = endpoint.rpartition('.')
                if self.blueprints and blueprint not in self.blueprints:
                    continue
                if blueprint in self.undoc_blueprints:
                    continue
            except ValueError:
                pass  # endpoint is not within a blueprint

            if self.endpoints and endpoint not in self.endpoints:
                continue
            if endpoint in self.undoc_endpoints:
                continue
            try:
                static_url_path = app.static_url_path # Flask 0.7 or higher
            except AttributeError:
                static_url_path = app.static_path # Flask 0.6 or under
            if ('undoc-static' in self.options and endpoint == 'static' and
                path == static_url_path + '/(path:filename)'):
                continue
            view = app.view_functions[endpoint]
            docstring = view.__doc__ or ''
            if hasattr(view, 'view_class'):
                meth_func = getattr(view.view_class, method.lower(), None)
                if meth_func and meth_func.__doc__:
                    docstring = meth_func.__doc__
            if not isinstance(docstring, six.text_type):
                analyzer = ModuleAnalyzer.for_module(view.__module__)
                docstring = force_decode(docstring, analyzer.encoding)
    
            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            docstring = prepare_docstring(docstring)
            for line in http_directive(method, path, docstring):
                yield line 
开发者ID:preems,项目名称:nltk-server,代码行数:40,代码来源:flask.py

示例4: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self, section_title_set):
        # print('importing falcon app %s...' % self.arguments[0])
        app = autohttp_import_object(self.arguments[0])
        for method, path, handler in get_routes(app):
            docstring = handler.__doc__
            if not isinstance(docstring, str):
                analyzer = ModuleAnalyzer.for_module(handler.__module__)
                docstring = force_decode(docstring, analyzer.encoding)
            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            # exclude falcon HTTPMethodNotAllowed endpoints
            if docstring == 'Raise 405 HTTPMethodNotAllowed error':
                continue
            if not docstring:
                continue
            if hasattr(handler, '__self__'):
                if not (handler.__self__.allow_read_no_auth and method == 'GET'):
                    docstring += '\n:reqheader Authorization: see :ref:`hmac-auth-label`.\n'

            docstring = prepare_docstring(docstring)

            # generate section title if needed
            if path.startswith('/v'):
                section_title = '/'.join(path.split('/')[0:3])
            else:
                section_title = path
            if section_title not in section_title_set:
                section_title_set.add(section_title)
                yield section_title
                yield '_' * len(section_title)

            for line in autohttp_http_directive(method, path, docstring):
                yield line 
开发者ID:linkedin,项目名称:iris,代码行数:35,代码来源:sphinx_extension.py

示例5: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self, section_title_set):
        # print('importing falcon app %s...' % self.arguments[0])
        app = autohttp_import_object(self.arguments[0])
        for method, path, handler in get_routes(app):
            docstring = handler.__doc__
            if not isinstance(docstring, str):
                analyzer = ModuleAnalyzer.for_module(handler.__module__)
                docstring = force_decode(docstring, analyzer.encoding)
            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            if not docstring:
                continue
            docstring = prepare_docstring(docstring)

            # generate section title if needed
            if path.startswith('/api'):
                section_title = '/'.join(path.split('/')[0:4])
            else:
                section_title = path
            if section_title not in section_title_set:
                section_title_set.add(section_title)
                yield section_title
                yield '_' * len(section_title)

            for line in autohttp_http_directive(method, path, docstring):
                yield line 
开发者ID:linkedin,项目名称:oncall,代码行数:28,代码来源:sphinx_extension.py

示例6: get_attr_docs

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def get_attr_docs(self, ty):
        # this reaches into some undocumented stuff in sphinx to
        # extract the attribute documentation.
        analyzer = ModuleAnalyzer.for_module(ty.__module__)
        module_attrs = analyzer.find_attr_docs()  # (scope is broken!)
        # Make sure we can split lines for type docs on long lines
        attrs_docs = {}
        for k, v in module_attrs.iteritems():
            attrs_docs[k[1]] = "\n".join(v).strip()
        return attrs_docs 
开发者ID:mozilla,项目名称:build-relengapi,代码行数:12,代码来源:apidoc.py

示例7: properties

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def properties(self):
        if self._cls is None:
            return []
        analyzer = ModuleAnalyzer.for_module(self._cls.__module__)
        instance_members = set([attr_name for (class_name, attr_name) in
                                iterkeys(analyzer.find_attr_docs())
                                if class_name == self._cls.__name__])
        class_members = set([name for name, func in iteritems(getattr(self._cls, '__dict__'))
                             if not name.startswith('_') and (func is None or
                                                              inspect.isdatadescriptor(func))])

        return instance_members | class_members 
开发者ID:brian-team,项目名称:brian2genn,代码行数:14,代码来源:docscrape.py

示例8: register_source

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def register_source(app, env, modname):
    """
    Registers source code.

    :param app: application
    :param env: environment of the plugin
    :param modname: name of the module to load
    :return: True if the code is registered successfully, False otherwise
    """
    entry = env._viewcode_modules.get(modname, None)  # type: ignore
    if entry is False:
        print("[%s] Entry is false for " % modname)
        return False

    code_tags = app.emit_firstresult("viewcode-find-source", modname)
    if code_tags is None:
        # noinspection PyBroadException
        try:
            analyzer = ModuleAnalyzer.for_module(modname)
        except Exception as ex:  # pylint: disable=broad-except
            logger.info("Module \"%s\" could not be loaded. Full source will not be available. \"%s\"",
                        modname, ex)
            env._viewcode_modules[modname] = False  # type: ignore
            return False

        if not isinstance(analyzer.code, str):
            code = analyzer.code.decode(analyzer.encoding)
        else:
            code = analyzer.code

        analyzer.find_tags()
        tags = analyzer.tags

    else:
        code, tags = code_tags

    if entry is None or entry[0] != code:
        entry = code, tags, {}, ""
        env._viewcode_modules[modname] = entry  # type: ignore

    return True
# pylint: enable=protected-access 
开发者ID:apache,项目名称:airflow,代码行数:44,代码来源:exampleinclude.py

示例9: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def make_rst(self):
        app = import_object(self.arguments[0])
        if self.endpoints:
            routes = itertools.chain(*[get_routes(app, endpoint)
                                     for endpoint in self.endpoints])
        else:
            routes = get_routes(app)

        for method, paths, endpoint in routes:
            if not self.check_regex_validate_path(paths):
                continue
            if self.check_regex_cancel_path(paths):
                continue
            try:
                blueprint, _, endpoint_internal = endpoint.rpartition('.')
                if self.blueprints and blueprint not in self.blueprints:
                    continue
                if blueprint in self.undoc_blueprints:
                    continue
            except ValueError:
                pass  # endpoint is not within a blueprint

            if endpoint in self.undoc_endpoints:
                continue
            try:
                static_url_path = app.static_url_path  # Flask 0.7 or higher
            except AttributeError:
                static_url_path = app.static_path  # Flask 0.6 or under
            if ('undoc-static' in self.options and endpoint == 'static' and
                    static_url_path + '/(path:filename)' in paths):
                continue
            view = app.view_functions[endpoint]
            docstring = view.__doc__ or ''
            if hasattr(view, 'view_class'):
                meth_func = getattr(view.view_class, method.lower(), None)
                if meth_func and meth_func.__doc__:
                    docstring = meth_func.__doc__
            if not isinstance(docstring, six.text_type):
                analyzer = ModuleAnalyzer.for_module(view.__module__)
                docstring = force_decode(docstring, analyzer.encoding)

            if not docstring and 'include-empty-docstring' not in self.options:
                continue
            docstring = prepare_docstring(docstring)
            for line in http_directive(method, paths, docstring):
                yield line 
开发者ID:ovh,项目名称:ip-reputation-monitoring,代码行数:48,代码来源:extended_autohttp_flask.py

示例10: generate

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def generate(self, more_content=None, real_modname=None,
                 check_module=False, all_members=False):
        """
        Generate reST for the object given by *self.name*, and possibly members.

        If *more_content* is given, include that content. If *real_modname* is
        given, use that module name to find attribute docs. If *check_module* is
        True, only generate if the object is defined in the module name it is
        imported from. If *all_members* is True, document all members.
        """
        if not self.parse_name():
            # need a module to import
            self.directive.warn(
                'don\'t know which module to import for autodocumenting '
                '%r (try placing a "module" or "currentmodule" directive '
                'in the document, or giving an explicit module name)'
                % self.name)
            return

        # now, import the module and get object to document
        if not self.import_object():
            return

        # If there is no real module defined, figure out which to use.
        # The real module is used in the module analyzer to look up the module
        # where the attribute documentation would actually be found in.
        # This is used for situations where you have a module that collects the
        # functions and classes of internal submodules.
        self.real_modname = real_modname or self.get_real_modname()

        # try to also get a source code analyzer for attribute docs
        try:
            self.analyzer = ModuleAnalyzer.for_module(self.real_modname)
            # parse right now, to get PycodeErrors on parsing (results will
            # be cached anyway)
            self.analyzer.find_attr_docs()
        except PycodeError, err:
            # no source file -- e.g. for builtin and C modules
            self.analyzer = None
            # at least add the module.__file__ as a dependency
            if hasattr(self.module, '__file__') and self.module.__file__:
                self.directive.filename_set.add(self.module.__file__) 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:44,代码来源:sage_autodoc.py

示例11: run

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def run(self):
        module_name = str(self.arguments[0])
        module = importlib.import_module(module_name)

        analyzer = ModuleAnalyzer.for_module(module_name)
        attr_docs = analyzer.find_attr_docs()

        with open(module.__file__) as module_file:
            symbols = symtable.symtable(module_file.read(), module.__file__, "exec")

        members = []

        for name in dir(module):
            member = getattr(module, name)

            # Ignore private members
            if name.startswith("_"):
                continue

            # Ignore imported modules
            if isinstance(member, types.ModuleType):
                continue

            # Ignore members imported from other modules
            member_module_name = getattr(member, "__module__", None)
            if member_module_name is None:
                try:
                    if symbols.lookup(name).is_imported():
                        continue
                except KeyError:
                    continue
            else:
                if member_module_name != module_name:
                    continue

            documenter = get_documenter(self.env.app, member, module)

            # Ignore data items that do not have docstrings
            if documenter.objtype == "data" and ("", name) not in attr_docs:
                continue

            members.append(name)

        # Sort members in the order they appear in source code
        tagorder = analyzer.tagorder
        members.sort(key=lambda name: tagorder.get(name, len(tagorder)))

        self.content = [f"{module_name}.{member}" for member in members]

        return super().run() 
开发者ID:broadinstitute,项目名称:gnomad_methods,代码行数:52,代码来源:directives.py

示例12: _str_member_list

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def _str_member_list(self):
        """
        Generate a member listing, autosummary:: table .

        """
        out = []

        
        
        for name in ['Attributes', 'Methods']:
            if not self[name]:
                continue
            
            out += ['.. rubric:: %s' % name, '']
            prefix = getattr(self, '_name', '')

            if prefix:
                prefix = '%s.' % prefix

            autosum = []
            for param, _, desc in self[name]:
                param = param.strip()
                if self._obj:
                    # Fake the attribute as a class property, but do not touch
                    # methods
                    if (hasattr(self._obj, '__module__') and not 
                        (hasattr(self._obj, param) and callable(getattr(self._obj, param)))):

                        # Do not override directly provided docstrings
                        if not len(''.join(desc).strip()):
                            analyzer = ModuleAnalyzer.for_module(self._obj.__module__)
                            desc = analyzer.find_attr_docs().get((self._obj.__name__, param), '')
                            
                        # Only fake a property if we got a docstring
                        if len(''.join(desc).strip()):
                            setattr(self._obj, param, property(lambda self: None,
                                                               doc='\n'.join(desc)))

                if len(prefix):
                    autosum += ["   ~%s%s" % (prefix, param)]
                else:
                    autosum += ["   %s" % param]

            if autosum:
                out += ['.. autosummary::', '']
                out += autosum
            
            out += ['']
        return out 
开发者ID:brian-team,项目名称:brian2genn,代码行数:51,代码来源:docscrape_sphinx.py


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