当前位置: 首页>>代码示例>>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方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: has_tag

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
    def has_tag(modname, fullname, docname, refname):
        entry = env._viewcode_modules.get(modname, None)  # type: ignore
        if entry is False:
            return

        code_tags = app.emit_firstresult('viewcode-find-source', modname)
        if code_tags is None:
            try:
                analyzer = ModuleAnalyzer.for_module(modname)
            except Exception:
                env._viewcode_modules[modname] = False  # type: ignore
                return

            if not isinstance(analyzer.code, text_type):
                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, {}, refname
            env._viewcode_modules[modname] = entry  # type: ignore
        _, tags, used, _ = entry
        if fullname in tags:
            used[fullname] = docname
            return True
开发者ID:sam-m888,项目名称:sphinx,代码行数:32,代码来源:viewcode.py

示例2: recurse

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
        def recurse(cls):
            if not show_builtins and cls in py_builtins:
                return
            if not private_bases and cls.__name__.startswith('_'):
                return

            nodename = self.class_name(cls, parts)
            fullname = self.class_name(cls, 0)

            # Use first line of docstring as tooltip, if available
            tooltip = None
            try:
                if cls.__doc__:
                    enc = ModuleAnalyzer.for_module(cls.__module__).encoding
                    doc = cls.__doc__.strip().split("\n")[0]
                    if not isinstance(doc, text_type):
                        doc = force_decode(doc, enc)
                    if doc:
                        tooltip = '"%s"' % doc.replace('"', '\\"')
            except Exception:  # might raise AttributeError for strange classes
                pass

            baselist = []
            all_classes[cls] = (nodename, fullname, baselist, tooltip)
            for base in cls.__bases__:
                if not show_builtins and base in py_builtins:
                    continue
                if not private_bases and base.__name__.startswith('_'):
                    continue
                baselist.append(self.class_name(base, parts))
                if base not in all_classes:
                    recurse(base)
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:34,代码来源:inheritance_diagram.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.split('.')
                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, 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, path, docstring):
                yield line
开发者ID:superduper,项目名称:sphinxcontrib-httpdomain,代码行数:37,代码来源:flask.py

示例4: inspect_routes

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
    def inspect_routes(self, app):
        """Inspects the views of Flask.

        :param app: The Flask application.
        :returns: 4-tuple like ``(method, paths, view_func, view_doc)``
        """
        if self.endpoints:
            routes = itertools.chain(*[get_routes(app, endpoint, self.order)
                                       for endpoint in self.endpoints])
        else:
            routes = get_routes(app, order=self.order)

        for method, paths, endpoint in routes:
            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]

            if self.modules and view.__module__ not in self.modules:
                continue

            if self.undoc_modules and view.__module__ in self.modules:
                continue

            view_class = getattr(view, 'view_class', None)
            if view_class is None:
                view_func = view
            else:
                view_func = getattr(view_class, method.lower(), None)

            view_doc = view.__doc__ or ''
            if view_func and view_func.__doc__:
                view_doc = view_func.__doc__

            if not isinstance(view_doc, six.text_type):
                analyzer = ModuleAnalyzer.for_module(view.__module__)
                view_doc = force_decode(view_doc, analyzer.encoding)

            if not view_doc and 'include-empty-docstring' not in self.options:
                continue

            yield (method, paths, view_func, view_doc)
开发者ID:Lemma1,项目名称:MINAMI,代码行数:60,代码来源:flask_base.py

示例5: test_ModuleAnalyzer_for_module_in_egg

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def test_ModuleAnalyzer_for_module_in_egg(rootdir):
    try:
        path = rootdir / 'test-pycode-egg' / 'sample-0.0.0-py3.7.egg'
        sys.path.insert(0, path)

        analyzer = ModuleAnalyzer.for_module('sample')
        docs = analyzer.find_attr_docs()
        assert docs == {('', 'CONSTANT'): ['constant on sample.py', '']}
    finally:
        sys.path.pop(0)
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:12,代码来源:test_pycode.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:azizadnan,项目名称:build-relengapi,代码行数:12,代码来源:apidoc.py

示例7: _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
            elif hasattr(self, 'name') and self.name:
                # This is a class: Use its name to make sure Sphinx can find
                # the methods and attributes
                prefix = '%s.' % (self.name)
            else:
                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:vipuldivyanshu92,项目名称:brian2,代码行数:57,代码来源:docscrape_sphinx.py

