Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Default hoverxref_api_host to the proxied API #134

Merged
merged 5 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SOURCEDIR = .
BUILDDIR = _build

# sphinx-hoverxref expected variables
export READTHEDOCS=True
export READTHEDOCS_PROJECT=sphinx-hoverxref
export READTHEDOCS_VERSION=latest

Expand Down
18 changes: 2 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
Expand Down Expand Up @@ -65,22 +63,10 @@
'sphinx': 'tooltip',
}

# Used when building the documentation from the terminal and using a local Read
# the Docs instance as backend
hoverxref_api_host = 'http://localhost:8000'

if os.environ.get('READTHEDOCS') == 'True':
# Building on Read the Docs
# Used when building the documentation locally.
if os.environ.get('READTHEDOCS') != 'True':
hoverxref_api_host = 'https://readthedocs.org'

if os.environ.get('PROXIED_API_ENDPOINT') == 'True':
# Use the proxied API endpoint
hoverxref_api_host = '/_'

if os.environ.get('LOCAL_READTHEDOCS') == 'True':
# Building on a local Read the Docs instance
hoverxref_api_host = 'http://community.dev.readthedocs.io'

hoverxref_tooltip_maxwidth = 650
hoverxref_auto_ref = True
hoverxref_roles = [
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ These settings are global and have effect on both, tooltips and modal dialogues.

.. confval:: hoverxref_api_host

Description: Host URL for the API to retrieve the content of the floating window
Description: Host or root URL for the API to retrieve the content of the floating window

Default: ``https://readthedocs.org``
Default: ``/_``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to default this value when running on RTD, don't we? For dev setup this will cause weird breakage for a lot of users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's documented that this should be changed to rtd.org in the dev docs, for the docs of this extension we are checking if we are running on rtd

# Used when building the documentation locally.
if os.environ.get('READTHEDOCS') != 'True':
hoverxref_api_host = 'https://readthedocs.org'

People testing this locally will need to define the hoverxref_project and hoverxref_version anyway.


Type: string

Expand Down
37 changes: 3 additions & 34 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,14 @@ Serve the documentation locally with this command:

Now, you can hit http://localhost:9000/ and you should see your documentation here.


Avoid CORS on local backend
+++++++++++++++++++++++++++

When building the documentation locally,
the API calls will be blocked by the browser because of :abbr:`CORS (Cross Origin Resource Sharing)`
(you are hitting the URL http://localhost:9000/ and the API calls are to https://readthedocs.org/).

You can disable this while developing our extension.
To do this, you can open Google Chrome with these arguments:

.. prompt:: bash

google-chrome-stable --disable-web-security --user-data-dir='/tmp/testing'

If Firefox, you can install this add-ons: `Allow CORS: Access-Control-Allow-Origin <https://addons.mozilla.org/es/firefox/addon/access-control-allow-origin/>`_.


Using a local Read the Docs instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can `install Read the Docs locally following these instructions`_.
Although, it may be too complicated just to retrieve the same content that you could have in https://readthedocs.org.

To make the extension to work, you will need to define this setting in your ``conf.py`` file:

.. code-block:: python

hoverxref_api_host = 'http://dev.readthedocs.io:8000'

.. tip::

The value of this setting should be the same as ``PUBLIC_API_URL``.

Once you have done that, you can just import the project directly in your local instance,
and the tooltips should work without problem.

.. _install Read the Docs locally following these instructions: https://docs.readthedocs.io/en/stable/development/install.html
You don't need to change anything to be able to use your local instance,
the default :confval:`hoverxref_api_host` value should work.

.. _install Read the Docs locally following these instructions: https://docs.readthedocs.io/page/development/install.html

Permanent tooltip to work with CSS
----------------------------------
Expand Down
4 changes: 2 additions & 2 deletions hoverxref/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ def setup(app):
app.add_config_value('hoverxref_default_type', 'tooltip', 'env')
app.add_config_value('hoverxref_intersphinx', [], 'env')
app.add_config_value('hoverxref_intersphinx_types', {}, 'env')
app.add_config_value('hoverxref_api_host', 'https://readthedocs.org', 'env')
app.add_config_value('hoverxref_api_host', '/_', 'env')

# Tooltipster settings
# Deprecated in favor of ``hoverxref_api_host``
app.add_config_value('hoverxref_tooltip_api_host', 'https://readthedocs.org', 'env')
app.add_config_value('hoverxref_tooltip_api_host', '/_', 'env')
app.add_config_value('hoverxref_tooltip_theme', ['tooltipster-shadow', 'tooltipster-shadow-custom'], 'env')
app.add_config_value('hoverxref_tooltip_interactive', True, 'env')
app.add_config_value('hoverxref_tooltip_maxwidth', 450, 'env')
Expand Down