forked from fastai/fastai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_doc.gen_notebooks.html
342 lines (269 loc) · 20 KB
/
gen_doc.gen_notebooks.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
---
title: gen_doc.gen_notebooks
keywords: fastai
sidebar: home_sidebar
summary: "Generation of documentation notebook skeletons from python module"
---
<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: docs_src/gen_doc.gen_notebooks.ipynb
# instructions: https://docs.fast.ai/gen_doc_main.html
-->
<div class="container" id="notebook-container">
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Notebook-generation">Notebook generation<a class="anchor-link" href="#Notebook-generation">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This module contains the scripts and API to auto-generate or update a documentation notebook skeleton from a fastai module (e.g. - fastai.<em>) or existing documentation file (e.g. - docs_src/</em>.ipynb). It is not expected you'd use this skeleton as your final docs - you should add markdown, examples, etc to it. The skeleton just has a minimal list of exported symbols.</p>
<p><a href="https://github.com/fastai/fastai/blob/master/tools/build-docs"><code>tools/build-docs</code></a> contains a command line tool that transforms a given module into a notebook skeleton. It's essentially a wrapper around <a href="/gen_doc.gen_notebooks.html#update_notebooks"><code>gen_notebooks.update_notebooks</code></a>. For usage around the command line tool, please follow instructions at <a href="/gen_doc_main.html#updating-notebooks"><code>gen_doc_main#updating-notebooks</code></a>.</p>
<p>Alternatively, you can access the same functionality through the module API, documented below.</p>
<p><strong>Important note:</strong> The notebooks automatically generated or updated need to be trusted before you can see the results in the output cells. To trust a notebook, click on File, then Trust notebook.</p>
<p>This module also contains the scripts and API to convert the documentation notebooks into HTML, which is the format used for the final documentation site.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Installation">Installation<a class="anchor-link" href="#Installation">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This package requires:</p>
<ul>
<li><a href="https://github.com/jupyter/nbconvert">nbconvert</a>: conda install nbconvert</li>
<li><a href="https://github.com/ipython-contrib/jupyter_contrib_nbextensions">nb_extensions</a>: conda install -c conda-forge jupyter_contrib_nbextensions</li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Once nbextensions is installed, your home page of jupyter notebook will look like this:</p>
<p><img src="imgs/nbext.png" alt="Homepage with nbextension"></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Click on the Nbextensions tab then make sure the hide inputs extension is activated:</p>
<p><img src="imgs/hide_input.png" alt="Activate hidden input"></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>As its name suggests, this will allow you to hide input cells and only show their results.</p>
<p>There is also the <code>Hide Input all</code> extension, but don't use it, since it toggles all inputs on/off and once executed it'll be very difficult to restore the notebook to its original state where some inputs are supposed to be hidden and some are not.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Convert-modules-into-notebook-skeleton">Convert modules into notebook skeleton<a class="anchor-link" href="#Convert-modules-into-notebook-skeleton">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The first (optional) step is to create a notebook "skeleton" - i.e. a notebook containing all the classes, methods, functions, and other symbols you wish to document. You can create this manually if you prefer, however using the automatic approach can save you some time and ensure you don't miss anything.</p>
<p>For the initial skeleton, use <a href="/gen_doc.gen_notebooks.html#create_module_page"><code>create_module_page</code></a>, which creates a new module from scratch. To update it later with any newly-added symbols, use <a href="/gen_doc.gen_notebooks.html#update_module_page"><code>update_module_page</code></a>.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="create_module_page" class="doc_header"><code>create_module_page</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L93" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#create_module_page-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>create_module_page</code>(<strong><code>mod</code></strong>, <strong><code>dest_path</code></strong>, <strong><code>force</code></strong>=<strong><em><code>False</code></em></strong>)</p>
</blockquote>
<div class="collapse" id="create_module_page-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#create_module_page-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>create_module_page</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div><p>Create the documentation notebook for module <code>mod_name</code> in path <code>dest_path</code></p>
<ul>
<li><em>mod</em>: the module</li>
<li><em>dest_path</em>: the folder in which to generate the notebook</li>
<li><em>force</em>: if False, will raise an exception if the notebook is already present </li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Equivalent <a href="/gen_doc_main.html#creating-a-new-documentation-notebook-from-existing-module">CLI</a>:</p>
<div class="highlight"><pre><span></span>tools/build-docs fastai.subpackage.module
</pre></div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="link_nb" class="doc_header"><code>link_nb</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L290" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#link_nb-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>link_nb</code>(<strong><code>nb_path</code></strong>)</p>
</blockquote>
<div class="collapse" id="link_nb-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#link_nb-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>link_nb</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="update_module_page" class="doc_header"><code>update_module_page</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L262" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#update_module_page-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>update_module_page</code>(<strong><code>mod</code></strong>, <strong><code>dest_path</code></strong>=<strong><em><code>'.'</code></em></strong>)</p>
</blockquote>
<div class="collapse" id="update_module_page-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#update_module_page-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>update_module_page</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div><p>Update the documentation notebook of a given module.</p>
<ul>
<li><em>mod</em>: the module</li>
<li><em>dest_path</em>: the folder in which to generate the notebook </li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>All the cells added by a user are conserved, only the cells of new symbols (aka that weren't documented before) will be inserted at the end. You can then move them to wherever you like in the notebook. For instance, to update this module's documentation, simply run:</p>
<pre><code>update_module_page(gen_doc.gen_notebooks, '.')</code></pre>
<p>You can also generate and update <em>all</em> modules in a package using <a href="/gen_doc.gen_notebooks.html#update_notebooks"><code>update_notebooks</code></a>.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Equivalent <a href="/gen_doc_main.html#updating-an-existing-functionclass">CLI</a>:</p>
<div class="highlight"><pre><span></span>tools/build-docs docs_src/gen_doc.gen_notebooks.ipynb
</pre></div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Updating-module-metadata">Updating module metadata<a class="anchor-link" href="#Updating-module-metadata">¶</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Jekyll pulls the documentation title, summary, and keywords from the metadata of each notebook.<br>
Notebook metadata structure looks like this: <code>'metadata': { 'jekyll': {...} }</code></p>
<p>To update metadata of these notebooks, run <code>generate_missing_metadata('.')</code>. Then open the notebook <code>jekyll_metadata.ipynb</code> to change the metadata.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="generate_missing_metadata" class="doc_header"><code>generate_missing_metadata</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L189" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#generate_missing_metadata-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>generate_missing_metadata</code>(<strong><code>dest_file</code></strong>)</p>
</blockquote>
<div class="collapse" id="generate_missing_metadata-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#generate_missing_metadata-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>generate_missing_metadata</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="update_nb_metadata" class="doc_header"><code>update_nb_metadata</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L204" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#update_nb_metadata-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>update_nb_metadata</code>(<strong><code>nb_path</code></strong>=<strong><em><code>None</code></em></strong>, <strong><code>title</code></strong>=<strong><em><code>None</code></em></strong>, <strong><code>summary</code></strong>=<strong><em><code>None</code></em></strong>, <strong><code>keywords</code></strong>=<strong><em><code>'fastai'</code></em></strong>, <strong><code>overwrite</code></strong>=<strong><em><code>True</code></em></strong>, <strong>**<code>kwargs</code></strong>)</p>
</blockquote>
<div class="collapse" id="update_nb_metadata-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#update_nb_metadata-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>update_nb_metadata</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div><p>Creates jekyll metadata for given notebook path.</p>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Updating-all-module-docs">Updating all module docs<a class="anchor-link" href="#Updating-all-module-docs">¶</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h4 id="update_notebooks" class="doc_header"><code>update_notebooks</code><a href="https://github.com/fastai/fastai/blob/master/fastai/gen_doc/gen_notebooks.py#L305" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#update_notebooks-pytest" style="float:right; padding-right:10px">[test]</a></h4><blockquote><p><code>update_notebooks</code>(<strong><code>source_path</code></strong>, <strong><code>dest_path</code></strong>=<strong><em><code>None</code></em></strong>, <strong><code>update_html</code></strong>=<strong><em><code>True</code></em></strong>, <strong><code>document_new_fns</code></strong>=<strong><em><code>False</code></em></strong>, <strong><code>update_nb_links</code></strong>=<strong><em><code>True</code></em></strong>, <strong><code>html_path</code></strong>=<strong><em><code>None</code></em></strong>, <strong><code>force</code></strong>=<strong><em><code>False</code></em></strong>)</p>
</blockquote>
<div class="collapse" id="update_notebooks-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#update_notebooks-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>No tests found for <code>update_notebooks</code>. To contribute a test please refer to <a href="/dev/test.html">this guide</a> and <a href="https://forums.fast.ai/t/improving-expanding-functional-tests/32929">this discussion</a>.</p></div></div><p><code>source_path</code> can be a directory or a file. Assume all modules reside in the fastai directory.</p>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>As a convenience method, this can update all notebooks. This snippet does the whole lot for you:</p>
<div class="highlight"><pre><span></span><span class="n">update_notebooks</span><span class="p">(</span><span class="s1">'docs_src'</span><span class="p">,</span> <span class="n">update_html</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">update_nb</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
</pre></div>
<p>This will update all ipynb documentation notebooks specified under source_path</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Add-documentation">Add documentation<a class="anchor-link" href="#Add-documentation">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The automatically generated module will only contain the table of contents and the doc string of the functions and classes in your module (or the ones you picked with __all__). You should add more prose to them in markdown cells, or examples of uses inside the notebook.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>At any time, if you don't want the input of a code cell to figure in the final result, you can use the little button in your tool bar to hide it.</p>
<p><img src="imgs/button_hide.png" alt="Button to hide an input"></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The same button can show you the hidden input from a cell. This used in conjunction with the helper functions from <a href="gen_doc.nbdoc.ipynb">nbdoc</a> should allow you to easily add any content you need.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Convert-notebook-to-html">Convert notebook to html<a class="anchor-link" href="#Convert-notebook-to-html">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Once you're finished, don't forget to properly save your notebook, then you can either convert all the notebooks together with the script:</p>
<pre><code>python -m convert2html dir</code></pre>
<ul>
<li><strong>dir</strong> is the directory where all your notebooks are stored.</li>
</ul>
<p>If you prefer to do this in a notebook, you can simply type:</p>
<div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">fastai.gen_doc.convert2html</span> <span class="kn">import</span> <span class="n">convert_nb</span>
<span class="n">convert_nb</span><span class="p">(</span><span class="s1">'gen_doc.gen_notebooks.ipynb'</span><span class="p">,</span> <span class="s1">'../docs'</span><span class="p">)</span>
</pre></div>
<p>For more information see the <a href="/gen_doc.convert2html.html">documentation of convert2html</a>.</p>
</div>
</div>
</div>
</div>