-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
505 lines (400 loc) · 16.4 KB
/
index.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Software Development for Engineering Research - Documentation</title>
<meta name="description" content="
Lecture on documentation for ME 599: Software Development for Engineering Research
">
<meta name="author" content="Kyle Niemeyer">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/simple.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h2>Documentation</h2>
<br/>
<h3>Kyle Niemeyer. 1 Feb 2022</h3>
<h3>ME 599, Corvallis, OR</h3>
</section>
<section data-markdown>
<textarea data-template>
## Today: Documentation, and building a documentation website with Sphinx
</textarea>
</section>
<section>
<section>
<h2>Documentation</h2>
<br/>
<p class="fragment">Professor Carole Goble in <a href="https://doi.org/10.1109/MIC.2014.88">“Better Software, Better Research”</a>:</p>
<blockquote class="fragment" cite="https://doi.org/10.1109/MIC.2014.88">
One of my favorite #overlyhonestmethods tweets (a hashtag for lab scientists) is <a href="https://twitter.com/ianholmes/status/288689712636493824">
Ian Holmes’s “You can download our code from the URL supplied. Good luck downloading the only postdoc who can get it to run, though.</a>”
</blockquote>
</section>
<section>
<h2>Value of documentation</h2>
<br/>
<ul>
<li class="fragment">The value and extent of your work is clearer if it can be understood by colleagues.</li>
<li class="fragment">Documentation provides provenance for your scientific process, for your colleagues and yourself.</li>
<li class="fragment">Documentation demonstrates your skill and professionalism.</li>
</ul>
</section>
<section>
<h2>Documentation is easier than you think.</h2>
<br/>
<ul>
<li class="fragment">Documentation pays for itself with the time it saves in the long run.</li>
<li class="fragment">Documentation requires little effort beyond writing the software itself.</li>
</ul>
</section>
<section>
<h2>Types of documentation</h2>
<br/>
<ul>
<li>Theory manuals</li>
<li>User and developer guides</li>
<li>Code comments</li>
<li>Self-documenting code</li>
<li>Generated API documentation</li>
</ul>
</section>
<section>
<h2>User and developer guides</h2>
<br/>
<p class="fragment"><code>README</code>: sits in top-level directory and
contains all the necessary information for installing, getting started with, and understanding the accompanying code.
</p>
<p class="fragment">May be accompanied by other specific files:
<code>LICENSE</code>, <code>INSTALL</code>, <code>CITATION</code>, <code>ABOUT</code>, <code>CHANGELOG</code>
</p>
</section>
<section>
<h3>README example</h3>
<br/>
<div style="font-size:25px">
<pre><code data-trim class="text">
SQUIRREL, version 1.2 released on 2026-09-20
# About
The Spectral Q and U Imaging Radiation Replicating Experimental Library
(SQUIRREL) is a library for replicating radiation sources with spectral details
and Q and U polarizations of superman bubblegum.
# Installation
The SQUIRREL library relies on other libraries:
- The ACORN library www.acorn.nutz
- The TREEBRANCH database format API
Install those before installing the SQUIRREL library. To install the SQUIRREL
library:
./configure
make --prefix=/install/path
make install
...
</code></pre>
</div>
</section>
<section>
<h3>Comments</h3>
<br/>
<p class="fragment">Comments provide a way to insert metainformation about code intended for people, right next to the code:</p>
<pre><code data-trim class="python fragment">
def the_function(var):
"""This is a docstring, where a function definition might live"""
a = 1 + var # this is a simple comment
return a
</code></pre>
</section>
<section>
<h3>Bad Comments</h3>
<br/>
<p class="fragment">Also possible to pollute code with unnecessary cruft:</p>
<pre><code data-trim class="python fragment">
def decay(index, database):
# first, retrieve the decay constants from the database
mylist = database.decay_constants()
# next, try to access an element of the list
try:
d = mylist[index] # gets decay constant at index in the list
# if the index doesn't exist
except IndexError:
# throw an informative error message
raise Exception("value not found in the list")
return d
</code></pre>
</section>
<section>
<h3>Useful Comments</h3>
<br/>
<p class="fragment">Code written cleanly will have its own voice. Use intelligent naming
to make most lines of code clear without comments, then use comments sparingly to
help explain reasons or complicated sections:
</p>
<pre><code data-trim class="python fragment">
def decay(index, database):
lambdas = database.decay_constants()
try:
lambda_i = lambdas[index] # gets decay constant at index in the list
except IndexError:
raise Exception("value not found in the list")
return lambda
</code></pre>
</section>
<section>
<h3>Self-Documenting Code</h3>
<br/>
<p class="fragment"><strong>Naming:</strong> a class, variable, or function name should tell you why it exists,
what it does, and how it is used.
</p>
<p class="fragment"><strong>Simple functions:</strong> functions should be small to be understandable and testable;
they should only do <em>one thing</em>.
</p>
<p class="fragment"><strong>Consistent style:</strong> use a consistent, standardized style; e.g., select
variable and function names according to the <a href="https://www.python.org/dev/peps/pep-0008/">
PEP8 style guide</a> for Python.
</p>
</section>
<section>
<h4>Guidelines for naming:</h4>
<br/>
<pre><code data-trim class="python">
# packages and modules are short and lowercase
packages
modules
# other objects can be long
ClassesUseCamelCase
ExceptionsAreClassesToo
functions_use_snake_case
CONSTANTS_USE_ALL_CAPS
# variable scope is *suggested* by style convention
_single_leading_underscore_ # internal to module
single_trailing_underscore_ # avoids conflicts with Python keywords
__double_leading_and_trailing__ # these are magic, like __init__
</code></pre>
</section>
<section>
<h3>Docstrings</h3>
<br/>
<p class="fragment"><strong>docstring:</strong> comment placed immediately after a function or class
definition, typically enclosed by three pairs of double quotes:
</p>
<pre><code data-trim class="python fragment">
def <name>(<args>):
"""<docstring>"""
<body>
</code></pre>
<p class="fragment">docstrings are available within Python via <code>help()</code> and
iPython's magic command <code>?</code>, and Sphinx picks them up.
</p>
</section>
<section>
<h3>Docstrings (more)</h3>
<br/>
<p class="fragment">Make docstrings descriptive and concise; you can explain the arguments
of a function, its behavior, and how you intend it to be used.
</p>
<pre><code data-trim class="python fragment">
def power(base, x):
"""Computes base^x. Both base and x should be integers,
floats, or another numeric type.
"""
return base**x
</code></pre>
</section>
</section>
<section>
<section>
<h3>Sphinx: automate generating documentation</h3>
<br/>
<p class="fragment">Sphinx can be used to automate the generation of HTML documentation;
we can even use it with Travis CI to automatically build and deploy the docs
on GitHub Pages.
</p>
<p class="fragment">For now, let's just make sure your docstrings are suitable for Sphinx.
</p>
</section>
<section>
<h3>Numpy-Style Docstrings</h3>
<br/>
<div style="font-size:25px">
<pre><code data-trim class="python">
def function_with_types_in_docstring(param1, param2):
"""Example function with types documented in the docstring.
`PEP 484`_ type annotations are supported. If attribute, parameter, and
return types are annotated according to `PEP 484`_, they do not need to be
included in the docstring:
Parameters
----------
param1 : int
The first parameter.
param2 : str
The second parameter.
Returns
-------
bool
True if successful, False otherwise.
.. _PEP 484:
https://www.python.org/dev/peps/pep-0484/
"""
</code></pre>
</div>
<p>More examples at the <a href="http://www.sphinx-doc.org/en/master/ext/example_numpy.html">
Sphinx documentation</a>
</p>
</section>
<section>
<h3>Google-Style Docstrings</h3>
<br/>
<div style="font-size:25px">
<pre><code data-trim class="python">
def function_with_types_in_docstring(param1, param2):
"""Example function with types documented in the docstring.
`PEP 484`_ type annotations are supported. If attribute, parameter, and
return types are annotated according to `PEP 484`_, they do not need to be
included in the docstring:
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
bool: The return value. True for success, False otherwise.
.. _PEP 484:
https://www.python.org/dev/peps/pep-0484/
"""
</code></pre>
</div>
<p>More examples at the <a href="http://www.sphinx-doc.org/en/master/ext/example_google.html#example-google">
Sphinx documentation</a>
</p>
</section>
<section>
<h3>Get started with sphinx</h3>
<br/>
<ol>
<li class="fragment">
<code>mkdir docs</code>
</li>
<li class="fragment">
<code>cd docs</code>
</li>
<li class="fragment">
<code>sphinx-quickstart</code> (accept defaults if unsure; answer "yes" for question about
<code>autodoc</code>)
</li>
<li class="fragment">
<code>source</code> directory holds <code>.rst</code> files for user guides, theory manuals, etc.
separate from the autogenerated API documentation
</li>
</ol>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
### [Sphinx quickstart](https://www.sphinx-doc.org/en/master/usage/quickstart.html)
- Install sphinx: `conda install sphinx`
- In the top-level of your repo, run `sphinx-quickstart`
- Answer questions; accept most defaults. Say yes to `autodoc` extension
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Add content
- In the `docs` directory, add an `installation.rst` file (for example)
- Try building with `make html`
- Did sphinx find and automatically build docs for your modules? Look for `.rst` files for each module.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Configuration
Other useful things for `conf.py`:
- In extensions, add `sphinx.ext.napoleon` (for Google/NumPy-style docstring reading) and `sphinx.ext.mathjax` (if you want LaTeX-based equations), and `sphinx.ext.intersphinx` for connections to other docs
- Set `napoleon_numpy_docstring` and `napoleon_google_docstring` to `True`/`False` depending on your docstring style.
- Add an `intersphinx_mapping` dict to connect to other docs
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### `intersphinx_mapping`
<pre><code data-trim class="python">
intersphinx_mapping = {
'python': ('https://docs.python.org/3.6', None),
'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
}
</code></pre>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Sphinx with Markdown
Generally Sphinx uses ReStructuredText (`.rst`) files for documentation.
But, you can also have it read Markdown files with the `recommonmark` extension:
- `conda install recommonmark`
- Add `'recommonmark'` to the `extensions` list in `conf.py`
- Extend the `source_suffix` dict:
<pre><code data-trim class="python">
source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
'.md': 'markdown',
}
</code></pre>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Other Sphinx goodness:
- You can configure it to generate a LaTeX-based PDF (i.e., a single user manual)
- You can have versioned documentation, and also simultaneously have "devel" docs for unreleased changes.
</textarea>
</section>
</section>
<section data-markdown>
<textarea data-template>
### Using [doctr](https://drdoctr.github.io)
Doctr helps autodeploy docs to GitHub Pages using Travis CI.
Steps:
- Install: `conda install -c conda-forge doctr`
- `doctr configure`
</textarea>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
});
</script>
</body>
</html>