File: api_index.py

package info (click to toggle)
buildbot 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,080 kB
  • sloc: python: 174,183; sh: 1,204; makefile: 332; javascript: 119; xml: 16
file content (53 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from sphinx.domains import Index
from sphinx.domains.std import StandardDomain


class PythonAPIIndex(Index):
    objecttype = 'class'
    name = 'apiindex'
    localname = 'Public API Index'
    shortname = 'classes'

    def generate(self, docnames=None):
        unsorted_objects = [
            (refname, entry.docname, entry.objtype)
            for (refname, entry) in self.domain.data['objects'].items()
            if entry.objtype in ['class', 'function']
        ]
        objects = sorted(unsorted_objects, key=lambda x: x[0].lower())

        entries = []

        for refname, docname, objtype in objects:
            if docnames and docname not in docnames:
                continue

            extra_info = objtype
            display_name = refname
            if objtype == 'function':
                display_name += '()'
            entries.append([display_name, 0, docname, refname, extra_info, '', ''])

        return [('', entries)], False


def setup(app):
    app.add_index_to_domain('py', PythonAPIIndex)
    StandardDomain.initial_data['labels']['apiindex'] = ('py-apiindex', '', 'Public API Index')
    StandardDomain.initial_data['anonlabels']['apiindex'] = ('py-apiindex', '')
    return {'parallel_read_safe': True, 'parallel_write_safe': True}