Sphinx¶
Cross-referencing symbols¶
Sphinx provides several roles to create cross-references to Python symbols in the extra_platforms module. These roles work in both MyST Markdown and reStructuredText formats.
Available roles¶
{func}— Reference a function (e.g.,is_linux(),current_traits()){data}— Reference a module-level constant (e.g.,UBUNTU,skip_linux){class}— Reference a class (e.g.,Platform,Architecture,Group)
Note
Pytest decorators like skip_linux are MarkDecorator objects. Use {data} for inline cross-references. For API documentation, the built-in autodecorator directive renders them with the @ prefix (see pytest.md).
Syntax¶
Use curly braces and backticks:
Check the current platform with {func}`~extra_platforms.is_linux`.
The {class}`~extra_platforms.Platform` class represents operating systems.
Pre-defined platforms like {data}`~extra_platforms.UBUNTU` are available.
See the {mod}`extra_platforms.detection` module for detection functions.
Use colons and backticks:
Check the current platform with :func:`~extra_platforms.is_linux`.
The :class:`~extra_platforms.Platform` class represents operating systems.
Pre-defined platforms like :data:`~extra_platforms.UBUNTU` are available.
See the :mod:`extra_platforms.detection` module for detection functions.
Which renders as:
Check the current platform with
is_linux().The
Platformclass represents operating systems.Pre-defined platforms like
UBUNTUare available.See the
extra_platforms.detectionmodule for detection functions.
The tilde (~) prefix displays only the symbol name without the full module path:
{func}`~extra_platforms.is_linuxrenders asis_linux(){func}`extra_platforms.is_linuxrenders asextra_platforms.is_linux()
Setting a default module¶
To avoid repeating the module name, use the currentmodule directive:
```{py:currentmodule} extra_platforms
```
Use {func}`is_linux` or {func}`is_windows` to check platforms.
.. py:currentmodule:: extra_platforms
Use :func:`is_linux` or :func:`is_windows` to check platforms.
Which renders as:
Use
is_linux()oris_windows()to check platforms.
Cross-reference resolution¶
Symbols exposed at the root extra_platforms module automatically link to their actual definition location:
current_traits()links todetection.htmlPlatformlinks totrait.htmlUBUNTUlinks toplatform_data.html
This ensures documentation remains accurate even when symbols are re-exported from submodules.
Reference matrix¶
This section demonstrates all syntax variations for referencing different object types in the extra_platforms module. All examples use the short-path format with the currentmodule directive.
MyST syntax |
reST syntax |
Rendering |
Description |
|---|---|---|---|
Traits |
|||
|
|
Platform trait symbol |
|
|
|
Platform trait detection function |
|
|
|
Platform trait skip decorator |
|
|
|
Platform trait unless decorator |
|
|
|
Architecture trait symbol |
|
|
|
Architecture trait detection function |
|
|
|
Architecture trait skip decorator |
|
|
|
Architecture trait unless decorator |
|
|
|
Shell trait symbol |
|
|
|
Shell trait detection function |
|
|
|
Shell trait skip decorator |
|
|
|
Shell trait unless decorator |
|
|
|
CI trait symbol |
|
|
|
CI trait detection function |
|
|
|
CI trait skip decorator |
|
|
|
CI trait unless decorator |
|
|
|
Terminal trait symbol |
|
|
|
Terminal trait detection function |
|
|
|
Terminal trait skip decorator |
|
|
|
Terminal trait unless decorator |
|
|
|
Agent trait symbol |
|
|
|
Agent trait detection function |
|
|
|
Agent trait skip decorator |
|
|
|
Agent trait unless decorator |
|
Groups |
|||
|
|
Regular group symbol |
|
|
|
Regular group detection function |
|
|
|
Regular group skip decorator |
|
|
|
Regular group unless decorator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unknown platform symbol |
|
|
|
Unknown platform detection function |
|
|
|
Unknown platform skip decorator |
|
|
|
Unknown platform unless decorator |
|
|
|
Unknown architecture symbol |
|
|
|
Unknown architecture detection function |
|
|
|
Unknown architecture skip decorator |
|
|
|
Unknown architecture unless decorator |
|
|
|
Unknown shell symbol |
|
|
|
Unknown shell detection function |
|
|
|
Unknown shell skip decorator |
|
|
|
Unknown shell unless decorator |
|
|
|
Unknown CI symbol |
|
|
|
Unknown CI detection function |
|
|
|
Unknown CI skip decorator |
|
|
|
Unknown CI unless decorator |
|
|
|
Unknown terminal symbol |
|
|
|
Unknown terminal detection function |
|
|
|
Unknown terminal skip decorator |
|
|
|
Unknown terminal unless decorator |
|
|
|
Unknown agent symbol |
|
|
|
Unknown agent detection function |
|
|
|
Unknown agent skip decorator |
|
|
|
Unknown agent unless decorator |
|
|
|
Group with |
|
|
|
Group function with |
|
Detection Methods |
|||
|
|
Current platform detection function |
|
|
|
Current architecture detection function |
|
|
|
Current shell detection function |
|
|
|
Current CI detection function |
|
|
|
Current terminal detection function |
|
|
|
Current agent detection function |
|
|
|
All current traits detection function |
|
Classes |
|||
|
|
Platform trait class |
|
|
|
Architecture trait class |
|
|
|
Shell trait class |
|
|
|
Terminal trait class |
|
|
|
CI trait class |
|
|
|
Agent trait class |
|
|
|
Base trait class |
|
|
|
Group class |
|
Utilities |
|||
|
|
Reduce utility function |
|
|
|
Extract group members utility function |
|
|
|
Traits from IDs utility function |
|
|
|
Groups from IDs utility function |
|
|
|
Cache invalidation utility function |
Tip
All the examples in this reference matrix are tested in tests/test_sphinx_crossrefs.py to ensure cross-references resolve correctly in the built documentation.
Third-party cross-references¶
Other projects can link to extra_platforms symbols in their own Sphinx documentation via intersphinx.
Setup¶
Add extra_platforms to the intersphinx_mapping in your project’s conf.py:
extensions = [
"sphinx.ext.intersphinx",
# ...
]
intersphinx_mapping = {
"extra_platforms": ("https://kdeldycke.github.io/extra-platforms/", None),
}
Syntax¶
Cross-references use the inventory:target format. The inventory name is extra_platforms (matching the key in intersphinx_mapping), and the target is the fully-qualified Python symbol:
Skip this test on Linux with {data}`extra_platforms:extra_platforms.pytest.skip_linux`.
Detect macOS at runtime with {func}`extra_platforms:extra_platforms.is_macos`.
The {class}`extra_platforms:extra_platforms.Group` class supports set operations.
Use {data}`extra_platforms:extra_platforms.UBUNTU` for the Ubuntu platform constant.
Skip this test on Linux with :data:`extra_platforms:extra_platforms.pytest.skip_linux`.
Detect macOS at runtime with :func:`extra_platforms:extra_platforms.is_macos`.
The :class:`extra_platforms:extra_platforms.Group` class supports set operations.
Use :data:`extra_platforms:extra_platforms.UBUNTU` for the Ubuntu platform constant.
The tilde (~) prefix works the same way with the inventory qualifier:
{func}`~extra_platforms:extra_platforms.is_linux`renders asis_linux(){func}`extra_platforms:extra_platforms.is_linux`renders asextra_platforms.is_linux()
Inspecting the inventory¶
To list all available symbols in the published inventory:
$ python -m sphinx.ext.intersphinx https://kdeldycke.github.io/extra-platforms/objects.inv