Python sphinx.addnodes 模块,desc_name() 实例源码

我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用sphinx.addnodes.desc_name()

项目:rscfl    作者:lc525    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        print("looking for: " + sig)
        cache = _APP_CACHES.get(self.env.app, {})
        key = CursorKind.FUNCTION_DECL, (sig, )
        if key in cache:
            print("KEY FOunD!")
            node, comment, start, end, _ = cache[key]

            result_type = node.type.get_result()
            signode += addnodes.desc_type(result_type.spelling, result_type.spelling + ' ')
            signode += addnodes.desc_name(node.spelling, node.spelling)
            paramlist = addnodes.desc_parameterlist()
            for argument in node.get_arguments():
                parameter = addnodes.desc_parameter()
                parameter += addnodes.desc_type(argument.type.spelling, argument.type.spelling + ' ')
                parameter += nodes.Text(argument.spelling, argument.spelling)
                paramlist += parameter
            signode += paramlist

            self.content = ViewList()
            comment = ''.join(comment)
            for lineno, line in enumerate(comment.splitlines(), start[0]):
                self.content.append(line, '<unknown>', lineno)
        return sig
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def describe_signature(self, signode, mode, env, prefix, parentScope):
        _verify_description_mode(mode)
        if mode == 'markType':
            targetText = prefix + text_type(self)
            pnode = addnodes.pending_xref(
                '', refdomain='cpp', reftype='type',
                reftarget=targetText, modname=None, classname=None)
            pnode['cpp:parent'] = [parentScope]
            pnode += nodes.Text(text_type(self.identifier))
            signode += pnode
        elif mode == 'lastIsName':
            name = text_type(self.identifier)
            signode += addnodes.desc_name(name, name)
        else:
            raise Exception('Unknown description mode: %s' % mode)
        if self.templateArgs:
            signode += nodes.Text('<')
            first = True
            for a in self.templateArgs:
                if not first:
                    signode += nodes.Text(', ')
                first = False
                a.describe_signature(signode, 'markType', env,
                                     parentScope=parentScope)
            signode += nodes.Text('>')
项目:everett    作者:willkg    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        if sig != 'Configuration':
            # Add "component" to the beginning if it's a specific component
            signode.clear()

            # Add "component" which is the type of this thing
            signode += addnodes.desc_annotation('component ', 'component ')

            if '.' in sig:
                modname, clsname = sig.rsplit('.', 1)
            else:
                modname, clsname = '', sig

            # If there's a module name, then we add the module
            if modname:
                signode += addnodes.desc_addname(modname + '.', modname + '.')

            # Add the class name
            signode += addnodes.desc_name(clsname, clsname)
        else:
            # Add just "Configuration"
            signode += addnodes.desc_name(sig, sig)

        return sig
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        path = self.get_display_path()
        signode['is_multiline'] = True
        line = addnodes.desc_signature_line()
        line['add_permalink'] = True
        for x in path:
            line += addnodes.desc_addname(x + '.', x + '.')
        line += addnodes.desc_name(sig, sig)
        if 'required' in self.options:
            line += addnodes.desc_annotation(' (required)', ' (required)')
        signode += line
        if 'default' in self.options:
            line = addnodes.desc_signature_line()
            line += addnodes.desc_type('Default: ', 'Default: ')
            line += nodes.literal(self.options['default'],
                                  self.options['default'])
            signode += line
        return sig
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        if 'hidden' in self.options:
            return sig
        path = self.get_display_path()
        for x in path:
            signode += addnodes.desc_addname(x + '.', x + '.')
        signode += addnodes.desc_name(sig, sig)
        if 'type' in self.options:
            t = ' (%s)' % self.options['type']
            signode += addnodes.desc_annotation(t, t)
        return sig


######################################################################
#
# Autodoc directives
#
项目:docs    作者:hasura    | 项目源码 | 文件源码
def parse_django_admin_node(env, sig, signode):
    command = sig.split(' ')[0]
    env.ref_context['std:program'] = command
    title = "django-admin %s" % sig
    signode += addnodes.desc_name(title, title)
    return command
