當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。