示例8: parse_override_docs

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
def parse_override_docs(namespace, version):
    import_namespace(namespace, version)

    try:
        ma = ModuleAnalyzer.for_module("pgi.overrides.%s" % namespace)
    except PycodeError:
        return {}
    docs = {}
    for key, value in ma.find_attr_docs().iteritems():
        docs[namespace + "." + ".".join(filter(None, key))] = "\n".join(value)
    return docs
开发者ID:gbtami,项目名称:pgi-docgen,代码行数:13,代码来源:repo.py

示例9: 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
                                analyzer.find_attr_docs().keys()
                                if class_name == self._cls.__name__])
        class_members = set([name for name, func in getattr(self._cls, '__dict__').iteritems()
                             if not name.startswith('_') and (func is None or
                                                              inspect.isdatadescriptor(func))])

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

示例10: make_rst

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
    def make_rst(self, qref=False):
        app = import_object(self.arguments[0])
        if self.endpoints:
            routes = itertools.chain(*[get_routes(app, endpoint, self.order)
                    for endpoint in self.endpoints])
        else:
            routes = get_routes(app, order=self.order)
        for method, paths, endpoint in routes:
            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]

            if self.modules and view.__module__ not in self.modules:
                continue

            if self.undoc_modules and view.__module__ in self.modules:
                continue

            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)
            if qref == True:
                for path in paths:
                    row = quickref_directive(method, path, docstring)
                    yield row
            else:
                for line in http_directive(method, paths, docstring):
                    yield line
开发者ID:elcojacobs,项目名称:sphinx-contrib,代码行数:55,代码来源:flask_base.py

示例11: get_iattributes

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
 def get_iattributes(obj):
     items = []
     name = obj.__name__
     obj_attr = dir(obj)
     analyzer = ModuleAnalyzer.for_module(obj.__module__)
     attr_docs = analyzer.find_attr_docs()
     for pair, doc in attr_docs.iteritems():
         if name!=pair[0]:
             continue
         if not pair[1] in obj_attr:
             items.append({"name":pair[1],
                           "doc":'\n   '.join(doc)})
     items.sort(key=lambda d: d["name"]) 
     return items
开发者ID:Benrflanders,项目名称:Pytris,代码行数:16,代码来源:generate.py

示例12: has_tag

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
 def has_tag(modname, fullname, docname):
     entry = env._viewcode_modules.get(modname, None)
     if entry is None:
         try:
             analyzer = ModuleAnalyzer.for_module(modname)
         except Exception:
             env._viewcode_modules[modname] = False
             return
         analyzer.find_tags()
         entry = analyzer.code.decode(analyzer.encoding), analyzer.tags, {}
         env._viewcode_modules[modname] = entry
     elif entry is False:
         return
     code, tags, used = entry
     if fullname in tags:
         used[fullname] = docname
         return True
开发者ID:hurtado452,项目名称:battleAtSea-master,代码行数:19,代码来源:viewcode.py

示例13: 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:hirobert,项目名称:sphinxcontrib-httpdomain,代码行数:20,代码来源:bottle.py

示例14: 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 for
        its 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:
            self.env.app.debug('[autodoc] module analyzer failed: %s', 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:aaditya-thakkar,项目名称:sage,代码行数:45,代码来源:sage_autodoc.py

示例15: has_tag

# 需要导入模块: from sphinx.pycode import ModuleAnalyzer [as 别名]
# 或者: from sphinx.pycode.ModuleAnalyzer import for_module [as 别名]
 def has_tag(modname, fullname, docname, refname):
     entry = env._viewcode_modules.get(modname, None)
     if entry is None:
         try:
             analyzer = ModuleAnalyzer.for_module(modname)
         except Exception:
             env._viewcode_modules[modname] = False
             return
         analyzer.find_tags()
         if not isinstance(analyzer.code, text_type):
             code = analyzer.code.decode(analyzer.encoding)
         else:
             code = analyzer.code
         entry = code, analyzer.tags, {}, refname
         env._viewcode_modules[modname] = entry
     elif entry is False:
         return
     _, tags, used, _ = entry
     if fullname in tags:
         used[fullname] = docname
         return True
开发者ID:Punyaslok,项目名称:astropy-helpers,代码行数:23,代码来源:viewcode.py


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