项目:rscfl    作者:lc525    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        cache = _APP_CACHES.get(self.env.app, {})
        key = CursorKind.MACRO_DEFINITION, (sig, )
        if key in cache:
            node, comment, start, end, _ = cache[key]
            signode += addnodes.desc_name(node.displayname, node.displayname)

            # There is unfortunately no API to get the parameters of a macro,
            # so we identify them by looking at the tokens.
            tokens = list(node.get_tokens())
            if (
                tokens[1].kind is TokenKind.PUNCTUATION and
                tokens[1].spelling == '('
            ):
                paramlist = addnodes.desc_parameterlist()
                for token in tokens[2:]:
                    if (
                        token.kind is TokenKind.PUNCTUATION and
                        token.spelling == ')'
                    ):
                        break
                    elif token.kind is TokenKind.IDENTIFIER:
                        paramlist += addnodes.desc_parameter(token.spelling, token.spelling)
                signode += paramlist

            self.content = ViewList()
            for lineno, line in enumerate(comment.splitlines(), start[0]):
                self.content.append(line, '<unknown>', lineno)
        return sig
项目:rscfl    作者:lc525    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        cache = _APP_CACHES.get(self.env.app, {})
        key = CursorKind.VAR_DECL, (sig, )
        if key in cache:
            node, comment, start, end, _ = cache[key]
            signode += addnodes.desc_type(node.type.spelling, node.type.spelling + ' ')
            signode += addnodes.desc_name(node.spelling, node.spelling)

            self.content = ViewList()
            for lineno, line in enumerate(comment.splitlines(), start[0]):
                self.content.append(line, '<unknown>', lineno)
        return sig
项目:rscfl    作者:lc525    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        try:
            tag, name = sig.split()
        except ValueError:
            tag, name = None, sig
        cache = _APP_CACHES.get(self.env.app, {})
        key = {'struct': CursorKind.STRUCT_DECL}[tag], (name, )
        if key in cache:
            node, comment, start, end, members = cache[key]
            signode += addnodes.desc_type(tag, tag + ' ')
            signode += addnodes.desc_name(node.spelling, node.spelling)

            self.content = ViewList()
            for line in comment.splitlines():
                self.content.append(line, '<unknown>')

            self.content.append('', '<unknown>')

            for (_, member_name), value in members.items():
                member_node, member_comment, _, _, _ = value
                self.content.append(
                    '.. c:member:: %s %s' % (member_node.type.spelling, member_node.spelling),
                    '<unknown>'
                )
                self.content.append('', '<unknown>')
                for line in member_comment.splitlines():
                    self.content.append('   ' + line, '<unknown>')
                self.content.append('', '<unknown>')


        return sig
项目:zing    作者:evernote    | 项目源码 | 文件源码
def parse_django_admin_node(env, sig, signode):
    command = sig.split(' ')[0]
    env.ref_context['std:program'] = command
    signode += addnodes.desc_name(sig, sig)
    return command
项目:integration-prototype    作者:SKA-ScienceDataProcessor    | 项目源码 | 文件源码
def parse_opcode_signature(env, sig, signode):
    """Transform an opcode signature into RST nodes."""
    m = opcode_sig_re.match(sig)
    if m is None:
        raise ValueError
    opname, arglist = m.groups()
    signode += addnodes.desc_name(opname, opname)
    if arglist is not None:
        paramlist = addnodes.desc_parameterlist()
        signode += paramlist
        paramlist += addnodes.desc_parameter(arglist, arglist)
    return opname.strip()


# Support for documenting pdb commands
项目:integration-prototype    作者:SKA-ScienceDataProcessor    | 项目源码 | 文件源码
def parse_pdb_command(env, sig, signode):
    """Transform a pdb command signature into RST nodes."""
    m = pdbcmd_sig_re.match(sig)
    if m is None:
        raise ValueError
    name, args = m.groups()
    fullname = name.replace('(', '').replace(')', '')
    signode += addnodes.desc_name(name, name)
    if args:
        signode += addnodes.desc_addname(' '+args, ' '+args)
    return fullname
项目:trio    作者:python-trio    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(sig, sig)
        return sig, ""
