Skip to content

Commit 331ba0d

Browse files
committed
Merge branch 'master' of github.com:humitos/sphinx-hoverxref into humitos/sphinx-3
2 parents 674a782 + c882d19 commit 331ba0d

File tree

10 files changed

+50
-25
lines changed

10 files changed

+50
-25
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dist: xenial
33
python:
44
- 3.6
55
- 3.7
6+
- 3.8
67
install:
78
pip install tox-travis
89
script:

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
# Add any paths that contain custom static files (such as style sheets) here,
129129
# relative to this directory. They are copied after the builtin static files,
130130
# so a file named "default.css" will overwrite the builtin "default.css".
131-
html_static_path = ['_static']
131+
# html_static_path = ['_static']
132132

133133
# Custom sidebar templates, must be a dictionary that maps document names
134134
# to template names.

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sphinx==1.8.5 # pyup: ignore
2-
sphinx-autoapi==1.2.1
2+
sphinx-autoapi==1.3.0
33
sphinx-rtd-theme==0.4.3
44
sphinx-tabs==1.1.13
55
sphinx-prompt==1.1.0

docs/usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ An example using Python Domain would be like:
6868

6969
.. code-block:: rst
7070
71-
:py:class:`hoverxref.domains.HoverXRefStandardDomain`
71+
:py:class:`hoverxref.domains.HoverXRefStandardDomainMixin`
7272
7373
That will render to:
7474

75-
:py:class:`hoverxref.domains.HoverXRefStandardDomain`
75+
:py:class:`hoverxref.domains.HoverXRefStandardDomainMixin`
7676

7777

7878
To enable ``hoverxref`` on a domain, you need to use the config :confval:`hoverxref_domains`

hoverxref/domains.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from sphinx.domains.python import PythonDomain
2-
from sphinx.domains.std import StandardDomain
31
from sphinx.util import logging
42
from .utils import get_ref_xref_data, get_ref_obj_data
53

@@ -26,7 +24,7 @@ def _inject_hoverxref_data(self, env, refnode, docname, labelid):
2624
}
2725

2826

29-
class HoverXRefPythonDomain(HoverXRefBaseDomain, PythonDomain):
27+
class HoverXRefPythonDomainMixin(HoverXRefBaseDomain):
3028

3129
def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode):
3230
refnode = super().resolve_xref(env, fromdocname, builder, type, target, node, contnode)
@@ -51,9 +49,9 @@ def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode):
5149
return refnode
5250

5351

