Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 4 additions & 8 deletions docs/rez_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import rez.cli._main
import rez.cli._util
import rez.rezconfig
from rez.utils.sphinxext import PkgDefDomain as BasePkgDefDomain
from rez.utils.sphinxext import RexDomain as BaseRexDomain
import docutils.nodes
import sphinx.util.nodes
import sphinx.application
Expand Down Expand Up @@ -138,19 +140,13 @@ class BareNamePythonDomain(sphinx.domains.python.PythonDomain):



class RexDomain(BareNamePythonDomain):
class RexDomain(BareNamePythonDomain, BaseRexDomain):
"""Domain for rex (Rez EXecution language) objects used in commands() functions."""

name = "rex"
label = "Rex"


class PkgDefDomain(BareNamePythonDomain):
class PkgDefDomain(BareNamePythonDomain, BasePkgDefDomain):
"""Domain for package definition attributes in package.py files."""

name = "pkgdef"
label = "Package Definition"


def convert_rez_config_to_rst() -> list[str]:
with open(rez.rezconfig.__file__) as fd:
Expand Down
1 change: 1 addition & 0 deletions docs/source/guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ This section contains various user guides.

update_to_3
developing_your_own_plugin
linking_to_rez_documentation
67 changes: 67 additions & 0 deletions docs/source/guides/linking_to_rez_documentation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
============================
Linking to rez documentation
============================

Sphinx projects can use `intersphinx <https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html>`_
to link to objects in the rez documentation. Rez provides the
``rez.utils.sphinxext`` Sphinx extension for its two custom domains:

``pkgdef``
Package definition attributes and functions documented in
:doc:`../package_definition`.

``rex``
Objects available to package commands documented in
:doc:`../package_commands`.

Configuration
=============

Install rez and Sphinx in the environment that builds your documentation. Rez
does not install or pin Sphinx, so your project can select the appropriate Sphinx
version.

Add the rez extension and intersphinx mapping to your Sphinx ``conf.py`` file:

.. code-block:: python

extensions = [
"sphinx.ext.intersphinx",
"rez.utils.sphinxext",
]

intersphinx_mapping = {
"rez": ("https://docs.rez-project.io/en/stable/", None),
}

If your project already defines ``extensions`` or ``intersphinx_mapping``, add
these entries to the existing values instead of replacing them.

Creating links
==============

Use an explicit external reference to select the rez inventory, domain, and
object type:

.. code-block:: rst

:external+rez:pkgdef:attr:`requires`
:external+rez:pkgdef:func:`commands`
:external+rez:rex:attr:`this.root`
:external+rez:rex:func:`alias`

The ``external+rez`` prefix selects the ``rez`` entry in
``intersphinx_mapping``. The next two components select the domain and role.

Compatibility
=============

Rez intentionally keeps this integration small and does not install or pin a
Sphinx version. Documentation projects can select and manage the Sphinx version
appropriate for their own builds.

We aim to keep ``rez.utils.sphinxext`` compatible across Sphinx and rez releases, but
not every combination is guaranteed. Changes to Sphinx's domain or intersphinx
APIs may require an updated rez extension. For reproducible documentation
builds, projects should pin their documentation dependencies and treat
unresolved references as errors.
42 changes: 42 additions & 0 deletions src/rez/utils/sphinxext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the Rez Project


"""Lightweight Sphinx domains for referencing objects in Rez's documentation.

Rez's own documentation adds its directive implementations in ``rez_sphinxext``.
Consumers only need these domain names and the inherited Python roles for
intersphinx resolution.
"""

from rez.utils import _rez_version

from sphinx.domains.python import PythonDomain

__all__ = ["setup"]


class RexDomain(PythonDomain):
"""Domain for Rex objects used in ``commands()`` functions."""

name = "rex"
label = "Rex"


class PkgDefDomain(PythonDomain):
"""Domain for attributes in Rez package definition files."""

name = "pkgdef"
label = "Package Definition"


def setup(app):
"""Register Rez's Sphinx domains."""
app.add_domain(RexDomain)
app.add_domain(PkgDefDomain)

return {
"version": _rez_version,
"parallel_read_safe": True,
"parallel_write_safe": True,
}
Loading