Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersphinx support #86

Merged
merged 34 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2cd8013
Override `missing-reference` from intersphinx to support hoverxref
humitos Aug 20, 2020
9f30017
Only send `?url=` to Embed API when `data-url` is available
humitos Aug 20, 2020
25a6936
Merge branch 'master' of github.com:humitos/sphinx-hoverxref into hum…
humitos May 5, 2021
7eae53b
Add testcase for intersphinx
humitos May 5, 2021
121af16
Make tootltip type for intersphinx configurable
humitos May 5, 2021
29394a8
Update copyright year
humitos May 5, 2021
501fba4
Docs: for intersphinx
humitos May 5, 2021
3a25b2c
Docs: fail on warning
humitos May 5, 2021
b838f4e
Docs: use :doc: to reference documents via intersphinx
humitos May 5, 2021
fab9d6c
Docs: use automation rules for the tooltip
humitos May 5, 2021
3e81de8
Remove `title=` from HTML tag
humitos May 6, 2021
dd1ae8c
Update docs/usage.rst
humitos May 20, 2021
bc6ae49
Update hoverxref/extension.py
humitos May 20, 2021
5a94e4d
Merge branch 'master' into humitos/support-intersphinx
humitos May 20, 2021
42d11f5
Merge branch 'humitos/support-intersphinx' of github.com:humitos/sphi…
humitos May 20, 2021
35594cd
Typo on link
humitos May 20, 2021
cb7996c
Remove note about extension installation order
humitos May 20, 2021
ee220b4
Don't execute our intersphinx feature if Sphinx's one is not enabled
humitos May 20, 2021
c4068b4
Default to `None` for `hoverxref_intersphinx`
humitos May 25, 2021
9187faa
Make `hoverxref_intersphinx` able to define the target projects
humitos May 25, 2021
5c4d743
Re-configure our docs to work with intersphinx
humitos May 25, 2021
c0f6cb2
Make a `list()` because it can't pickle `.keys()`
humitos May 25, 2021
0a28a0a
Allow to define what interpshinx mappings have hoverxref enabled
humitos Jun 1, 2021
1bbb002
Docs' typo
humitos Jun 1, 2021
bdc4431
Define the tooltip type/style per intersphinx mapping
humitos Jun 1, 2021
277f801
Configure our documentation with intersphinx
humitos Jun 1, 2021
9f4f46e
Test cases for intersphinx support
humitos Jun 1, 2021
d3e9348
Define project/version at docs' conf.py from testcase
humitos Jun 1, 2021
ce8fd61
Variable typo
humitos Jun 1, 2021
b96f217
Make tests work with Sphinx 4.x
humitos Jun 1, 2021
8b78377
Merge remote-tracking branch 'origin/master' into humitos/support-int…
humitos Jun 1, 2021
0a75b73
Do not remove `reftitle` because it breaks other extensions
humitos Jun 1, 2021
26c1476
Update docs/configuration.rst
humitos Jun 7, 2021
6ca6dfd
Allow to specify the tooltip's type for each intersphinx role
humitos Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test cases for intersphinx support
  • Loading branch information
humitos committed Jun 1, 2021
commit 9f4f46e6bad606a72e9275486067f1d49f8aca08
7 changes: 1 addition & 6 deletions tests/examples/intersphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
extensions = [
'hoverxref.extension',
'sphinx.ext.intersphinx',
'sphinx.ext.autodoc',
]

hoverxref_intersphinx = [
'python',
]
hoverxref_intersphinx_type = 'modal'
autosectionlabel_prefix_document = True

# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
Expand Down
7 changes: 7 additions & 0 deletions tests/examples/intersphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ This is an example page.
:ref:`This a :ref: to datetime.datetime Python's function using intersphinx <python:datetime-datetime>`.

:ref:`This a :ref: to Config File v2 Read the Docs' page using intersphinx <readthedocs:config-file/v2:python>`.

:py:class:`float`

.. autofunction:: hoverxref.extension.setup


:py:func:`hoverxref.extension.setup`
82 changes: 76 additions & 6 deletions tests/test_htmltag.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,88 @@ def test_ignore_refs(app, status, warning):
@pytest.mark.sphinx(
srcdir=intersphinxsrc,
)
def test_intersphinx(app, status, warning):
def test_intersphinx_default_configs(app, status, warning):
app.build()
path = app.outdir / 'index.html'
assert path.exists() is True
content = open(path).read()