54-
class HoverXRefStandardDomain(HoverXRefBaseDomain, StandardDomain):
52+
class HoverXRefStandardDomainMixin(HoverXRefBaseDomain):
5553
"""
56-
Override ``StandardDomain`` to save the values after the xref resolution.
54+
Mixin for ``StandardDomain`` to save the values after the xref resolution.
5755
5856
``:ref:`` are treating as a different node in Sphinx
5957
(``sphinx.addnodes.pending_xref``). These nodes are translated to regular

hoverxref/extension.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
import inspect
3+
import types
34
from docutils import nodes
45
import sphinx
56
from sphinx.roles import XRefRole
67
from sphinx.util.fileutil import copy_asset
78

89
from . import version
9-
from .domains import HoverXRefPythonDomain, HoverXRefStandardDomain
10+
from .domains import HoverXRefPythonDomainMixin, HoverXRefStandardDomainMixin
1011
from .translators import HoverXRefHTMLTranslator
1112

1213
ASSETS_FILES = [
@@ -54,6 +55,13 @@ def copy_asset_files(app, exception):
5455

5556

5657
def setup_domains(app, config):
58+
"""
59+
Override domains respecting the one defined (if any).
60+
61+
We create a new class by inheriting the Sphinx Domain already defined
62+
and our own ``HoverXRef...DomainMixin`` that includes the logic for
63+
``_hoverxref`` attributes.
64+
"""
5765
# Add ``hoverxref`` role replicating the behavior of ``ref``
5866
app.add_role_to_domain(
5967
'std',
@@ -64,10 +72,27 @@ def setup_domains(app, config):
6472
warn_dangling=True,
6573
),
6674
)
67-
app.add_domain(HoverXRefStandardDomain, override=True)
6875

69-
if 'py' in config.hoverxref_domains:
70-
app.add_domain(HoverXRefPythonDomain, override=True)
76+
domain = types.new_class(
77+
'HoverXRefStandardDomain',
78+
(
79+
HoverXRefStandardDomainMixin,
80+
app.registry.domains.get('std'),
81+
),
82+
{}
83+
)
84+
app.add_domain(domain, override=True)
85+
86+
if 'py' in app.config.hoverxref_domains:
87+
domain = types.new_class(
88+
'HoverXRefPythonDomain',
89+
(
90+
HoverXRefPythonDomainMixin,
91+
app.registry.domains.get('py'),
92+
),
93+
{}
94+
)
95+
app.add_domain(domain, override=True)
7196

7297

7398
def setup_sphinx_tabs(app, config):

tests/examples/python-domain/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
API
44
===
55

6-
.. autoclass:: hoverxref.extension.HoverXRefStandardDomain
6+
.. autoclass:: hoverxref.extension.HoverXRefStandardDomainMixin
77

88

99
.. automodule:: hoverxref.extension

tests/examples/python-domain/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Python Domain
33

44
This is an example page with a Python Domain role usage.
55

6-
:py:class:`This is a :py:class: role to a Python object <hoverxref.extension.HoverXRefStandardDomain>`.
6+
:py:class:`This is a :py:class: role to a Python object <hoverxref.extension.HoverXRefStandardDomainMixin>`.
77

88
:py:mod:`hoverxref.extension`
99

tests/test_htmltag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_python_domain(app, status, warning):
162162
content = open(path).read()
163163

164164
chunks = [
165-
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.extension.HoverXRefStandardDomain" data-version="myversion" href="api.html#hoverxref.extension.HoverXRefStandardDomain" title="hoverxref.extension.HoverXRefStandardDomain"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
165+
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.extension.HoverXRefStandardDomainMixin" data-version="myversion" href="api.html#hoverxref.extension.HoverXRefStandardDomainMixin" title="hoverxref.extension.HoverXRefStandardDomainMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">This</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">:py:class:</span> <span class="pre">role</span> <span class="pre">to</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">object</span></code></a>',
166166
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.extension" data-version="myversion" href="api.html#module-hoverxref.extension" title="hoverxref.extension"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hoverxref.extension</span></code></a>',
167167
'<a class="hoverxref reference internal" data-doc="api" data-project="myproject" data-section="hoverxref.utils.get_ref_xref_data" data-version="myversion" href="api.html#hoverxref.utils.get_ref_xref_data" title="hoverxref.utils.get_ref_xref_data"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.utils.get_ref_xref_data()</span></code></a>',
168168
]

tox.ini

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
[tox]
22
envlist =
33
docs
4-
py{36,37,38}-sphinx{185,201,210,220,231,300}
4+
py{36,37,38}-sphinx{18,20,21,22,23,24,30}
55

66
[testenv]
77
deps =
88
pytest
99
pdbpp
1010
.
11-
sphinx185: sphinx==1.8.5
12-
sphinx201: sphinx==2.0.1
13-
sphinx210: sphinx==2.1.0
14-
sphinx220: sphinx==2.2.0
15-
sphinx231: sphinx==2.3.1
16-
sphinx300: sphinx==3.0.0
11+
sphinx18: sphinx~=1.8.0
12+
sphinx20: sphinx~=2.0.0
13+
sphinx21: sphinx~=2.1.0
14+
sphinx22: sphinx~=2.2.0
15+
sphinx23: sphinx~=2.3.0
16+
sphinx24: sphinx~=2.4.0
17+
sphinx30: sphinx~=3.0.0
1718
commands = pytest {posargs}
1819

19-
[testenv:py37-sphinx210]
20+
[testenv:py38-sphinx30]
2021
deps =
2122
{[testenv]deps}
2223
pytest-cov
@@ -31,4 +32,4 @@ setenv =
3132
READTHEDOCS_PROJECT = sphinx-hoverxref
3233
READTHEDOCS_VERSION = latest
3334
commands =
34-
sphinx-build -W -q -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
35+
sphinx-build -W -E -q -b html -d {envtmpdir}/doctrees . {envtmpdir}/html

0 commit comments

Comments
 (0)