Skip to content

Commit 25b7d86

Browse files
emiliocuestafmergify[bot]
authored andcommitted
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/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
1 parent 64d76a5 commit 25b7d86

31 files changed

Lines changed: 820 additions & 47 deletions

File tree

docs/conf.py

Lines changed: 139 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,25 @@ def select_css(html_css_dir):
207207

208208

209209
def get_git_branch():
210-
"""Get the git branch this repository is currently on."""
210+
"""Get the git branch this repository is currently on.
211+
212+
On Read the Docs the repo is checked out in detached-HEAD mode, so
213+
``git name-rev`` returns synthetic names like ``remotes/origin/external-1234``
214+
instead of the real branch. A workaround is provided using
215+
``READTHEDOCS_VERSION_TYPE`` and ``READTHEDOCS_VERSION`` according to the build type:
216+
- ``"branch"`` builds: READTHEDOCS_VERSION is the branch name (e.g. ``"3.6.x"``) → use it.
217+
- ``"tag"`` builds: READTHEDOCS_VERSION is the tag name (e.g. ``"v3.6.0"``) → use it.
218+
- ``"external"`` (PR preview) builds: READTHEDOCS_VERSION is the PR number (e.g. ``"1241"``)
219+
which is not a valid git ref. In this case we return None so resolve_fallback_branch falls
220+
back to its default instead of generating broken GitHub URLs.
221+
- Local builds: READTHEDOCS_VERSION_TYPE is unset → fall back to git name-rev.
222+
"""
223+
rtd_type = os.environ.get("READTHEDOCS_VERSION_TYPE")
224+
if rtd_type in ("branch", "tag"):
225+
return os.environ.get("READTHEDOCS_VERSION")
226+
if rtd_type == "external":
227+
return None
228+
211229
path_to_here = os.path.abspath(os.path.dirname(__file__))
212230

213231
# Invoke git to get the current branch which we use to get the theme
@@ -229,12 +247,28 @@ def get_git_branch():
229247
return p.communicate()[0].decode().rstrip()
230248

231249
except Exception:
250+
# Local build without git or some error occurred
232251
print("Could not get the branch")
233252

234253
# Couldn't figure out the branch probably due to an error
235254
return None
236255

237256