项目:anarchy_sphinx    作者:AnarchyTools    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        container_class_name = self.env.temp_data.get('swift:class')
        enum_case = None
        assoc_value = None
        raw_value = None

        # split on ( -> first part is case name
        parts = [x.strip() for x in sig.split('(', maxsplit=1)]
        enum_case = parts[0].strip()
        if len(parts) > 1:
            parts = parts[1].rsplit('=', maxsplit=1)
            assoc_value = parts[0].strip()
            if len(parts) > 1:
                raw_value = parts[1].strip()
            if assoc_value == "":
                assoc_value = None
            else:
                assoc_value = "(" + assoc_value
        else:
            parts = [x.strip() for x in sig.split('=', maxsplit=1)]
            enum_case = parts[0].strip()
            if len(parts) > 1:
                raw_value = parts[1].strip()

        # Add class name
        signode += addnodes.desc_name(enum_case, enum_case)
        if assoc_value:
            signode += addnodes.desc_type(assoc_value, assoc_value)
        if raw_value:
            signode += addnodes.desc_addname(raw_value, " = " + raw_value)

        if container_class_name:
            enum_case = container_class_name + '.' + enum_case
        return enum_case, enum_case, True
项目:anarchy_sphinx    作者:AnarchyTools    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        if self.parse_node:
            name = self.parse_node(self.env, sig, signode)
        else:
            signode.clear()
            signode += addnodes.desc_name(sig, sig)
            # normalize whitespace like XRefRole does
            name = ws_re.sub('', sig)
        return name
项目:anarchy_sphinx    作者:AnarchyTools    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        """Transform an option description into RST nodes."""
        count = 0
        firstname = ''
        for potential_option in sig.split(', '):
            potential_option = potential_option.strip()
            m = option_desc_re.match(potential_option)
            if not m:
                self.env.warn(
                    self.env.docname,
                    'Malformed option description %r, should '
                    'look like "opt", "-opt args", "--opt args", '
                    '"/opt args" or "+opt args"' % potential_option,
                    self.lineno)
                continue
            optname, args = m.groups()
            if count:
                signode += addnodes.desc_addname(', ', ', ')
            signode += addnodes.desc_name(optname, optname)
            signode += addnodes.desc_addname(args, args)
            if not count:
                firstname = optname
                signode['allnames'] = [optname]
            else:
                signode['allnames'].append(optname)
            count += 1
        if not firstname:
            raise ValueError
        return firstname
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def parse_opcode_signature(env, sig, signode):
    """Transform an opcode signature into RST nodes."""
    m = opcode_sig_re.match(sig)
    if m is None:
        raise ValueError
    opname, arglist = m.groups()
    signode += addnodes.desc_name(opname, opname)
    if arglist is not None:
        paramlist = addnodes.desc_parameterlist()
        signode += paramlist
        paramlist += addnodes.desc_parameter(arglist, arglist)
    return opname.strip()


# Support for documenting pdb commands
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def parse_pdb_command(env, sig, signode):
    """Transform a pdb command signature into RST nodes."""
    m = pdbcmd_sig_re.match(sig)
    if m is None:
        raise ValueError
    name, args = m.groups()
    fullname = name.replace('(', '').replace(')', '')
    signode += addnodes.desc_name(name, name)
    if args:
        signode += addnodes.desc_addname(' '+args, ' '+args)
    return fullname
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        """
        Parse the signature *sig* into individual nodes and append them to
        *signode*. If ValueError is raised, parsing is aborted and the whole
        *sig* is put into a single desc_name node.

        The return value should be a value that identifies the object.  It is
        passed to :meth:`add_target_and_index()` unchanged, and otherwise only
        used to skip duplicates.
        """
        raise ValueError
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        name, args = parse_directive(sig)
        desc_name = '.. %s::' % name
        signode += addnodes.desc_name(desc_name, desc_name)
        if len(args) > 0:
            signode += addnodes.desc_addname(args, args)
        return name
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(':%s:' % sig, ':%s:' % sig)
        return sig
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def describe_signature(self, signode, mode, env, prefix, parentScope):
        _verify_description_mode(mode)
        identifier = text_type(self)
        if mode == 'lastIsName':
            signode += addnodes.desc_name(identifier, identifier)
        else:
            signode += addnodes.desc_addname(identifier, identifier)
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        if self.parse_node:
            name = self.parse_node(self.env, sig, signode)
        else:
            signode.clear()
            signode += addnodes.desc_name(sig, sig)
            # normalize whitespace like XRefRole does
            name = ws_re.sub('', sig)
        return name
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        """Transform an option description into RST nodes."""
        count = 0
        firstname = ''
        for potential_option in sig.split(', '):
            potential_option = potential_option.strip()
            m = option_desc_re.match(potential_option)
            if not m:
                self.env.warn(
                    self.env.docname,
                    'Malformed option description %r, should '
                    'look like "opt", "-opt args", "--opt args", '
                    '"/opt args" or "+opt args"' % potential_option,
                    self.lineno)
                continue
            optname, args = m.groups()
            if count:
                signode += addnodes.desc_addname(', ', ', ')
            signode += addnodes.desc_name(optname, optname)
            signode += addnodes.desc_addname(args, args)
            if not count:
                firstname = optname
                signode['allnames'] = [optname]
            else:
                signode['allnames'].append(optname)
            count += 1
        if not firstname:
            raise ValueError
        return firstname
