From 7e0646bc0066acd62091670e2cb4002302db20a4 Mon Sep 17 00:00:00 2001 From: crea Date: Thu, 29 Jun 2017 15:10:21 +0800 Subject: [PATCH 1/3] Fixed implementation of interface role/object type --- repoze/sphinx/autointerface.py | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/repoze/sphinx/autointerface.py b/repoze/sphinx/autointerface.py index 597567e..b41cc78 100644 --- a/repoze/sphinx/autointerface.py +++ b/repoze/sphinx/autointerface.py @@ -1,7 +1,11 @@ from sphinx.util.docstrings import prepare_docstring from sphinx.util import force_decode -from sphinx.domains.python import PyClasslike +from sphinx.domains import ObjType +from sphinx.domains.python import ( + PyClasslike, + PyXRefRole, +) from sphinx.ext import autodoc from zope.interface import Interface from zope.interface.interface import InterfaceClass @@ -94,20 +98,21 @@ def keyfunc(entry): def setup(app): + # We have to add a new ``object type`` for ``:interface:`` references + # to work properly. However, Sphinx does not have an + # ``add_object_type_to_domain()`` method, so we have to carefully + # override the whole domain. We are using the currently configured + # domain class instead of importing it, because it could be already + # overriden (clumsy inheritance). + current_domain = app.registry.domains['py'] + new_types = current_domain.object_types.copy() + new_types['interface'] = ObjType('interface', 'interface', 'obj', 'class') + + class InterfacePythonDomain(current_domain): + object_types = new_types + + app.override_domain(InterfacePythonDomain) app.add_directive_to_domain('py', 'interface', InterfaceDesc) - - from sphinx.domains import ObjType - - # Allow the :class: directive to xref interface objects through the search - # mechanism, i.e., prefixed with a '.', like :class:`.ITheInterface` - # (without this, an exact match is required) - class InterfacePythonDomain(app.domains['py']): - pass - InterfacePythonDomain.object_types = app.domains['py'].object_types.copy() - InterfacePythonDomain.object_types['interface'] = ObjType( 'interface', 'interface', 'obj', 'class') - old_class = InterfacePythonDomain.object_types['class'] - new_class = ObjType( old_class.lname, *(old_class.roles + ('interface',)), **old_class.attrs ) - InterfacePythonDomain.object_types['class'] = new_class - app.override_domain( InterfacePythonDomain ) - + app.add_role_to_domain('py', 'interface', PyXRefRole()) app.add_autodocumenter(InterfaceDocumenter) + From 610132b3448b670220288d48de8580bc0b8af140 Mon Sep 17 00:00:00 2001 From: crea Date: Thu, 29 Jun 2017 17:26:01 +0800 Subject: [PATCH 2/3] Updated contributors --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 7a58e87..6fc0d35 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -105,3 +105,4 @@ Contributors - Tres Seaver, 2011/03/22 - Jason Madden, 2013/01/10 +- Andrey Tretyakov, 2017/06/29 From 115917da30d972514b8c8197d35771ea099845a6 Mon Sep 17 00:00:00 2001 From: crea Date: Fri, 30 Jun 2017 23:24:38 +0800 Subject: [PATCH 3/3] Added checks to support old Sphinx API --- repoze/sphinx/autointerface.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/repoze/sphinx/autointerface.py b/repoze/sphinx/autointerface.py index b41cc78..8e0cfef 100644 --- a/repoze/sphinx/autointerface.py +++ b/repoze/sphinx/autointerface.py @@ -103,8 +103,14 @@ def setup(app): # ``add_object_type_to_domain()`` method, so we have to carefully # override the whole domain. We are using the currently configured # domain class instead of importing it, because it could be already - # overriden (clumsy inheritance). - current_domain = app.registry.domains['py'] + # overriden. + try: + # New API + current_domain = app.registry.domains['py'] + except AttributeError: + # Old API + current_domain = app.domains['py'] + new_types = current_domain.object_types.copy() new_types['interface'] = ObjType('interface', 'interface', 'obj', 'class')