257+
def resolve_fallback_branch(env_var, docs_branch, default="master"):
258+
"""
259+
Resolve the branch to use for GitHub links.
260+
261+
Priority:
262+
1. Environment variable ``env_var`` (e.g. FASTDDS_BRANCH)
263+
2. Current documentation branch (``docs_branch``)
264+
3. Hard-coded ``default``
265+
266+
This mirrors the checkout logic used in the ReadTheDocs clone block so
267+
that extlinks and the actual checkout always point at the same branch.
268+
"""
269+
return os.environ.get(env_var) or docs_branch or default
270+
271+
238272
def configure_doxyfile(
239273
doxyfile_in,
240274
doxyfile_out,
@@ -282,6 +316,27 @@ def configure_doxyfile(
282316
# Header files
283317
input_dir = os.path.abspath("{}/fastdds/include/fastdds".format(project_binary_dir))
284318

319+
# Current branch of the documentation repository — resolved once, used everywhere.
320+
docs_branch = get_git_branch()
321+
if docs_branch:
322+
print('Current documentation branch is "{}"'.format(docs_branch))
323+
else:
324+
print("Current documentation branch could not be determined; " \
325+
"GitHub links will point to default branches instead of the corresponding branch.")
326+
327+
# Resolve GitHub link branches: env var → current docs branch → default.
328+
# Computed here so they are available both in the ReadTheDocs clone block and in extlinks.
329+
fastdds_fallback_branch = resolve_fallback_branch("FASTDDS_BRANCH", docs_branch, "master")
330+
fastdds_docs_fallback_branch = resolve_fallback_branch("FASTDDS_DOCS_BRANCH", docs_branch, "master")
331+
fastdds_python_fallback_branch = resolve_fallback_branch("FASTDDS_PYTHON_BRANCH", docs_branch, "master")
332+
fastdds_gen_fallback_branch = resolve_fallback_branch("FASTDDS_GEN_BRANCH", docs_branch, "master")
333+
334+
print("Fallback branches for GitHub links:")
335+
print(' Fast-DDS: "{}"'.format(fastdds_fallback_branch))
336+
print(' Fast-DDS-docs: "{}"'.format(fastdds_docs_fallback_branch))
337+
print(' Fast-DDS-Python: "{}"'.format(fastdds_python_fallback_branch))
338+
print(' Fast-DDS-Gen: "{}"'.format(fastdds_gen_fallback_branch))
339+
285340
# Check if we're running on Read the Docs' servers
286341
read_the_docs_build = os.environ.get("READTHEDOCS", None) == "True"
287342
if read_the_docs_build:
@@ -314,6 +369,7 @@ def configure_doxyfile(
314369
fastdds_repo_name,
315370
)
316371

372+
<<<<<<< HEAD
317373
# Documentation repository branch
318374
docs_branch = get_git_branch()
319375
print('Current documentation branch is "{}"'.format(docs_branch))
@@ -325,13 +381,16 @@ def configure_doxyfile(
325381
# Else try with current documentation branch
326382
# Else checkout to 3.2.x
327383
if fastdds_branch and fastdds.refs.__contains__("origin/{}".format(fastdds_branch)):
384+
=======
385+
# Verify the desired branch actually exists in the cloned remote, falling back to master if not.
386+
fastdds_branch = fastdds_fallback_branch
387+
if fastdds.refs.__contains__("origin/{}".format(fastdds_branch)):
388+
>>>>>>> 60e9c7d (Add fallback branch for master links (#1241))
328389
fastdds_branch = "origin/{}".format(fastdds_branch)
329-
elif docs_branch and fastdds.refs.__contains__("origin/{}".format(docs_branch)):
330-
fastdds_branch = "origin/{}".format(docs_branch)
331390
else:
332391
print(
333-
'Fast DDS does not have either "{}" or "{}" branches'.format(
334-
fastdds_branch, docs_branch
392+
'Fast DDS does not have branch "{}"; falling back to master'.format(
393+
fastdds_branch
335394
)
336395
)
337396
fastdds_branch = "origin/3.2.x"
@@ -347,6 +406,7 @@ def configure_doxyfile(
347406
fastdds_python_repo_name,
348407
)
349408

409+
<<<<<<< HEAD
350410
# User specified Fast DDS branch
351411
fastdds_python_branch = os.environ.get("FASTDDS_PYTHON_BRANCH", None)
352412

@@ -356,15 +416,16 @@ def configure_doxyfile(
356416
if fastdds_python_branch and fastdds_python.refs.__contains__(
357417
"origin/{}".format(fastdds_python_branch)
358418
):
419+
=======
420+
# Verify the desired branch actually exists in the cloned remote, falling back to master if not.
421+
fastdds_python_branch = fastdds_python_fallback_branch
422+
if fastdds_python.refs.__contains__("origin/{}".format(fastdds_python_branch)):
423+
>>>>>>> 60e9c7d (Add fallback branch for master links (#1241))
359424
fastdds_python_branch = "origin/{}".format(fastdds_python_branch)
360-
elif docs_branch and fastdds_python.refs.__contains__(
361-
"origin/{}".format(docs_branch)
362-
):
363-
fastdds_python_branch = "origin/{}".format(docs_branch)
364425
else:
365426
print(
366-
'Fast DDS Python does not have either "{}" or "{}" branches'.format(
367-
fastdds_python_branch, docs_branch
427+
'Fast DDS Python does not have branch "{}"; falling back to master'.format(
428+
fastdds_python_branch
368429
)
369430
)
370431
fastdds_python_branch = "origin/2.2.x"
@@ -444,9 +505,37 @@ def configure_doxyfile(
444505
"sphinx_copybutton",
445506
"sphinx_design",
446507
"sphinx.ext.autodoc", # Document Pydoc documentation from Python bindings.
508+
<<<<<<< HEAD
509+
=======
510+
"sphinx.ext.extlinks",
511+
"sphinx_substitution_extensions",
512+
>>>>>>> 60e9c7d (Add fallback branch for master links (#1241))
447513
"sphinx_toolbox.collapse",
448514
]
449515

516+
extlinks = {
517+
# Fast-DDS repo (tree = directory, blob = file)
518+
"fastdds-tree": (
519+
f"https://github.com/eProsima/Fast-DDS/tree/{fastdds_fallback_branch}/%s", "%s"
520+
),
521+
"fastdds-blob": (
522+
f"https://github.com/eProsima/Fast-DDS/blob/{fastdds_fallback_branch}/%s", "%s"
523+
),
524+
# Fast-DDS-python repo
525+
"fastdds-python-tree": (
526+
f"https://github.com/eProsima/Fast-DDS-Python/tree/{fastdds_python_fallback_branch}/%s", "%s"
527+
),
528+
# Fast-DDS-docs repo (code examples embedded in the docs repo)
529+
"fastdds-docs-tree": (
530+
f"https://github.com/eProsima/Fast-DDS-docs/tree/{fastdds_docs_fallback_branch}/%s", "%s"
531+
),
532+
# Fast-DDS-Gen raw files
533+
"fastddsgen-raw": (
534+
f"https://raw.githubusercontent.com/eProsima/Fast-DDS-Gen/{fastdds_gen_fallback_branch}/%s",
535+
"%s",
536+
),
537+
}
538+
450539
sphinx_tabs_disable_css_loading = False
451540
sphinx_tabs_disable_tab_closing = True
452541

@@ -611,7 +700,46 @@ def configure_doxyfile(
611700

612701
html_use_smartypants = True
613702

703+
<<<<<<< HEAD
614704
html_css_files = [select_css(script_path)]
705+
=======
706+
# The CSS files referenced here should have a path relative to the _static folder.
707+
# We use static_relative(download_file(...)) to ensure the resulting paths are relative to "_static".
708+
html_css_files = [
709+
static_relative(
710+
download_file(
711+
"https://raw.githubusercontent.com/eProsima/all-docs/master/source/_static/css/eprosima-furo.css",
712+
"{}/_static/css/eprosima-furo.css".format(script_path),
713+
)
714+
),
715+
static_relative(
716+
download_file(
717+
"https://raw.githubusercontent.com/eProsima/all-docs/master/source/_static/css/pro-badge.css",
718+
"{}/_static/css/pro-badge.css".format(script_path),
719+
)
720+
),
721+
]
722+
723+
# Custom substitutions that are included at the beginning of every source file.
724+
# |Pro|: badge with PRO text. Place it after titles where needed as follows:
725+
# Title |Pro|
726+
# ===========
727+
# rst_prolog = r"""
728+
# .. |Pro| replace:: :bdg-primary-line:`Pro`
729+
# """
730+
rst_prolog = f"""
731+
.. |Pro| raw:: html
732+
733+
<span class="sd-badge sd-outline-primary sd-text-primary" title="Exclusive to Fast DDS Pro">Pro</span>
734+
735+
.. |ProjectVersion| replace:: {version}
736+
737+
.. |FastDDSBranch| replace:: {fastdds_fallback_branch}
738+
739+
.. |FastDDSPythonBranch| replace:: {fastdds_python_fallback_branch}
740+
"""
741+
742+
>>>>>>> 60e9c7d (Add fallback branch for master links (#1241))
615743

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

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)