项目:coq-rst    作者:cpitclaudel    | 项目源码 | 文件源码
def _render_signature(self, signature, signode):
        signode += addnodes.desc_name(signature, signature)
项目:coq-rst    作者:cpitclaudel    | 项目源码 | 文件源码
def _render_signature(self, signature, signode):
        position = self.state_machine.get_source_and_line(self.lineno)
        tacn_node = parse_notation(signature, *position)
        signode += addnodes.desc_name(signature, '', tacn_node)
项目:sphinxcontrib-websupport    作者:sphinx-doc    | 项目源码 | 文件源码
def userdesc_parse(env, sig, signode):
    x, y = sig.split(':')
    signode += addnodes.desc_name(x, x)
    signode += addnodes.desc_parameterlist()
    signode[-1] += addnodes.desc_parameter(y, y)
    return x
项目:ThinkingInPython    作者:BruceEckel    | 项目源码 | 文件源码
def parse_directive(env, sig, signode):
    if not sig.startswith('.'):
        dec_sig = '.. %s::' % sig
        signode += addnodes.desc_name(dec_sig, dec_sig)
        return sig
    m = dir_sig_re.match(sig)
    if not m:
        signode += addnodes.desc_name(sig, sig)
        return sig
    name, args = m.groups()
    dec_name = '.. %s::' % name
    signode += addnodes.desc_name(dec_name, dec_name)
    signode += addnodes.desc_addname(args, args)
    return name
项目:ThinkingInPython    作者:BruceEckel    | 项目源码 | 文件源码
def parse_role(env, sig, signode):
    signode += addnodes.desc_name(':%s:' % sig, ':%s:' % sig)
    return sig
项目:ThinkingInPython    作者:BruceEckel    | 项目源码 | 文件源码
def parse_event(env, sig, signode):
    m = event_sig_re.match(sig)
    if not m:
        signode += addnodes.desc_name(sig, sig)
        return sig
    name, args = m.groups()
    signode += addnodes.desc_name(name, name)
    plist = addnodes.desc_parameterlist()
    for arg in args.split(','):
        arg = arg.strip()
        plist += addnodes.desc_parameter(arg, arg)
    signode += plist
    return name
项目:porcupine    作者:Akuli    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        assert (not sig.startswith('<<')) and (not sig.endswith('>>'))
        modname = self.options.get(
            'module', self.env.ref_context.get('py:module'))
        classname = self.env.ref_context.get('py:class')
        fullname = classname + '.' + sig

        signode['module'] = modname
        signode['class'] = classname
        signode['fullname'] = fullname

        signode += desc_annotation('virtual event ', 'virtual event ')
        signode += desc_name('<<' + sig + '>>', '<<' + sig + '>>')

        return fullname, ''
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(sig, sig)
        return sig
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(sig, sig)
        return sig
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(sig, sig)
        return sig
项目:zuul-sphinx    作者:openstack-infra    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        signode += addnodes.desc_name(sig, sig)
        return sig
项目:wiggle-docs    作者:wiggleport    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        if self.parse_node:
            name = self.parse_node(self.env, sig, signode)
        else:
            signode.clear()
            signode += addnodes.desc_name(sig, sig)
            # normalize whitespace like XRefRole does
            name = ws_re.sub('', sig)
        return name
