Skip to content

Commit 086f554

Browse files
1 parent fbfd3df commit 086f554

9 files changed

+1039
-1028
lines changed

documentation_instructions.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ <h1 id="previewing-changes">Previewing changes</h1>
190190
<span class="c"># Speed up the preview by only processing certain tool(s):</span>
191191
<span class="nv">$ </span>bazel run //doc:pages <span class="nt">--</span> <span class="nt">--serve</span> <span class="c"># Only the main site.</span>
192192
<span class="nv">$ </span>bazel run //doc/doxygen_cxx:build <span class="nt">--</span> <span class="nt">--serve</span> <span class="c"># Only the C++ API reference.</span>
193-
<span class="nv">$ </span>bazel run //doc/pydrake:build <span class="nt">--</span> <span class="nt">--serve</span> <span class="c"># Only the Python API reference.</span>
193+
<span class="nv">$ </span>bazel run //bindings/generated_docstrings:regenerate <span class="o">&amp;&amp;</span> <span class="se">\</span>
194+
<span class="c"># bazel run //doc/pydrake:build -- --serve # Only the Python API reference.</span>
194195
<span class="nv">$ </span>bazel run //doc/styleguide:build <span class="nt">--</span> <span class="nt">--serve</span> <span class="c"># Only the Style Guide.</span>
195196

196197
<span class="c"># Further speed up preview generating only some API modules, e.g., math:</span>
197198
<span class="nv">$ </span>bazel run //doc/doxygen_cxx:build <span class="nt">--</span> <span class="nt">--serve</span> drake.math <span class="c"># C++ math API.</span>
198-
<span class="nv">$ </span>bazel run //doc/pydrake:build <span class="nt">--</span> <span class="nt">--serve</span> pydrake.math <span class="c"># Python math API.</span>
199+
<span class="nv">$ </span>bazel run //bindings/generated_docstrings:regenerate <span class="o">&amp;&amp;</span> <span class="se">\</span>
200+
<span class="nv">$ </span> bazel run //doc/pydrake:build <span class="nt">--</span> <span class="nt">--serve</span> pydrake.math <span class="c"># Python math API.</span>
199201
<span class="nv">$ </span>bazel run //doc:build <span class="nt">--</span> <span class="nt">--serve</span> <span class="o">{</span>drake,pydrake<span class="o">}</span>.math <span class="c"># Both at once.</span>
200202

201203
<span class="c"># Further speed up preview by omitting expensive `dot` graphs (C++ API only):</span>

