Skip to content

Commit 5b49a3e

Browse files
mergify[bot]emiliocuestafcferreiragonz
authored
Add fallback branch for master links (#1241) (#1251)
* Add fallback branch for master links (#1241) * Add first version of build with master fallback Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Minor branch fix Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Separate python_branch and python fallback branch Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Update repos Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Add same fallback logic as in ReadTheDocs checkouts and logs Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Changes substitution-block per code-block Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Fix refs Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Tests with read the docs env variables Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Resolving problem when building from RTD Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Apply review Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> --------- Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> (cherry picked from commit 60e9c7d) # Conflicts: # docs/conf.py # docs/fastdds/discovery/discovery_server.rst # docs/fastdds/discovery/static.rst # docs/fastdds/getting_started/simple_app/includes/sum_and_next_steps.rst # docs/fastdds/getting_started/simple_python_app/includes/sum_and_next_steps.rst # docs/fastdds/rtps_layer/rtps_layer.rst # docs/fastdds/security/access_control_plugin/access_control_plugin.rst # docs/fastdds/transport/shared_memory/shared_memory.rst # docs/fastdds/transport/tcp/tcp.rst # docs/fastdds/use_cases/request_reply/request_reply.rst # docs/fastdds/use_cases/statistics_module/statistics_module.rst # docs/fastdds/use_cases/well_known_deployments/well_known_deployments.rst # docs/fastdds/use_cases/zero_copy/zero_copy.rst # docs/fastdds/xml_configuration/making_xml_profiles.rst # docs/fastddsgen/pubsub_app/includes/sum_and_next_steps.rst # docs/fastddsgen/rpc_calculator_basic_app/includes/app.rst # docs/fastddsgen/rpc_calculator_basic_app/intro.rst # docs/fastddsgen/rpc_calculator_feed_app/includes/app.rst # docs/fastddsgen/rpc_calculator_feed_app/intro.rst # docs/fastddsgen/usage/usage.rst # docs/installation/configuration/cmake_options.rst # docs/installation/sources/sources_linux.rst # docs/installation/sources/sources_mac.rst # docs/installation/sources/sources_windows.rst # docs/notes/migration_guide.rst # docs/notes/previous_versions/v3.0.0.rst * Fix conflicts Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Update ubuntu version in readthedocs.yaml Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Fix more conflicts, deps, unneeded files Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Change default branches Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Adapt version to branch Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Fix extensions Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Fix even more conflicts Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> --------- Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> Co-authored-by: Emilio Cuesta Fernandez <emiliocuesta@eprosima.com> Co-authored-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent 4a1d1be commit 5b49a3e

27 files changed

Lines changed: 204 additions & 82 deletions

File tree

docs/conf.py

Lines changed: 149 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,52 @@
1818
#
1919
# import sys
2020
# sys.path.insert(0, os.path.abspath('.'))
21+
22+
import git
23+
import json
2124
import os
2225
import pathlib
26+
import requests
2327
import shutil
2428
import subprocess
2529
import sys
2630

27-
import git
28-
29-
import requests
30-
3131

3232
def setup(app):
3333
# Add property to avoid warning.
3434
app.add_config_value('skip_python', None, '')
3535

3636

37+
def download_json():
38+
"""
39+
Download the common theme options of eProsima readthedocs documentation.
40+
41+
The theme options are defined in a JSON file that is hosted in the eProsima GitHub
42+
repository with the index of all eProsima product documentation
43+
(https://github.com/eProsima/all-docs).
44+
45+
:return: dictionary.
46+
"""
47+
url = "https://raw.githubusercontent.com/eProsima/all-docs/master/source/_static/json/eprosima-furo.json"
48+
ret = dict()
49+
try:
50+
req = requests.get(url, allow_redirects=True, timeout=10)
51+
except requests.RequestException as e:
52+
print(
53+
"Failed to download the JSON with the eProsima theme."
54+
"Request Error: {}".format(e)
55+
)
56+
return ret
57+
if req.status_code != 200:
58+
print(
59+
"Failed to download the JSON with the eProsima theme."
60+
"Return code: {}".format(req.status_code)
61+
)
62+
return ret
63+
ret = json.loads(req.content)
64+
return ret
65+
66+
3767
def download_css(html_css_dir):
3868
"""
3969
Download the common theme of eProsima readthedocs documentation.
@@ -96,7 +126,25 @@ def select_css(html_css_dir):
96126

97127

98128
def get_git_branch():
99-
"""Get the git branch this repository is currently on."""
129+
"""Get the git branch this repository is currently on.
130+
131+
On Read the Docs the repo is checked out in detached-HEAD mode, so
132+
``git name-rev`` returns synthetic names like ``remotes/origin/external-1234``
133+
instead of the real branch. A workaround is provided using
134+
``READTHEDOCS_VERSION_TYPE`` and ``READTHEDOCS_VERSION`` according to the build type:
135+
- ``"branch"`` builds: READTHEDOCS_VERSION is the branch name (e.g. ``"3.6.x"``) → use it.
136+
- ``"tag"`` builds: READTHEDOCS_VERSION is the tag name (e.g. ``"v3.6.0"``) → use it.
137+
- ``"external"`` (PR preview) builds: READTHEDOCS_VERSION is the PR number (e.g. ``"1241"``)
138+
which is not a valid git ref. In this case we return None so resolve_fallback_branch falls
139+
back to its default instead of generating broken GitHub URLs.
140+
- Local builds: READTHEDOCS_VERSION_TYPE is unset → fall back to git name-rev.
141+
"""
142+
rtd_type = os.environ.get("READTHEDOCS_VERSION_TYPE")
143+
if rtd_type in ("branch", "tag"):
144+
return os.environ.get("READTHEDOCS_VERSION")
145+
if rtd_type == "external":
146+
return None
147+
100148
path_to_here = os.path.abspath(os.path.dirname(__file__))
101149

102150
# Invoke git to get the current branch which we use to get the theme
@@ -110,12 +158,28 @@ def get_git_branch():
110158
return p.communicate()[0].decode().rstrip()
111159

112160
except Exception:
113-
print('Could not get the branch')
161+
# Local build without git or some error occurred
162+
print("Could not get the branch")
114163

115164
# Couldn't figure out the branch probably due to an error
116165
return None
117166

118167

168+
def resolve_fallback_branch(env_var, docs_branch, default="master"):
169+
"""
170+
Resolve the branch to use for GitHub links.
171+
172+
Priority:
173+
1. Environment variable ``env_var`` (e.g. FASTDDS_BRANCH)
174+
2. Current documentation branch (``docs_branch``)
175+
3. Hard-coded ``default``
176+
177+
This mirrors the checkout logic used in the ReadTheDocs clone block so
178+
that extlinks and the actual checkout always point at the same branch.
179+
"""
180+
return os.environ.get(env_var) or docs_branch or default
181+
182+
119183
def configure_doxyfile(
120184
doxyfile_in,
121185
doxyfile_out,
@@ -169,6 +233,27 @@ def configure_doxyfile(
169233
)
170234
)
171235

236+
# Current branch of the documentation repository — resolved once, used everywhere.
237+
docs_branch = get_git_branch()
238+
if docs_branch:
239+
print('Current documentation branch is "{}"'.format(docs_branch))
240+
else:
241+
print("Current documentation branch could not be determined; " \
242+
"GitHub links will point to default branches instead of the corresponding branch.")
243+
244+
# Resolve GitHub link branches: env var → current docs branch → default.
245+
# Computed here so they are available both in the ReadTheDocs clone block and in extlinks.
246+
fastdds_fallback_branch = resolve_fallback_branch("FASTDDS_BRANCH", docs_branch, "2.14.x")
247+
fastdds_docs_fallback_branch = resolve_fallback_branch("FASTDDS_DOCS_BRANCH", docs_branch, "2.14.x")
248+
fastdds_python_fallback_branch = resolve_fallback_branch("FASTDDS_PYTHON_BRANCH", docs_branch, "1.4.x")
249+
fastdds_gen_fallback_branch = resolve_fallback_branch("FASTDDS_GEN_BRANCH", docs_branch, "3.3.x")
250+
251+
print("Fallback branches for GitHub links:")
252+
print(' Fast-DDS: "{}"'.format(fastdds_fallback_branch))
253+
print(' Fast-DDS-docs: "{}"'.format(fastdds_docs_fallback_branch))
254+
print(' Fast-DDS-Python: "{}"'.format(fastdds_python_fallback_branch))
255+
print(' Fast-DDS-Gen: "{}"'.format(fastdds_gen_fallback_branch))
256+
172257
# Check if we're running on Read the Docs' servers
173258
read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
174259
if read_the_docs_build:
@@ -208,21 +293,17 @@ def configure_doxyfile(
208293
fastdds_repo_name,
209294
)
210295

211-
# Documentation repository branch
212-
docs_branch = get_git_branch()
213-
print('Current documentation branch is "{}"'.format(docs_branch))
214-
215-
# User specified Fast DDS branch
216-
fastdds_branch = os.environ.get('FASTDDS_BRANCH', None)
217-
218-
# First try to checkout to ${FASTDDS_BRANCH}
219-
# Else checkout to 2.14.x
220-
if (fastdds_branch and
221-
fastdds.refs.__contains__('origin/{}'.format(fastdds_branch))):
222-
fastdds_branch = 'origin/{}'.format(fastdds_branch)
296+
# Verify the desired branch actually exists in the cloned remote, falling back to 2.14.x if not.
297+
fastdds_branch = fastdds_fallback_branch
298+
if fastdds.refs.__contains__("origin/{}".format(fastdds_branch)):
299+
fastdds_branch = "origin/{}".format(fastdds_branch)
223300
else:
224-
fastdds_branch = 'origin/2.14.x'
225-
print(f'Fast DDS branch is not set by env var. Using "{fastdds_branch}"')
301+
print(
302+
'Fast DDS does not have branch "{}"; falling back to 2.14.x'.format(
303+
fastdds_branch
304+
)
305+
)
306+
fastdds_branch = "origin/2.14.x"
226307

227308
# Actual checkout
228309
print('Checking out Fast DDS branch "{}"'.format(fastdds_branch))
@@ -235,18 +316,17 @@ def configure_doxyfile(
235316
fastdds_python_repo_name,
236317
)
237318

238-
# User specified Fast DDS branch
239-
fastdds_python_branch = os.environ.get('FASTDDS_PYTHON_BRANCH', None)
240-
241-
# First try to checkout to ${FASTDDS_PYTHON_BRANCH}
242-
# Else checkout to 1.4.x
243-
if (fastdds_python_branch and
244-
fastdds_python.refs.__contains__(
245-
'origin/{}'.format(fastdds_python_branch))):
246-
fastdds_python_branch = 'origin/{}'.format(fastdds_python_branch)
319+
# Verify the desired branch actually exists in the cloned remote, falling back to 2.14.x if not.
320+
fastdds_python_branch = fastdds_python_fallback_branch
321+
if fastdds_python.refs.__contains__("origin/{}".format(fastdds_python_branch)):
322+
fastdds_python_branch = "origin/{}".format(fastdds_python_branch)
247323
else:
248-
fastdds_python_branch = 'origin/1.4.x'
249-
print(f'Fast DDS Python branch is not set by env var. Using "{fastdds_python_branch}"')
324+
print(
325+
'Fast DDS Python does not have branch "{}"; falling back to 2.14.x'.format(
326+
fastdds_python_branch
327+
)
328+
)
329+
fastdds_python_branch = "origin/2.14.x"
250330

251331
# Actual checkout
252332
print('Checking out Fast DDS Python branch "{}"'.format(
@@ -315,12 +395,40 @@ def configure_doxyfile(
315395
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
316396
# ones.
317397
extensions = [
318-
'breathe',
319-
'sphinxcontrib.plantuml',
320-
'sphinx.ext.autodoc', # Document Pydoc documentation from Python bindings.
321-
'sphinx_tabs.tabs'
398+
"breathe",
399+
"sphinx_copybutton",
400+
"sphinx_design",
401+
"sphinx_substitution_extensions",
402+
"sphinx_tabs.tabs",
403+
"sphinx_toolbox.collapse",
404+
"sphinx.ext.autodoc", # Document Pydoc documentation from Python bindings.
405+
"sphinx.ext.extlinks",
406+
"sphinxcontrib.plantuml",
322407
]
323408

409+
extlinks = {
410+
# Fast-DDS repo (tree = directory, blob = file)
411+
"fastdds-tree": (
412+
f"https://github.com/eProsima/Fast-DDS/tree/{fastdds_fallback_branch}/%s", "%s"
413+
),
414+
"fastdds-blob": (
415+
f"https://github.com/eProsima/Fast-DDS/blob/{fastdds_fallback_branch}/%s", "%s"
416+
),
417+
# Fast-DDS-python repo
418+
"fastdds-python-tree": (
419+
f"https://github.com/eProsima/Fast-DDS-Python/tree/{fastdds_python_fallback_branch}/%s", "%s"
420+
),
421+
# Fast-DDS-docs repo (code examples embedded in the docs repo)
422+
"fastdds-docs-tree": (
423+
f"https://github.com/eProsima/Fast-DDS-docs/tree/{fastdds_docs_fallback_branch}/%s", "%s"
424+
),
425+
# Fast-DDS-Gen raw files
426+
"fastddsgen-raw": (
427+
f"https://raw.githubusercontent.com/eProsima/Fast-DDS-Gen/{fastdds_gen_fallback_branch}/%s",
428+
"%s",
429+
),
430+
}
431+
324432
sphinx_tabs_disable_css_loading = False
325433
sphinx_tabs_disable_tab_closing = True
326434

@@ -462,7 +570,12 @@ def configure_doxyfile(
462570
# further. For a list of options available for each theme, see the
463571
# documentation.
464572
#
465-
# html_theme_options = {}
573+
html_theme_options = {}
574+
html_theme_options.update(download_json())
575+
576+
html_use_smartypants = True
577+
578+
html_css_files = [select_css(script_path)]
466579

467580
# Add any paths that contain custom themes here, relative to this directory.
468581
# html_theme_path = []

docs/fastdds/discovery/discovery_server.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ Full example
352352
^^^^^^^^^^^^
353353

354354
The following constitutes a full example on how to configure *server* and *client* both programmatically and using XML.
355-
You may also have a look at the *eProsima Fast DDS* Github repository, which contains `an example <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/dds/DiscoveryServerExample>`_
356-
similar to the one discussed in this section, as well as multiple other examples for different use cases.
355+
You may also have a look at the *eProsima Fast DDS* Github repository, which contains
356+
:fastdds-tree:`an example <examples/cpp/discovery_server>` similar to the one discussed in this section, as well as
357+
multiple other examples for different use cases.
357358

358359
Server side setup
359360
"""""""""""""""""

docs/fastdds/discovery/static.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ and DataReaders) must be statically specified, which is done using dedicated XML
6767
A |DomainParticipant| may load several of such configuration files so that the information about different entities can
6868
be contained in one file, or split into different files to keep it more organized.
6969
*Fast DDS* provides a
70-
`Static Discovery example <https://github.com/eProsima/Fast-DDS/blob/2.x/examples/cpp/dds/StaticHelloWorldExample>`_
70+
:fastdds-blob:`Static Discovery example <examples/cpp/dds/StaticHelloWorldExample>`
7171
that implements this EDP discovery protocol.
7272

7373
The following table describes all the possible elements of a STATIC EDP XML configuration file.

docs/fastdds/getting_started/simple_app/includes/sum_and_next_steps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Next steps
1010

1111
In the *eProsima Fast DDS* Github repository you will find more complex examples that implement DDS communication for
1212
a multitude of use cases and scenarios. You can find them
13-
`here <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/dds>`_.
13+
:fastdds-tree:`here <examples/cpp>`.

docs/fastdds/getting_started/simple_python_app/includes/sum_and_next_steps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Next steps
99

1010
In the *eProsima Fast DDS* Github repository you will find more complex examples that implement DDS communication for
1111
a multitude of use cases and scenarios. You can find them
12-
`here <https://github.com/eProsima/Fast-DDS-python/tree/main/fastdds_python_examples>`_.
12+
:fastdds-python-tree:`here <fastdds_python_examples>`.

docs/fastdds/rtps_layer/rtps_layer.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ explaining the new features it presents.
4141
We recommend you to look at the two examples describing how to use the RTPS layer that come with the distribution
4242
while reading this section.
4343
They are located in
44-
`examples/cpp/rtps/AsSocket <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/rtps/AsSocket>`_ and
45-
`examples/cpp/rtps/Registered <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/rtps/Registered>`_
44+
:fastdds-tree:`examples/cpp/rtps <examples/cpp/rtps>`.
4645

4746
Managing the Participant
4847
^^^^^^^^^^^^^^^^^^^^^^^^

docs/fastdds/security/access_control_plugin/access_control_plugin.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ The following is an example of the Domain Governance XML file contents.
110110
:end-before: <!--><-->
111111
:linenos:
112112

113-
The `Governance XSD file <https://github.com/eProsima/Fast-DDS/blob/2.x/resources/xsd/governance.xsd>`_ and
113+
The :fastdds-blob:`Governance XSD file <resources/xsd/governance.xsd>` and
114114
the
115-
`Governance XML example <https://github.com/eProsima/Fast-DDS/blob/2.x/examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`_
115+
:fastdds-blob:`Governance XML example <examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`
116116
can also be downloaded from the `eProsima Fast DDS Github repository <https://github.com/eProsima/Fast-DDS>`_.
117117

118118
Domain Rules
@@ -447,9 +447,8 @@ The following is an example of the DomainParticipant Permissions XML file conten
447447
:end-before: <!--><-->
448448
:linenos:
449449

450-
The `Permissions XSD file <https://github.com/eProsima/Fast-DDS/blob/2.x/resources/xsd/governance.xsd>`_ and
451-
the
452-
`Permissions XML example <https://github.com/eProsima/Fast-DDS/blob/2.x/examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`_
450+
The :fastdds-blob:`Permissions XSD file <resources/xsd/governance.xsd>` and
451+
the :fastdds-blob:`Permissions XML example <examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`
453452
can also be downloaded from the `eProsima Fast DDS Github repository <https://github.com/eProsima/Fast-DDS>`_.
454453

455454
Grant Section

docs/fastdds/transport/shared_memory/shared_memory.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ The examples below show this procedure in both C++ code and XML file.
276276
HelloWorldExampleSharedMem
277277
--------------------------
278278

279-
A Shared Memory version of helloworld example can be found in the
280-
`HelloWorldExampleSharedMem folder <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/dds/HelloWorldExampleSharedMem>`_.
281-
It shows a publisher and a subscriber that communicate through Shared Memory.
279+
A hello world example suitable for supported delivery mechanisms can be found in the
280+
:fastdds-tree:`delivery_mechanisms folder <examples/cpp/delivery_mechanisms>`.
281+
It shows a publisher and a subscriber that communicate through the desired delivery mechanism (which can be set to
282+
shared memory only).

docs/fastdds/transport/tcp/tcp.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ HelloWorldExampleTCP
451451
--------------------
452452

453453
A TCP version of helloworld example can be found in the
454-
`HelloWorldExampleTCP folder <https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/dds/HelloWorldExampleTCP>`_.
454+
:fastdds-tree:`HelloWorld TCP Example <examples/cpp/dds/HelloWorldExampleTCP>`.
455455
It shows a publisher and a subscriber that communicate through TCP.
456456
The publisher is configured as *TCP server* while the Subscriber is acting as *TCP client*.
457+
:fastdds-blob:`Static Discovery example <examples/cpp/dds/StaticHelloWorldExample>`

docs/fastdds/use_cases/request_reply/request_reply.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The DDS communication schema will be:
5454
The key for making *Request-Reply* work is relating the Request with the Reply in the client's side.
5555
*Fast DDS* API provides |SampleIdentity-api| to achieve this.
5656

57-
A full example can be found in `Fast DDS repository`_.
57+
A full example can be found in the :fastdds-tree:`Fast DDS repository <examples/cpp/request_reply>`.
5858

5959
Getting started
6060
---------------
@@ -151,5 +151,3 @@ For this the client application has to compare the stored |SampleIdentity-api| w
151151
:dedent: 4
152152
:start-after: //REQUEST_REPLY_EXAMPLE_CLIENT_RECEIVE_REPLY
153153
:end-before: //!
154-
155-
.. _Fast DDS repository: https://github.com/eProsima/Fast-DDS/tree/2.x/examples/cpp/dds/RequestReplyExample

0 commit comments

Comments
 (0)