项目:guillotina    作者:plone    | 项目源码 | 文件源码
def process_service(self, filename):
        data = self.get_json_from_file(os.path.join(self.dir, filename))
        request_filename = self.write_tmp(data['request'] or '')
        response_filename = self.write_tmp(data['response'] or '')

        example = HTTPExample(
            'http:example',
            arguments=['curl', 'httpie', 'python-requests'],
            options={
                'request': request_filename,
                'response': response_filename
            },
            content=self.content,
            lineno=self.lineno,
            content_offset=self.content_offset,
            block_text='.. http:example::',
            state=self.state,
            state_machine=self.state_machine
        )

        method = data['method'].upper()
        service = data['service']
        name = service.get('name') or ''
        path_scheme = data.get('path_scheme') or name
        summary = service.get('summary') or ''
        permission = service.get('permission') or ''

        container = nodes.container('')
        container.append(addnodes.desc_name('', method + ' '))
        container.append(addnodes.desc_name('', path_scheme))

        inner_container = nodes.definition('')
        container.append(inner_container)

        inner_container.append(nodes.paragraph(summary, summary))
        inner_container.append(addnodes.desc_name('permission', 'permission'))
        perm_label = ': ' + permission
        inner_container.append(addnodes.desc_annotation(perm_label, perm_label))
        inner_container.append(example.run()[0])

        # extra = nodes.paragraph('', '')
        # inner_container.append(extra)
        # if service.get('responses'):
        #     extra.append(nodes.strong('', 'Responses'))
        #     blist = nodes.bullet_list('')
        #     extra.append(blist)
        #     for code, config in service['responses'].items():
        #         blist.append(render_response(code, 'Hello'))

        # cleanup
        os.remove(request_filename)
        os.remove(response_filename)

        return container
项目:anarchy_sphinx    作者:AnarchyTools    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        container_class_name = self.env.temp_data.get('swift:class')

        match = var_sig.match(sig)
        if not match:
            self.env.warn(
                self.env.docname,
                'invalid variable/constant documentation string "%s", ' % sig,
                self.lineno)
            return

        match = match.groupdict()

        if self.objtype == 'static_var':
            signode += addnodes.desc_addname("static var", "static var ")
        elif self.objtype == 'static_let':
            signode += addnodes.desc_addname("static let", "static let ")
        elif self.objtype == 'var':
            signode += addnodes.desc_addname("var", "var ")
        elif self.objtype == 'let':
            signode += addnodes.desc_addname("let", "let ")

        name = match['name'].strip()
        signature = name
        signode += addnodes.desc_name(name, name)
        if match['type']:
            typ = match['type'].strip()
            #signature += '-' + typ
            signode += addnodes.desc_type(typ, " : " + typ)
        if match['value'] and len(match['value']) > 0:
            value = match['value'].strip()
            signode += addnodes.desc_addname(value, " = " + value)
        elif match['value']:
            signode += addnodes.desc_addname('{ ... }', ' = { ... }')

        #signature += "-" + self.objtype

        if container_class_name:
            name = container_class_name + '.' + name
            signature = container_class_name + '.' + signature

        return name, signature, True
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def handle_signature(self, sig, signode):
        sig = sig.strip()
        if '(' in sig and sig[-1:] == ')':
            prefix, arglist = sig.split('(', 1)
            prefix = prefix.strip()
            arglist = arglist[:-1].strip()
        else:
            prefix = sig
            arglist = None
        if '.' in prefix:
            nameprefix, name = prefix.rsplit('.', 1)
        else:
            nameprefix = None
            name = prefix

        objectname = self.env.ref_context.get('js:object')
        if nameprefix:
            if objectname:
                # someone documenting the method of an attribute of the current
                # object? shouldn't happen but who knows...
                nameprefix = objectname + '.' + nameprefix
            fullname = nameprefix + '.' + name
        elif objectname:
            fullname = objectname + '.' + name
        else:
            # just a function or constructor
            objectname = ''
            fullname = name

        signode['object'] = objectname
        signode['fullname'] = fullname

        if self.display_prefix:
            signode += addnodes.desc_annotation(self.display_prefix,
                                                self.display_prefix)
        if nameprefix:
            signode += addnodes.desc_addname(nameprefix + '.', nameprefix + '.')
        signode += addnodes.desc_name(name, name)
        if self.has_arguments:
            if not arglist:
                signode += addnodes.desc_parameterlist()
            else:
                _pseudo_parse_arglist(signode, arglist)
        return fullname, nameprefix