Skip to content

Commit 60e9c7d

Browse files
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>
1 parent 93e64cd commit 60e9c7d

31 files changed

Lines changed: 142 additions & 76 deletions

File tree

docs/conf.py

Lines changed: 94 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,25 @@ def static_relative(path):
248248

249249

250250
def get_git_branch():
251-
"""Get the git branch this repository is currently on."""
251+
"""Get the git branch this repository is currently on.
252+
253+
On Read the Docs the repo is checked out in detached-HEAD mode, so
254+
``git name-rev`` returns synthetic names like ``remotes/origin/external-1234``
255+
instead of the real branch. A workaround is provided using
256+
``READTHEDOCS_VERSION_TYPE`` and ``READTHEDOCS_VERSION`` according to the build type:
257+
- ``"branch"`` builds: READTHEDOCS_VERSION is the branch name (e.g. ``"3.6.x"``) → use it.
258+
- ``"tag"`` builds: READTHEDOCS_VERSION is the tag name (e.g. ``"v3.6.0"``) → use it.
259+
- ``"external"`` (PR preview) builds: READTHEDOCS_VERSION is the PR number (e.g. ``"1241"``)
260+
which is not a valid git ref. In this case we return None so resolve_fallback_branch falls
261+
back to its default instead of generating broken GitHub URLs.
262+
- Local builds: READTHEDOCS_VERSION_TYPE is unset → fall back to git name-rev.
263+
"""
264+
rtd_type = os.environ.get("READTHEDOCS_VERSION_TYPE")
265+
if rtd_type in ("branch", "tag"):
266+
return os.environ.get("READTHEDOCS_VERSION")
267+
if rtd_type == "external":
268+
return None
269+
252270
path_to_here = os.path.abspath(os.path.dirname(__file__))
253271

254272
# Invoke git to get the current branch which we use to get the theme
@@ -270,12 +288,28 @@ def get_git_branch():
270288
return p.communicate()[0].decode().rstrip()
271289

272290
except Exception:
291+
# Local build without git or some error occurred
273292
print("Could not get the branch")
274293

275294
# Couldn't figure out the branch probably due to an error
276295
return None
277296

278297

