Skip to content

Commit 958b098

Browse files
[SymForce] Get cc_sym docs to generate correctly
**Why this PR:** We already have sphinx generate docs for everything in symforce. The problem, however, is sphinx will only generate docs for `cc_sym.py`, which merely re-exports the contents of `cc_sym.so`, leaving all of the contained classes and functions undocumented. **The core fix:** To fix this, nothing needs to be done for `make docs_apidoc`, as that seems to only generate `.rst` files noting that docs need to be generated for `cc_sym`. Instead, I just changed the file extension of `cc_sym.py` so sphinx will ignore it, and then copied in `cc_sym.so` so sphinx will use that module to generate the docs for `cc_sym` instead. **Note on getting the path of cc_sym.so:** To find `cc_sym.so`, I used the environment variable `PY_EXTENSION_MODULE_PATH`, and defaulted it to `build/pybind` so it works with the default settings. This is brittle though, as if one wants to change the location where the files are built, the `PY_EXTENSION_MODULE_PATH` won't be updated. It would better to instead use the cmake variable `SYMFORCE_PY_EXTENSION_MODULE_OUTPUT_PATH`, which is the source of truth for where `cc_sym.so` will get built, or perhaps `symforce.path_util.cc_sym_install_dir()`, which gets its value from the cmake variable, but there isn't an easy way to do that with our handwritten `Makefile` that I know of. GitOrigin-RevId: 8e7910920d8de6a47af5173ab6e2eb7470bf4579
1 parent 954d895 commit 958b098

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,17 @@ docs_apidoc:
165165
doxygen docs/Doxyfile-gen-cpp
166166
$(PYTHON) -m breathe.apidoc -o docs/api-cpp --project api-cpp $(BUILD_DIR)/doxygen-cpp/xml
167167
$(PYTHON) -m breathe.apidoc -o docs/api-gen-cpp --project api-gen-cpp $(BUILD_DIR)/doxygen-gen-cpp/xml
168+
# The generated symforce.cc_sym.rst file says to generate docs for symforce.cc_sym. However, that file
169+
# only rexports cc_sym, and consequently the actual contents of cc_sym are not documented. We replace
170+
# symforce.cc_sym.rst with a copy which is the same except it says to generate docs for cc_sym instead.
171+
rm docs/api/symforce.cc_sym.rst
172+
cp docs/symforce.cc_sym.rst docs/api/symforce.cc_sym.rst
173+
174+
PY_EXTENSION_MODULE_PATH?=$(BUILD_DIR)/pybind
168175

169176
docs_html: docs_apidoc
170-
SYMFORCE_LOGLEVEL=WARNING $(PYTHON) -m sphinx -b html docs $(DOCS_DIR) -j4
177+
export PYTHONPATH=$(PY_EXTENSION_MODULE_PATH):$(PYTHONPATH); \
178+
SYMFORCE_LOGLEVEL=WARNING $(PYTHON) -m sphinx -b html docs $(DOCS_DIR) -j $$(nproc)
171179

172180
docs: docs_clean docs_html
173181

docs/symforce.cc_sym.rst

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
symforce.cc\_sym module
2+
=======================
3+
4+
..
5+
Comment: This file exists because we want docs for cc_sym, not symforce.cc_sym.
6+
This file differs only from the one generated by api-docs by the target module.
7+
8+
.. automodule:: cc_sym
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:

0 commit comments

Comments
 (0)