Skip to content

Commit 1bba850

Browse files
authored
Enable adding any folder into docs (#431)
1 parent b2e62cd commit 1bba850

21 files changed

Lines changed: 472 additions & 14 deletions

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
extensions = [
1919
"score_sphinx_bundle",
2020
]
21+
22+
score_any_folder_mapping = {
23+
"../src/extensions/docs": "internals/extensions",
24+
}

docs/how-to/any_folder.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Use Any Folder for Documentation
2+
================================
3+
4+
Generally, your documentation must be ``docs/``,
5+
but the RST files for a module may live closer to the code they describe,
6+
for example in ``src/my_module/docs/``.
7+
You can symlink the folders by adding to your ``conf.py``:
8+
9+
.. code-block:: python
10+
11+
score_any_folder_mapping = {
12+
"../score/containers/docs": "component/containers",
13+
}
14+
15+
With this configuration, all files in ``score/containers/docs/`` become available at ``docs/component/containers/``.
16+
17+
If you have ``docs/component/overview.rst``, for example,
18+
you can include the component documentation via ``toctree``:
19+
20+
.. code-block:: rst
21+
22+
.. toctree::
23+
24+
containers/index
25+
26+
Only relative links are allowed.
27+
28+
The symlinks will show up in your sources.
29+
**Don't commit the symlinks to git!**

docs/how-to/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Here you find practical guides on how to use docs-as-code.
1616
source_to_doc_links
1717
test_to_doc_links
1818
add_extensions
19+
any_folder

src/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ filegroup(
3737
srcs = glob(
3838
["*.py"],
3939
) + [
40+
"//src/extensions/score_any_folder:all_sources",
4041
"//src/extensions/score_draw_uml_funcs:all_sources",
4142
"//src/extensions/score_header_service:all_sources",
4243
"//src/extensions/score_layout:all_sources",

src/extensions/docs/any_folder.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
Any Folder
16+
==========
17+
18+
The extension ``score_any_folder`` allows documentation roots to stay in ``docs/``
19+
while pulling in source files from anywhere else in the repository.
20+
21+
It does this by creating symlinks inside the Sphinx source directory (``confdir``) that point to the configured external directories.
22+
Sphinx then discovers and buildsthose files as if they were part of ``docs/`` from the start.
23+
24+
The extension hooks into the ``builder-inited`` event,
25+
which fires before Sphinx reads any documents.
26+
27+
Difference to Sphinx-Collections
28+
--------------------------------
29+
30+
The extension `sphinx-collections <https://sphinx-collections.readthedocs.io/>`_
31+
is very similar to this extension.
32+
We use it for including external modules
33+
as it allows conditional inclusion
34+
and we need to switch between "normal" and "combo" builds.
35+
36+
The relevant difference is that this extension allows to include folders to anywhere
37+
and is not restricted to a ``_collections/`` folder.
38+
We consider this additional control over folder placement necessary.
File renamed without changes.
File renamed without changes.
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
.. # *******************************************************************************
2-
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3-
#
4-
# See the NOTICE file(s) distributed with this work for additional
5-
# information regarding copyright ownership.
6-
#
7-
# This program and the accompanying materials are made available under the
8-
# terms of the Apache License Version 2.0 which is available at
9-
# https://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# SPDX-License-Identifier: Apache-2.0
12-
# *******************************************************************************
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
1314
1415
.. _extensions:
1516

@@ -71,6 +72,16 @@ Hello there
7172
`ubCode <https://ubcode.useblocks.com>`__ VS Code extension.
7273
Getting IDE support for Sphinx-Needs in a Bazel context made easy.
7374

75+
.. grid-item-card::
76+
77+
Any Folder
78+
^^^^^^^^^^
79+
80+
Learn about the :doc:`any_folder` extension that creates symlinks
81+
from arbitrary repository locations into the docs folder,
82+
allowing Sphinx to discover and build source files
83+
that live outside the documentation root.
84+
7485

7586

7687
.. toctree::
@@ -83,3 +94,4 @@ Hello there
8394
Source Code Linker <source_code_linker>
8495
Extension Guide <extension_guide>
8596
Sync TOML <sync_toml>
97+
Any Folder <any_folder>
File renamed without changes.

0 commit comments

Comments
 (0)