Ejemplo n.º 1
0
def reportErrors(obj: model.Documentable, errs: Sequence[ParseError]) -> None:
    if errs and obj.fullName() not in obj.system.docstring_syntax_errors:
        obj.system.docstring_syntax_errors.add(obj.fullName())
        for err in errs:
            obj.report('bad docstring: ' + err.descr(),
                       lineno_offset=(err.linenum() or 1) - 1,
                       section='docstring')
Ejemplo n.º 2
0
def taglink(o: model.Documentable, label: Optional[str] = None) -> Tag:
    if not o.isVisible:
        o.system.msg("html", "don't link to %s" % o.fullName())
    if label is None:
        label = o.fullName()
    # Create a link to the object, with a "data-type" attribute which says what
    # kind of object it is (class, etc). This helps doc2dash figure out what it
    # is.
    ret: Tag = tags.a(href=o.url, class_="code", **{"data-type":
                                                    o.kind})(label)
    return ret
Ejemplo n.º 3
0
 def privacyClass(self, documentable: Documentable) -> PrivacyClass:
     """Report the privacy level for an object. Hide the module
     'docstring_parser.tests'.
     """
     if documentable.fullName().startswith("docstring_parser.tests"):
         return PrivacyClass.HIDDEN
     return super().privacyClass(documentable)
Ejemplo n.º 4
0
def taglink(o: model.Documentable,
            page_url: str,
            label: Optional[str] = None) -> Tag:
    if not o.isVisible:
        o.system.msg("html", "don't link to %s" % o.fullName())

    if label is None:
        label = o.fullName()

    url = o.url
    if url.startswith(page_url + '#'):
        # When linking to an item on the same page, omit the path.
        # Besides shortening the HTML, this also avoids the page being reloaded
        # if the query string is non-empty.
        url = url[len(page_url):]

    ret: Tag = tags.a(label, href=url)
    return ret
Ejemplo n.º 5
0
def objects_order(o: model.Documentable) -> Tuple[int, int, str]:
    """
    Function to use as the value of standard library's L{sorted} function C{key} argument
    such that the objects are sorted by: Privacy, Kind and Name.

    Example::

        children = sorted((o for o in ob.contents.values() if o.isVisible),
                      key=objects_order)
    """
    return (-o.privacyClass.value, -o.kind.value if o.kind else 0,
            o.fullName().lower())
Ejemplo n.º 6
0
    def _generateLine(self, obj: Documentable) -> str:
        """
        Return inventory line for object.

        name domain_name:type priority URL display_name

        Domain name is always: py
        Priority is always: -1
        Display name is always: -
        """
        # Avoid circular import.
        from pydoctor import model

        full_name = obj.fullName()

        if obj.documentation_location is model.DocLocation.OWN_PAGE:
            url = obj.fullName() + '.html'
        else:
            url = obj.parent.fullName() + '.html#' + obj.name

        display = '-'
        if isinstance(obj, (model.Package, model.Module)):
            domainname = 'module'
        elif isinstance(obj, model.Class):
            domainname = 'class'
        elif isinstance(obj, model.Function):
            if obj.kind == 'Function':
                domainname = 'function'
            else:
                domainname = 'method'
        elif isinstance(obj, model.Attribute):
            domainname = 'attribute'
        else:
            domainname = 'obj'
            self.error('sphinx', "Unknown type %r for %s." % (
                type(obj),
                full_name,
            ))

        return f'{full_name} py:{domainname} -1 {url} {display}\n'
Ejemplo n.º 7
0
def _lckey(x: model.Documentable) -> Tuple[str, str]:
    return (x.fullName().lower(), x.fullName())
Ejemplo n.º 8
0
 def fullName(obj: model.Documentable) -> str:
     return obj.fullName()