doxygen_cxx/group__python__bindings.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,21 @@ <h3>Bazel</h3>
270270
</ul>
271271
<p><a class="anchor" id="PydrakeDoc"></a></p><h2>Documentation</h2>
272272
<p>Drake uses a modified version of <code>mkdoc.py</code> from <code>pybind11</code>, where <code>libclang</code> Python bindings are used to generate C++ docstrings accessible to the C++ binding code.</p>
273-
<p>These docstrings are available within <code>constexpr struct ... pydrake_doc</code> as <code>const char*</code> values . When these are not available or not suitable for Python documentation, provide custom strings. If this custom string is long, consider placing them in a heredoc string.</p>
274-
<p>An example of incorporating docstrings from <code>pydrake_doc</code>:</p>
275-
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;drake/bindings/pydrake/documentation_pybind.h&quot;</span></div><div class="line"></div><div class="line">PYBIND11_MODULE(math, m) {</div><div class="line"> <span class="keyword">using namespace </span><a class="code" href="namespacedrake_1_1math.html">drake::math</a>;</div><div class="line"> constexpr <span class="keyword">auto</span>&amp; doc = pydrake_doc.drake.math;</div><div class="line"> <span class="keyword">using</span> T = double;</div><div class="line"> py::class_&lt;RigidTransform&lt;T&gt;&gt;(m, <span class="stringliteral">&quot;RigidTransform&quot;</span>, doc.RigidTransform.doc)</div><div class="line"> .def(py::init(), doc.RigidTransform.ctor.doc_0args)</div><div class="line"> ...</div><div class="line"> .def(py::init&lt;<span class="keyword">const</span> <a class="code" href="classdrake_1_1math_1_1_rotation_matrix.html">RotationMatrix&lt;T&gt;</a>&amp;&gt;(), py::arg(<span class="stringliteral">&quot;R&quot;</span>),</div><div class="line"> doc.RigidTransform.ctor.doc_1args_R)</div><div class="line"> .def(py::init&lt;<span class="keyword">const</span> Eigen::Quaternion&lt;T&gt;&amp;, <span class="keyword">const</span> Vector3&lt;T&gt;&amp;&gt;(),</div><div class="line"> py::arg(<span class="stringliteral">&quot;quaternion&quot;</span>), py::arg(<span class="stringliteral">&quot;p&quot;</span>),</div><div class="line"> doc.RigidTransform.ctor.doc_2args_quaternion_p)</div><div class="line"> ...</div><div class="line"> .def(<span class="stringliteral">&quot;set_rotation&quot;</span>, &amp;<a class="code" href="classdrake_1_1math_1_1_rigid_transform.html">RigidTransform&lt;T&gt;::set_rotation</a>, py::arg(<span class="stringliteral">&quot;R&quot;</span>),</div><div class="line"> doc.<a class="code" href="classdrake_1_1math_1_1_rigid_transform.html#a8bedd8c483aaf5bc48587d10d7a3d485">RigidTransform</a>.set_rotation.doc)</div><div class="line"> ...</div><div class="line">}</div></div><!-- fragment --><p>An example of supplying custom strings:</p>
273+
<p>These docstrings are available within nested <code>constexpr struct</code> trees as <code>const char*</code> values. When these are not available or not suitable for Python documentation, provide custom strings. If this custom string is long, consider placing them in a heredoc string.</p>
274+
<p>An example of incorporating docstrings:</p>
275+
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;drake/bindings/generated_docstrings/math.h&quot;</span></div><div class="line"></div><div class="line">PYBIND11_MODULE(math, m) {</div><div class="line"> <span class="keyword">using namespace </span><a class="code" href="namespacedrake_1_1math.html">drake::math</a>;</div><div class="line"> constexpr <span class="keyword">auto</span>&amp; doc = pydrake_doc_math.drake.math;</div><div class="line"> <span class="keyword">using</span> T = double;</div><div class="line"> py::class_&lt;RigidTransform&lt;T&gt;&gt;(m, <span class="stringliteral">&quot;RigidTransform&quot;</span>, doc.RigidTransform.doc)</div><div class="line"> .def(py::init(), doc.RigidTransform.ctor.doc_0args)</div><div class="line"> ...</div><div class="line"> .def(py::init&lt;<span class="keyword">const</span> <a class="code" href="classdrake_1_1math_1_1_rotation_matrix.html">RotationMatrix&lt;T&gt;</a>&amp;&gt;(), py::arg(<span class="stringliteral">&quot;R&quot;</span>),</div><div class="line"> doc.RigidTransform.ctor.doc_1args_R)</div><div class="line"> .def(py::init&lt;<span class="keyword">const</span> Eigen::Quaternion&lt;T&gt;&amp;, <span class="keyword">const</span> Vector3&lt;T&gt;&amp;&gt;(),</div><div class="line"> py::arg(<span class="stringliteral">&quot;quaternion&quot;</span>), py::arg(<span class="stringliteral">&quot;p&quot;</span>),</div><div class="line"> doc.RigidTransform.ctor.doc_2args_quaternion_p)</div><div class="line"> ...</div><div class="line"> .def(<span class="stringliteral">&quot;set_rotation&quot;</span>, &amp;<a class="code" href="classdrake_1_1math_1_1_rigid_transform.html">RigidTransform&lt;T&gt;::set_rotation</a>, py::arg(<span class="stringliteral">&quot;R&quot;</span>),</div><div class="line"> doc.<a class="code" href="classdrake_1_1math_1_1_rigid_transform.html#a8bedd8c483aaf5bc48587d10d7a3d485">RigidTransform</a>.set_rotation.doc)</div><div class="line"> ...</div><div class="line">}</div></div><!-- fragment --><p>An example of supplying custom strings:</p>
276276
<div class="fragment"><div class="line">constexpr <span class="keywordtype">char</span> another_helper_doc[] = R<span class="stringliteral">&quot;&quot;&quot;(</span></div><div class="line"><span class="stringliteral">Another helper docstring. This is really long.</span></div><div class="line"><span class="stringliteral">And has multiple lines.</span></div><div class="line"><span class="stringliteral">)&quot;&quot;&quot;;</span></div><div class="line"><span class="stringliteral"></span></div><div class="line"><span class="stringliteral">PYBIND11_MODULE(example, m) {</span></div><div class="line"><span class="stringliteral"> m.def(</span><span class="stringliteral">&quot;helper&quot;</span>, []() { <span class="keywordflow">return</span> 42; }, <span class="stringliteral">&quot;My helper method&quot;</span>);</div><div class="line"> m.def(<span class="stringliteral">&quot;another_helper&quot;</span>, []() { <span class="keywordflow">return</span> 10; }, another_helper_doc);</div><div class="line">}</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>Consider using scoped aliases to abbreviate both the usage of bound types and the docstring structures. Borrowing from above:</dd></dl>
277-
<div class="fragment"><div class="line">{</div><div class="line"> <span class="keyword">using</span> Class = RigidTransform&lt;T&gt;;</div><div class="line"> constexpr <span class="keyword">auto</span>&amp; cls_doc = doc.RigidTransform;</div><div class="line"> py::class_&lt;Class&gt;(m, <span class="stringliteral">&quot;RigidTransform&quot;</span>, cls_doc.doc)</div><div class="line"> .def(py::init(), cls_doc.ctor.doc_0args)</div><div class="line"> ...</div><div class="line">}</div></div><!-- fragment --><p>To view the documentation rendered in Sphinx: </p><pre class="fragment">bazel run //doc/pydrake:serve_sphinx [-- --browser=false]
277+
<div class="fragment"><div class="line">{</div><div class="line"> <span class="keyword">using</span> Class = RigidTransform&lt;T&gt;;</div><div class="line"> constexpr <span class="keyword">auto</span>&amp; cls_doc = doc.RigidTransform;</div><div class="line"> py::class_&lt;Class&gt;(m, <span class="stringliteral">&quot;RigidTransform&quot;</span>, cls_doc.doc)</div><div class="line"> .def(py::init(), cls_doc.ctor.doc_0args)</div><div class="line"> ...</div><div class="line">}</div></div><!-- fragment --><p>To view the documentation rendered in Sphinx: </p><pre class="fragment">bazel run -- //doc/pydrake:build --serve [--browser=false]
278278
</pre><dl class="section note"><dt>Note</dt><dd>Drake's online Python documentation is generated on Ubuntu Noble, and it is suggested to preview documentation using this platform. Other platforms may have slightly different generated documentation.</dd></dl>
279-
<p>To browse the generated documentation strings that are available for use (or especially, to find out the names for overloaded functions' documentation), generate and open the docstring header: </p><pre class="fragment">bazel build //bindings/pydrake:documentation_pybind.h
280-
$EDITOR bazel-bin/bindings/pydrake/documentation_pybind.h
279+
<p>To browse the generated documentation strings that are available for use (or especially, to find out the names for overloaded functions' documentation), re-generate and open the docstring header: </p><pre class="fragment">bazel run //bindings/generated_docstrings:regenerate
280+
$EDITOR bazel-bin/bindings/generated_docstrings/SOME_FILE.h
281281
</pre><p>Search the comments for the symbol of interest, e.g., <code><a class="el" href="classdrake_1_1math_1_1_rigid_transform.html#a8bedd8c483aaf5bc48587d10d7a3d485">drake::math::RigidTransform::RigidTransform</a>&lt;T&gt;</code>, and view the include file and line corresponding to the symbol that the docstring was pulled from.</p>
282-
<dl class="section note"><dt>Note</dt><dd>This file may be large, on the order of ~100K lines; be sure to use an efficient editor!</dd>
283-
<dd>
284-
If you are debugging a certain file and want quicker generation and a smaller generated file, you can hack <code>mkdoc.py</code> to focus only on your include file of choice. As an example, debugging <code><a class="el" href="mathematical__program_8h.html">mathematical_program.h</a></code>: <div class="fragment"><div class="line">...</div><div class="line"><span class="keyword">assert</span> len(include_files) &gt; 0 <span class="comment"># Existing code.</span></div><div class="line">include_files = [<span class="stringliteral">&quot;drake/solvers/mathematical_program.h&quot;</span>] <span class="comment"># HACK</span></div></div><!-- fragment --> This may break the bindings themselves, and should only be used for inspecting the output.</dd></dl>
282+
<dl class="section note"><dt>Note</dt><dd>This file may be large, on the order of ~10K lines; be sure to use an efficient editor!</dd></dl>
285283
<p>For more detail:</p>
286284
<ul>
287-
<li>Each docstring is stored in <code>documentation_pybind.h</code> in the nested structure <code>pydrake_doc</code>.</li>
288-
<li>The docstring for a symbol without any overloads will be accessible via <code>pydrake_doc.drake.{namespace...}.{symbol}.doc</code>.</li>
285+
<li>Docstrings are stored in files named after the subdirectory where the original C++ header file lives, e.g., <code><a class="el" href="multibody__tree_8h.html">multibody_tree.h</a></code> for <code>drake/multibody/tree</code> docs.</li>
286+
<li>The constants sit within structures named <code>pydrake_doc_{directory_names}</code>, e.g., <code>pydrake_doc_multibody_tree</code> for <code>drake/multibody/tree</code> docs.</li>
287+
<li>The docstring for a symbol without any overloads will be accessible via <code>pydrake_doc_{directory_names}.drake.{namespace...}.{symbol}.doc</code>.</li>
289288
<li>The docstring for an overloaded symbol will be <code>.doc_something</code> instead of just <code>.doc</code>, where the <code>_something</code> suffix conveys some information about the overload. Browse the documentation_pybind.h (described above) for details. Most commonly, the names will be <code>doc_1args</code>, <code>doc_3args</code>, etc. Be sure that the pydrake binding's signature is consistent with the docstring argument count.</li>
290289
<li>If two or more docstrings are the same, only one new symbol is introduced.</li>
291290
<li>To suppress a Doxygen comment from mkdoc, add the custom Doxygen command <code>@exclude_from_pydrake_mkdoc{Explanation}</code> to the API comment text. This is useful to help dismiss unbound overloads, so that mkdoc's choice of <code>_something</code> name suffix is simpler for the remaining overloads, especially if you see the symbol <code>.doc_was_unable_to_choose_unambiguous_names</code> in the generated documentation.</li>

doxygen_cxx/identifier__pybind_8h.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
</div><!--header-->
167167
<div class="contents">
168168
<div class="textblock"><code>#include &lt;string&gt;</code><br />
169-
<code>#include &quot;drake/bindings/pydrake/documentation_pybind.h&quot;</code><br />
169+
<code>#include &quot;drake/bindings/generated_docstrings/common.h&quot;</code><br />
170170
<code>#include &quot;<a class="el" href="pydrake__pybind_8h.html">drake/bindings/pydrake/pydrake_pybind.h</a>&quot;</code><br />
171171
<code>#include &quot;<a class="el" href="identifier_8h.html">drake/common/identifier.h</a>&quot;</code><br />
172172
</div><div class="textblock"><div class="dynheader">

doxygen_cxx/identifier__pybind_8h__incl.svg

Lines changed: 2 additions & 2 deletions
Loading

doxygen_cxx/identifier__pybind_8h__incl_org.svg

Lines changed: 2 additions & 2 deletions
Loading

doxygen_cxx/type__safe__index__pybind_8h.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@
166166
</div><!--header-->
167167
<div class="contents">
168168
<div class="textblock"><code>#include &lt;string&gt;</code><br />
169+
<code>#include &quot;drake/bindings/generated_docstrings/common.h&quot;</code><br />
169170
<code>#include &quot;<a class="el" href="value__pybind_8h.html">drake/bindings/pydrake/common/value_pybind.h</a>&quot;</code><br />
170-
<code>#include &quot;drake/bindings/pydrake/documentation_pybind.h&quot;</code><br />
171171
<code>#include &quot;<a class="el" href="pydrake__pybind_8h.html">drake/bindings/pydrake/pydrake_pybind.h</a>&quot;</code><br />
172172
<code>#include &quot;<a class="el" href="type__safe__index_8h.html">drake/common/type_safe_index.h</a>&quot;</code><br />
173173
</div><div class="textblock"><div class="dynheader">

0 commit comments

Comments
 (0)