298+
def resolve_fallback_branch(env_var, docs_branch, default="master"):
299+
"""
300+
Resolve the branch to use for GitHub links.
301+
302+
Priority:
303+
1. Environment variable ``env_var`` (e.g. FASTDDS_BRANCH)
304+
2. Current documentation branch (``docs_branch``)
305+
3. Hard-coded ``default``
306+
307+
This mirrors the checkout logic used in the ReadTheDocs clone block so
308+
that extlinks and the actual checkout always point at the same branch.
309+
"""
310+
return os.environ.get(env_var) or docs_branch or default
311+
312+
279313
def configure_doxyfile(
280314
doxyfile_in,
281315
doxyfile_out,
@@ -323,6 +357,27 @@ def configure_doxyfile(
323357
# Header files
324358
input_dir = os.path.abspath("{}/fastdds/include/fastdds".format(project_binary_dir))
325359

360+
# Current branch of the documentation repository — resolved once, used everywhere.
361+
docs_branch = get_git_branch()
362+
if docs_branch:
363+
print('Current documentation branch is "{}"'.format(docs_branch))
364+
else:
365+
print("Current documentation branch could not be determined; " \
366+
"GitHub links will point to default branches instead of the corresponding branch.")
367+
368+
# Resolve GitHub link branches: env var → current docs branch → default.
369+
# Computed here so they are available both in the ReadTheDocs clone block and in extlinks.
370+
fastdds_fallback_branch = resolve_fallback_branch("FASTDDS_BRANCH", docs_branch, "master")
371+
fastdds_docs_fallback_branch = resolve_fallback_branch("FASTDDS_DOCS_BRANCH", docs_branch, "master")
372+
fastdds_python_fallback_branch = resolve_fallback_branch("FASTDDS_PYTHON_BRANCH", docs_branch, "master")
373+
fastdds_gen_fallback_branch = resolve_fallback_branch("FASTDDS_GEN_BRANCH", docs_branch, "master")
374+
375+
print("Fallback branches for GitHub links:")
376+
print(' Fast-DDS: "{}"'.format(fastdds_fallback_branch))
377+
print(' Fast-DDS-docs: "{}"'.format(fastdds_docs_fallback_branch))
378+
print(' Fast-DDS-Python: "{}"'.format(fastdds_python_fallback_branch))
379+
print(' Fast-DDS-Gen: "{}"'.format(fastdds_gen_fallback_branch))
380+
326381
# Check if we're running on Read the Docs' servers
327382
read_the_docs_build = os.environ.get("READTHEDOCS", None) == "True"
328383
if read_the_docs_build:
@@ -355,24 +410,14 @@ def configure_doxyfile(
355410
fastdds_repo_name,
356411
)
357412

358-
# Documentation repository branch
359-
docs_branch = get_git_branch()
360-
print('Current documentation branch is "{}"'.format(docs_branch))
361-
362-
# User specified Fast DDS branch
363-
fastdds_branch = os.environ.get("FASTDDS_BRANCH", None)
364-
365-
# First try to checkout to ${FASTDDS_BRANCH}
366-
# Else try with current documentation branch
367-
# Else checkout to master
368-
if fastdds_branch and fastdds.refs.__contains__("origin/{}".format(fastdds_branch)):
413+
# Verify the desired branch actually exists in the cloned remote, falling back to master if not.
414+
fastdds_branch = fastdds_fallback_branch
415+
if fastdds.refs.__contains__("origin/{}".format(fastdds_branch)):
369416
fastdds_branch = "origin/{}".format(fastdds_branch)
370-
elif docs_branch and fastdds.refs.__contains__("origin/{}".format(docs_branch)):
371-
fastdds_branch = "origin/{}".format(docs_branch)
372417
else:
373418
print(
374-
'Fast DDS does not have either "{}" or "{}" branches'.format(
375-
fastdds_branch, docs_branch
419+
'Fast DDS does not have branch "{}"; falling back to master'.format(
420+
fastdds_branch
376421
)
377422
)
378423
fastdds_branch = "origin/master"
@@ -388,24 +433,14 @@ def configure_doxyfile(
388433
fastdds_python_repo_name,
389434
)
390435

391-
# User specified Fast DDS branch
392-
fastdds_python_branch = os.environ.get("FASTDDS_PYTHON_BRANCH", None)
393-
394-
# First try to checkout to ${FASTDDS_PYTHON_BRANCH}
395-
# Else try with current documentation branch
396-
# Else checkout to master
397-
if fastdds_python_branch and fastdds_python.refs.__contains__(
398-
"origin/{}".format(fastdds_python_branch)
399-
):
436+
# Verify the desired branch actually exists in the cloned remote, falling back to master if not.
437+
fastdds_python_branch = fastdds_python_fallback_branch
438+
if fastdds_python.refs.__contains__("origin/{}".format(fastdds_python_branch)):
400439
fastdds_python_branch = "origin/{}".format(fastdds_python_branch)
401-
elif docs_branch and fastdds_python.refs.__contains__(
402-
"origin/{}".format(docs_branch)
403-
):
404-
fastdds_python_branch = "origin/{}".format(docs_branch)
405440
else:
406441
print(
407-
'Fast DDS Python does not have either "{}" or "{}" branches'.format(
408-
fastdds_python_branch, docs_branch
442+
'Fast DDS Python does not have branch "{}"; falling back to master'.format(
443+
fastdds_python_branch
409444
)
410445
)
411446
fastdds_python_branch = "origin/master"
@@ -480,10 +515,34 @@ def configure_doxyfile(
480515
"sphinx_copybutton",
481516
"sphinx_design",
482517
"sphinx.ext.autodoc", # Document Pydoc documentation from Python bindings.
518+
"sphinx.ext.extlinks",
483519
"sphinx_substitution_extensions",
484520
"sphinx_toolbox.collapse",
485521
]
486522

523+
extlinks = {
524+
# Fast-DDS repo (tree = directory, blob = file)
525+
"fastdds-tree": (
526+
f"https://github.com/eProsima/Fast-DDS/tree/{fastdds_fallback_branch}/%s", "%s"
527+
),
528+
"fastdds-blob": (
529+
f"https://github.com/eProsima/Fast-DDS/blob/{fastdds_fallback_branch}/%s", "%s"
530+
),
531+
# Fast-DDS-python repo
532+
"fastdds-python-tree": (
533+
f"https://github.com/eProsima/Fast-DDS-Python/tree/{fastdds_python_fallback_branch}/%s", "%s"
534+
),
535+
# Fast-DDS-docs repo (code examples embedded in the docs repo)
536+
"fastdds-docs-tree": (
537+
f"https://github.com/eProsima/Fast-DDS-docs/tree/{fastdds_docs_fallback_branch}/%s", "%s"
538+
),
539+
# Fast-DDS-Gen raw files
540+
"fastddsgen-raw": (
541+
f"https://raw.githubusercontent.com/eProsima/Fast-DDS-Gen/{fastdds_gen_fallback_branch}/%s",
542+
"%s",
543+
),
544+
}
545+
487546
sphinx_tabs_disable_css_loading = False
488547
sphinx_tabs_disable_tab_closing = True
489548

@@ -684,6 +743,10 @@ def configure_doxyfile(
684743
<span class="sd-badge sd-outline-primary sd-text-primary" title="Exclusive to Fast DDS Pro">Pro</span>
685744
686745
.. |ProjectVersion| replace:: {version}
746+
747+
.. |FastDDSBranch| replace:: {fastdds_fallback_branch}
748+
749+
.. |FastDDSPythonBranch| replace:: {fastdds_python_fallback_branch}
687750
"""
688751

689752

docs/fastdds/discovery/discovery_server.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ Full example
315315
^^^^^^^^^^^^
316316

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

321322
Server side setup
322323
"""""""""""""""""

docs/fastdds/discovery/static.rst

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

6969
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/master/examples/cpp>`_.
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/master/fastdds_python_examples>`_.
12+
:fastdds-python-tree:`here <fastdds_python_examples>`.

docs/fastdds/rtps_layer/rtps_layer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ explaining the new features it presents.
4141
We recommend you to look at the example describing how to use the RTPS layer that come with the distribution
4242
while reading this section.
4343
It is located in
44-
`examples/cpp/rtps <https://github.com/eProsima/Fast-DDS/tree/master/examples/cpp/rtps>`_.
44+
:fastdds-tree:`examples/cpp/rtps <examples/cpp/rtps>`.
4545

4646
Managing the Participant
4747
^^^^^^^^^^^^^^^^^^^^^^^^

docs/fastdds/security/access_control_plugin/access_control_plugin.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ The following is an example of the Domain Governance XML file contents.
105105
:end-before: <!--><-->
106106
:linenos:
107107

108-
The `Governance XSD file <https://github.com/eProsima/Fast-DDS/blob/master/resources/xsd/governance.xsd>`_ and
108+
The :fastdds-blob:`Governance XSD file <resources/xsd/governance.xsd>` and
109109
the
110-
`Governance XML example <https://github.com/eProsima/Fast-DDS/blob/master/examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`_
110+
:fastdds-blob:`Governance XML example <examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`
111111
can also be downloaded from the `eProsima Fast DDS Github repository <https://github.com/eProsima/Fast-DDS>`_.
112112

113113
Domain Rules
@@ -442,9 +442,9 @@ The following is an example of the DomainParticipant Permissions XML file conten
442442
:end-before: <!--><-->
443443
:linenos:
444444

445-
The `Permissions XSD file <https://github.com/eProsima/Fast-DDS/blob/master/resources/xsd/governance.xsd>`_ and
445+
The :fastdds-blob:`Permissions XSD file <resources/xsd/governance.xsd>` and
446446
the
447-
`Permissions XML example <https://github.com/eProsima/Fast-DDS/blob/master/examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`_
447+
:fastdds-blob:`Permissions XML example <examples/cpp/dds/SecureHelloWorldExample/certs/governance.xml>`
448448
can also be downloaded from the `eProsima Fast DDS Github repository <https://github.com/eProsima/Fast-DDS>`_.
449449

450450
Grant Section

docs/fastdds/transport/shared_memory/shared_memory.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,6 @@ Delivery Mechanisms example
269269
---------------------------
270270

271271
A hello world example suitable for supported delivery mechanisms can be found in the
272-
`delivery_mechanisms folder <https://github.com/eProsima/Fast-DDS/tree/master/examples/cpp/delivery_mechanisms>`_.
272+
:fastdds-tree:`delivery_mechanisms folder <examples/cpp/delivery_mechanisms>`.
273273
It shows a publisher and a subscriber that communicate through the desired delivery mechanism (which can be set to
274274
shared memory only).

docs/fastdds/transport/tcp/tcp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,6 @@ Delivery Mechanisms example
461461
---------------------------
462462

463463
A hello world example suitable for supported delivery mechanisms can be found in the
464-
`delivery_mechanisms folder <https://github.com/eProsima/Fast-DDS/tree/master/examples/cpp/delivery_mechanisms>`_.
464+
:fastdds-tree:`delivery_mechanisms folder <examples/cpp/delivery_mechanisms>`.
465465
It shows a publisher and a subscriber that communicate through the desired delivery mechanism (which can be set to TCP
466466
only).

docs/fastdds/use_cases/request_reply/request_reply.rst

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

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

5454
Getting started
5555
---------------
@@ -147,4 +147,3 @@ For this the client application has to compare the stored |SampleIdentity-api| w
147147
:start-after: //REQUEST_REPLY_EXAMPLE_CLIENT_RECEIVE_REPLY
148148
:end-before: //!
149149

150-
.. _Fast DDS repository: https://github.com/eProsima/Fast-DDS/tree/master/examples/cpp/request_reply

0 commit comments

Comments
 (0)