|
1 | 1 |
|
| 2 | +import sys |
| 3 | + |
2 | 4 | from sphinx.util.docstrings import prepare_docstring
|
3 |
| -from sphinx.util import force_decode |
4 | 5 | from sphinx.domains.python import PyClasslike
|
5 | 6 | from sphinx.ext import autodoc
|
6 | 7 | from zope.interface import Interface
|
7 | 8 | from zope.interface.interface import InterfaceClass
|
8 | 9 |
|
| 10 | + |
| 11 | +if sys.version_info < (3,): |
| 12 | + from sphinx.util import force_decode |
| 13 | +else: |
| 14 | + def force_decode(s, encoding): |
| 15 | + return s |
| 16 | + |
| 17 | + |
9 | 18 | class InterfaceDesc(PyClasslike):
|
10 | 19 | def get_index_text(self, modname, name_cls):
|
11 | 20 | return '%s (interface in %s)' % (name_cls[0], modname)
|
@@ -98,16 +107,25 @@ def setup(app):
|
98 | 107 |
|
99 | 108 | from sphinx.domains import ObjType
|
100 | 109 |
|
| 110 | + try: |
| 111 | + domains = app.domains |
| 112 | + except AttributeError: |
| 113 | + domains = app.registry.domains |
| 114 | + |
101 | 115 | # Allow the :class: directive to xref interface objects through the search
|
102 | 116 | # mechanism, i.e., prefixed with a '.', like :class:`.ITheInterface`
|
103 | 117 | # (without this, an exact match is required)
|
104 |
| - class InterfacePythonDomain(app.domains['py']): |
| 118 | + class InterfacePythonDomain(domains['py']): |
105 | 119 | pass
|
106 |
| - InterfacePythonDomain.object_types = app.domains['py'].object_types.copy() |
| 120 | + InterfacePythonDomain.object_types = domains['py'].object_types.copy() |
107 | 121 | InterfacePythonDomain.object_types['interface'] = ObjType( 'interface', 'interface', 'obj', 'class')
|
108 | 122 | old_class = InterfacePythonDomain.object_types['class']
|
109 | 123 | new_class = ObjType( old_class.lname, *(old_class.roles + ('interface',)), **old_class.attrs )
|
110 | 124 | InterfacePythonDomain.object_types['class'] = new_class
|
111 |
| - app.override_domain( InterfacePythonDomain ) |
| 125 | + |
| 126 | + if hasattr(app, 'override_domain'): |
| 127 | + app.override_domain( InterfacePythonDomain ) |
| 128 | + else: |
| 129 | + app.add_domain( InterfacePythonDomain, override=True ) |
112 | 130 |
|
113 | 131 | app.add_autodocumenter(InterfaceDocumenter)
|
0 commit comments