chunks = [
'<a class="hoverxref modal reference external" data-url="https://docs.python.org/3/tutorial/index.html#tutorial-index" href="https://docs.python.org/3/tutorial/index.html#tutorial-index"><span class="xref std std-ref">This a :ref: to The Python Tutorial using intersphinx</span></a>.',
'<a class="hoverxref modal reference external" data-url="https://docs.python.org/3/library/datetime.html#datetime-datetime" href="https://docs.python.org/3/library/datetime.html#datetime-datetime"><span class="xref std std-ref">This a :ref: to datetime.datetime Python’s function using intersphinx</span></a>.</p>',
# ``readthedocs`` mapping is not defined for hoverxref intersphinx,
# so it only adds the link without the hoverxref classes or data-url attribute
'<a class="reference external" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" title="(in Read the Docs v5.17.0)"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>.</p>',
'<a class="reference external" href="https://docs.python.org/3/tutorial/index.html#tutorial-index" title="(in Python v3.9)"><span class="xref std std-ref">This a :ref: to The Python Tutorial using intersphinx</span></a>',
'<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime-datetime" title="(in Python v3.9)"><span class="xref std std-ref">This a :ref: to datetime.datetime Python’s function using intersphinx</span></a>',
'<a class="reference external" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" title="(in Read the Docs v5.17.0)"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>',
'<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>',
'<dt id="hoverxref.extension.setup">',
'<a class="reference internal" href="#hoverxref.extension.setup" title="hoverxref.extension.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.extension.setup()</span></code></a>',
]

for chunk in chunks:
assert chunk in content


@pytest.mark.sphinx(
srcdir=intersphinxsrc,
confoverrides={
'hoverxref_intersphinx': [
'python',
],
},
)
def test_intersphinx_python_mapping(app, status, warning):
app.build()
path = app.outdir / 'index.html'
assert path.exists() is True
content = open(path).read()

chunks = [
# Python's links do have hoverxref enabled
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/tutorial/index.html#tutorial-index" href="https://docs.python.org/3/tutorial/index.html#tutorial-index"><span class="xref std std-ref">This a :ref: to The Python Tutorial using intersphinx</span></a>',
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/datetime.html#datetime-datetime" href="https://docs.python.org/3/library/datetime.html#datetime-datetime"><span class="xref std std-ref">This a :ref: to datetime.datetime Python’s function using intersphinx</span></a>',
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/functions.html#float" href="https://docs.python.org/3/library/functions.html#float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>',

# Read the Docs' link does not have hoverxref enabled
'<a class="reference external" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" title="(in Read the Docs v5.17.0)"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>',

# Python's domain does not have hoverxref enabled
'<a class="reference internal" href="#hoverxref.extension.setup" title="hoverxref.extension.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.extension.setup()</span></code></a>',
]

for chunk in chunks:
assert chunk in content


@pytest.mark.sphinx(
srcdir=intersphinxsrc,
confoverrides={
'hoverxref_intersphinx': [
'readthedocs',
'python',
],
'hoverxref_intersphinx_types': {
'readthedocs': 'modal',
},
'hoverxref_domains': ['py'],
'hoverxref_project': 'test',
'hoverxref_version': 'test',
},
)
def test_intersphinx_all_mappings(app, status, warning):
app.build()
path = app.outdir / 'index.html'
assert path.exists() is True
content = open(path).read()

chunks = [
# Python's links do have hoverxref enabled
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/tutorial/index.html#tutorial-index" href="https://docs.python.org/3/tutorial/index.html#tutorial-index"><span class="xref std std-ref">This a :ref: to The Python Tutorial using intersphinx</span></a>',
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/datetime.html#datetime-datetime" href="https://docs.python.org/3/library/datetime.html#datetime-datetime"><span class="xref std std-ref">This a :ref: to datetime.datetime Python’s function using intersphinx</span></a>',
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/functions.html#float" href="https://docs.python.org/3/library/functions.html#float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>',

# Read the Docs' link does have hoverxref enabled
'<a class="hoverxref modal reference external" data-url="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>',

# Python domain's link does have hoverxref enabled
'<a class="hoverxref tooltip reference internal" data-doc="index" data-docpath="/index.html" data-project="test" data-section="hoverxref.extension.setup" data-version="test" href="#hoverxref.extension.setup" title="hoverxref.extension.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">hoverxref.extension.setup()</span></code></a>',
]

for chunk in chunks:
Expand Down