@@ -81,19 +81,21 @@ by introducing syntax for docstrings for variables.
81
81
following the normal class inheritance patterns.
82
82
Consider the following code example:
83
83
84
- >>> class A:
85
- ... def test(self):
86
- ... """Docstring for A."""
87
- ... pass
88
- ...
89
- >>> class B(A):
90
- ... def test(self):
91
- ... pass
92
- ...
93
- >>> A.test.__doc__
94
- 'Docstring for A.'
95
- >>> B.test.__doc__
96
- None
84
+ ``` python-repl
85
+ >>> class A:
86
+ ... def test(self):
87
+ ... """Docstring for A."""
88
+ ... pass
89
+ ...
90
+ >>> class B(A):
91
+ ... def test(self):
92
+ ... pass
93
+ ...
94
+ >>> A.test.__doc__
95
+ 'Docstring for A.'
96
+ >>> B.test.__doc__
97
+ None
98
+ ```
97
99
98
100
In Python, the docstring for ` B.test ` doesn't exist, even though a
99
101
docstring was defined for ` A.test ` .
@@ -115,18 +117,20 @@ For example:
115
117
116
118
[ PEP-224 ] : http://www.python.org/dev/peps/pep-0224
117
119
118
- module_variable = 1
119
- """PEP 224 docstring for module_variable."""
120
+ ``` python
121
+ module_variable = 1
122
+ """ PEP 224 docstring for module_variable."""
120
123
121
- class C:
122
- #: Documentation comment for class_variable
123
- #: spanning over three lines.
124
- class_variable = 2 #: Assignment line is included.
124
+ class C :
125
+ # : Documentation comment for class_variable
126
+ # : spanning over three lines.
127
+ class_variable = 2 # : Assignment line is included.
125
128
126
- def __init__(self):
127
- #: Instance variable's doc-comment
128
- self.variable = 3
129
- """But note, PEP 224 docstrings take precedence."""
129
+ def __init__ (self ):
130
+ # : Instance variable's doc-comment
131
+ self .variable = 3
132
+ """ But note, PEP 224 docstrings take precedence."""
133
+ ```
130
134
131
135
While the resulting variables have no ` __doc__ ` attribute,
132
136
` pdoc ` compensates by reading the source code (when available)
@@ -162,12 +166,14 @@ This feature is useful when there's no feasible way of
162
166
attaching a docstring to something. A good example is a
163
167
[ namedtuple] ( https://docs.python.org/3/library/collections.html#collections.namedtuple ) :
164
168
165
- __pdoc__ = {}
169
+ ``` python
170
+ __pdoc__ = {}
166
171
167
- Table = namedtuple('Table', ['types', 'names', 'rows'])
168
- __pdoc__['Table.types'] = 'Types for each column in the table.'
169
- __pdoc__['Table.names'] = 'The names of each column in the table.'
170
- __pdoc__['Table.rows'] = 'Lists corresponding to each row in the table.'
172
+ Table = namedtuple(' Table' , [' types' , ' names' , ' rows' ])
173
+ __pdoc__[' Table.types' ] = ' Types for each column in the table.'
174
+ __pdoc__[' Table.names' ] = ' The names of each column in the table.'
175
+ __pdoc__[' Table.rows' ] = ' Lists corresponding to each row in the table.'
176
+ ```
171
177
172
178
` pdoc ` will then show ` Table ` as a class with documentation for the
173
179
` types ` , ` names ` and ` rows ` members.
@@ -234,7 +240,7 @@ the identifier name must be fully qualified, for example
234
240
` pdoc.Doc.docstring ` ) while <code >\` Doc.docstring\` </code >
235
241
only works within ` pdoc ` module.
236
242
237
- [ backticks ] : https://en.wikipedia.org/wiki/Grave_accent#Use_in_programming
243
+ [ backticks ] : https://en.wikipedia.org/wiki/Backtick
238
244
239
245
240
246
Command-line interface
@@ -246,32 +252,42 @@ For example, to produce HTML documentation of your whole package
246
252
in subdirectory 'build' of the current directory, using the default
247
253
HTML template, run:
248
254
249
- $ pdoc --html --output-dir build my_package
255
+ ``` shell
256
+ $ pdoc --html --output-dir build my_package
257
+ ```
250
258
251
259
If you want to omit the source code preview, run:
252
260
253
- $ pdoc --html --config show_source_code=False my_package
261
+ ``` shell
262
+ $ pdoc --html --config show_source_code=False my_package
263
+ ```
254
264
255
265
Find additional template configuration tunables in [ custom templates]
256
266
section below.
257
267
258
268
To run a local HTTP server while developing your package or writing
259
269
docstrings for it, run:
260
270
261
- $ pdoc --http : my_package
271
+ ``` shell
272
+ $ pdoc --http : my_package
273
+ ```
262
274
263
275
To re-build documentation as part of your continuous integration (CI)
264
276
best practice, i.e. ensuring all reference links are correct and
265
277
up-to-date, make warnings error loudly by settings the environment
266
278
variable [ ` PYTHONWARNINGS ` ] [ PYTHONWARNINGS ] before running pdoc:
267
279
268
- $ export PYTHONWARNINGS='error::UserWarning'
280
+ ``` shell
281
+ $ export PYTHONWARNINGS=' error::UserWarning'
282
+ ```
269
283
270
284
[ PYTHONWARNINGS ] : https://docs.python.org/3/using/cmdline.html#envvar-PYTHONWARNINGS
271
285
272
286
For brief usage instructions, type:
273
287
274
- $ pdoc --help
288
+ ``` shell
289
+ $ pdoc --help
290
+ ```
275
291
276
292
Even more usage examples can be found in the [ FAQ] .
277
293
@@ -292,23 +308,25 @@ Afterwards, you can use `pdoc.Module.html` and `pdoc.Module.text`
292
308
methods to output documentation in the desired format.
293
309
For example:
294
310
295
- import pdoc
311
+ ``` python
312
+ import pdoc
296
313
297
- modules = ['a', 'b'] # Public submodules are auto-imported
298
- context = pdoc.Context()
314
+ modules = [' a' , ' b' ] # Public submodules are auto-imported
315
+ context = pdoc.Context()
299
316
300
- modules = [pdoc.Module(mod, context=context)
301
- for mod in modules]
302
- pdoc.link_inheritance(context)
317
+ modules = [pdoc.Module(mod, context = context)
318
+ for mod in modules]
319
+ pdoc.link_inheritance(context)
303
320
304
- def recursive_htmls(mod):
305
- yield mod.name, mod.html()
306
- for submod in mod.submodules():
307
- yield from recursive_htmls(submod)
321
+ def recursive_htmls (mod ):
322
+ yield mod.name, mod.html()
323
+ for submod in mod.submodules():
324
+ yield from recursive_htmls(submod)
308
325
309
- for mod in modules:
310
- for module_name, html in recursive_htmls(mod):
311
- ... # Process
326
+ for mod in modules:
327
+ for module_name, html in recursive_htmls(mod):
328
+ ... # Process
329
+ ```
312
330
313
331
When documenting a single module, you might find
314
332
functions ` pdoc.html ` and ` pdoc.text ` handy.
0 commit comments