File: python.rst

package info (click to toggle)
taskflow 3.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 45,948 kB
  • sloc: cpp: 39,058; xml: 35,572; python: 12,935; javascript: 1,732; makefile: 59; sh: 16
file content (1469 lines) | stat: -rw-r--r-- 70,882 bytes parent folder | download
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
..
    This file is part of m.css.

    Copyright © 2017, 2018, 2019, 2020, 2021, 2022, 2023
              Vladimír Vondruš <mosra@centrum.cz>

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
..

Python docs
###########

:breadcrumb: {filename}/documentation.rst Doc generators
:summary: A modern, mobile-friendly Sphinx-alike Python documentation
    generator with a first-class search functionality
:footer:
    .. note-dim::
        :class: m-text-center

        `« Doxygen C++ theme <{filename}/documentation/doxygen.rst>`_ | `Doc generators <{filename}/documentation.rst>`_

.. role:: cpp(code)
    :language: cpp
.. role:: css(code)
    :language: css
.. role:: html(code)
    :language: html
.. role:: js(code)
    :language: js
.. role:: py(code)
    :language: py
.. role:: sh(code)
    :language: sh
.. role:: rst(code)
    :language: rst

.. |wink| replace:: 😉

A modern, mobile-friendly Sphinx-alike Python documentation generator with a
first-class search functionality. Generated by inspecting Python modules and
using either embedded docstrings or external :abbr:`reST <reStructuredText>`
files to populate the documentation.

One of the design goals is providing a similar user experience to the
`Doxygen documentation theme <{filename}doxygen.rst>`_.

.. button-success:: https://doc.magnum.graphics/python/

    Live demo

    doc.magnum.graphics

.. contents::
    :class: m-block m-default

`Basic usage`_
==============

The base is contained in a single Python script and related style/template
files, for advanced features such as math rendering it'll make use of internals
of some `m.css plugins <{filename}/plugins.rst>`_. Clone
:gh:`the m.css GitHub repository <mosra/m.css$master/documentation>` and look
into the ``documentation/`` directory:

.. code:: sh

    git clone https://github.com/mosra/m.css
    cd m.css/documentation

The script requires Python 3.6 and depends on `Jinja2 <http://jinja.pocoo.org/>`_
for templating and docutils for :abbr:`reST <reStructuredText>` markup
rendering. You can install the dependencies via ``pip`` or your distribution
package manager, in most cases you'll probably have them already installed:

.. code:: sh

    # You may need sudo here
    pip3 install docutils jinja2

Next, you need a configuration file which tells the script what modules to
inspect, how to name the project and where to put the output. In this example,
we'll generate documentation for the Python builtin ``math`` module:

.. code:: py

    PROJECT_TITLE = "Python math"
    INPUT_MODULES = ['math']

Now, run the script and pass path to the configuration file to it:

.. code:: sh

    ./python.py path/to/conf.py

This will generate an ``output/`` directory next to the ``conf.py`` file and
fill it with the generated output. Open ``index.html`` to see the result.

`Features`_
===========

-   Theme tailored from scratch for Python-specific language features
-   Uses code inspection to query modules, classes, data, functions and their
    signatures, does not rely on error-prone source code parsing
-   Does not force the documentation writer to explicitly list all symbols in
    order to have them documented
-   Can use both in-code docstrings and external :abbr:`reST <reStructuredText>`
    files to describe the APIs, giving the user a control over the code size vs
    documentation verbosity tradeoff

`Configuration`_
================

Together with the above :py:`PROJECT_TITLE` and :py:`INPUT_MODULES` variables
mentioned above, the configuration file supports the following variables. The
options are similar to the `Doxygen config <{filename}doxygen.rst#configuration>`_,
but free of the Doxygen-specific naming and constraints.

.. class:: m-table m-fullwidth

=================================== ===========================================
Variable                            Description
=================================== ===========================================
:py:`PROJECT_TITLE: str`            Project title. Rendered in top navbar, page
                                    title and fine print. If not set,
                                    :py:`"My Python Project"` is used.
:py:`PROJECT_SUBTITLE: str`         Project subtitle. If set, appended in a
                                    thinner font to :py:`PROJECT_TITLE`.
:py:`PROJECT_LOGO: str`             URL of an image to use as a log in the top
                                    navbar. Default is none.
:py:`MAIN_PROJECT_URL: str`         If set and :py:`PROJECT_SUBTITLE` is also
                                    set, then :py:`PROJECT_TITLE` in the top
                                    navbar will link to this URL and
                                    :py:`PROJECT_SUBTITLE` to the documentation
                                    main page, similarly as
                                    `shown here <{filename}/css/page-layout.rst#link-back-to-main-site-from-a-subsite>`_.
:py:`INPUT: str`                    Base input directory. If not set, config
                                    file base dir is used. Relative paths are
                                    relative to config file base dir.
:py:`OUTPUT: str`                   Where to save the output. Relative paths
                                    are relative to :py:`INPUT`; if not set,
                                    ``output/`` is used.
:py:`INPUT_MODULES: List[Any]`      List of modules to generate the docs from.
                                    Values can be either strings or module
                                    objects. See `Module inspection`_ for more
                                    information.
:py:`INPUT_PAGES: List[str]`        List of :abbr:`reST <reStructuredText>`
                                    files for standalone pages. See `Pages`_
                                    for more information.
:py:`THEME_COLOR: str`              Color for :html:`<meta name="theme-color" />`,
                                    corresponding to the CSS style. If empty,
                                    no :html:`<meta>` tag is rendered. See
                                    `Theme selection`_ for more information.
:py:`FAVICON: str`                  Favicon URL, used to populate
                                    :html:`<link rel="icon" />`. If empty, no
                                    :html:`<link>` tag is rendered. Relative
                                    paths are searched relative to :py:`INPUT`
                                    and to the ``python.py`` script dir as a
                                    fallback. See `Theme selection`_ for more
                                    information.
:py:`STYLESHEETS: List[str]`        List of CSS files to include. Relative
                                    paths are searched relative to :py:`INPUT`
                                    and to the ``python.py`` script dir as a
                                    fallback. See `Theme selection`_ for more
                                    information.
:py:`HTML_HEADER: str`              HTML code to put at the end of the
                                    :html:`<head>` element. Useful for linking
                                    arbitrary JavaScript code or, for example,
                                    adding :html:`<link>` CSS stylesheets with
                                    additional properties and IDs that are
                                    otherwise not possible with just
                                    :py:`STYLESHEETS`.
:py:`EXTRA_FILES: List[str]`        List of extra files to copy (for example
                                    additional CSS files that are :css:`@import`\ ed
                                    from the primary one). Relative paths are
                                    searched relative to :py:`INPUT` and to the
                                    ``python.py`` script dir as a fallback.
:py:`LINKS_NAVBAR1: List[Any]`      Left navbar column links. See
                                    `Navbar links`_ for more information.
:py:`LINKS_NAVBAR2: List[Any]`      Right navbar column links. See
                                    `Navbar links`_ for more information.
:py:`PAGE_HEADER: str`              :abbr:`reST <reStructuredText>` markup to
                                    put at the top of every page. If not set,
                                    nothing is added anywhere. The
                                    ``{url}`` placeholder is replaced with
                                    current file URL.
:py:`FINE_PRINT: str`               :abbr:`reST <reStructuredText>` markup to
                                    put into the footer. If not set, a default
                                    generic text is used. If empty, no footer
                                    is rendered at all.
:py:`FORMATTED_METADATA: List[str]` Which metadata fields should be formatted
                                    in documentation pages. By default only
                                    the ``summary`` field is.
:py:`PLUGINS: List[str]`            List of `plugins <{filename}/plugins.rst>`_
                                    to use. See `Plugins`_ for more
                                    information.
:py:`PLUGIN_PATHS: List[str]`       Additional plugin search paths. Relative
                                    paths are relative to :py:`INPUT`.
:py:`CLASS_INDEX_EXPAND_LEVELS`     How many levels of the class index tree to
                                    expand. :py:`0` means only the top-level
                                    symbols are shown. If not set, :py:`1` is
                                    used.
:py:`CLASS_INDEX_EXPAND_INNER`      Whether to expand inner classes in the
                                    class index. If not set, :py:`False` is
                                    used.
:py:`NAME_MAPPING: Dict[str, str]`  Additional name mapping in addition to
                                    what's figured out from the ``__all__``
                                    members
:py:`PYBIND11_COMPATIBILITY: bool`  Enable some additional tricks for better
                                    compatibility with pybind11. If not set,
                                    :py:`False` is used. See
                                    `pybind11 compatibility`_ for more
                                    information.
:py:`ATTRS_COMPATIBILITY: bool`     Enable some additional tricks for better
                                    compatibility with attrs. If not set,
                                    :py:`False` is used. See
                                    `attrs compatibility`_ for more
                                    information.
:py:`SEARCH_DISABLED: bool`         Disable search functionality. If this
                                    option is set, no search data is compiled
                                    and the rendered HTML does not contain
                                    search-related UI or support. If not set,
                                    :py:`False` is used.
:py:`SEARCH_DOWNLOAD_BINARY`        Download search data as a binary to save
                                    bandwidth and initial processing time. If
                                    not set, :py:`False` is used. See `Search options`_
                                    for more information.
:py:`SEARCH_FILENAME_PREFIX: str`   Search data filename prefix. Useful to
                                    prevent file conflicts if both C++ and
                                    Python documentation shares the same
                                    directory. If not set, ``searchdata`` is
                                    used.
:py:`SEARCH_RESULT_ID_BYTES: int`   Search data packing option. A value of
                                    :py:`2`, :py:`3` or :py:`4` is allowed. If
                                    not set, :py:`2` is used. See
                                    `Search options`_ for more information.
:py:`SEARCH_FILE_OFFSET_BYTES: int` Search data packing option. A value of
                                    :py:`3` or :py:`4` is allowed. If not set,
                                    :py:`3` is used. See `Search options`_ for
                                    more information.
:py:`SEARCH_NAME_SIZE_BYTES: int`   Search data packing option. A value of
                                    :py:`1` or :py:`2` is allowed. If not set,
                                    :py:`1` is used. See `Search options`_ for
                                    more information.
:py:`SEARCH_HELP: str`              :abbr:`reST <reStructuredText>` markup to
                                    display as help text on empty search popup.
                                    If not set, a default message is used. Has
                                    effect only if :py:`SEARCH_DISABLED` is not
                                    :py:`True`.
:py:`SEARCH_BASE_URL: str`          Base URL for OpenSearch-based search engine
                                    suggestions for web browsers. See
                                    `Search options`_ for more information. Has
                                    effect only if :py:`SEARCH_DISABLED` is not
                                    :py:`True`.
:py:`SEARCH_EXTERNAL_URL: str`      URL for external search. The ``{query}``
                                    placeholder is replaced with urlencoded
                                    search string. If not set, no external
                                    search is offered. See `Search options`_
                                    for more information. Has effect only if
                                    :py:`SEARCH_DISABLED` is not :py:`True`.
:py:`DOCUTILS_SETTINGS: Dict[Any]`  Additional docutils settings. Key/value
                                    pairs as described in `the docs <http://docutils.sourceforge.net/docs/user/config.html>`_.
:py:`URL_FORMATTER: Callable`       Function for creating filenames and URLs
                                    for modules, classes, pages and index
                                    pages. See `Custom URL formatters`_ for
                                    more information.
:py:`ID_FORMATTER: Callable`        Function for creating link anchors for
                                    module and class members. See
                                    `Custom URL formatters`_ for more
                                    information.
=================================== ===========================================

`Theme selection`_
------------------

By default, the `dark m.css theme <{filename}/css/themes.rst#dark>`_ together
with documentation-theme-specific additions is used, which corresponds to the
following configuration:

.. code:: py

    STYLESHEETS = [
        'https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600',
        '../css/m-dark+documentation.compiled.css']
    THEME_COLOR = '#22272e'
    FAVICON = 'favicon-dark.png'

If you have a site already using the ``m-dark.compiled.css`` file, there's
another file called ``m-dark.documentation.compiled.css``, which contains just
the documentation-theme-specific additions so you can reuse the already cached
``m-dark.compiled.css`` file from your main site:

.. code:: ini

    STYLESHEETS = [
        'https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600',
        '../css/m-dark.compiled.css',
        '../css/m-dark.documentation.compiled.css']
    THEME_COLOR = '#22272e'
    FAVICON = 'favicon-dark.png'

If you prefer the `light m.css theme <{filename}/css/themes.rst#light>`_
instead, use the following configuration (and, similarly, you can use
``m-light.compiled.css`` together with ``m-light.documentation.compiled-css``
in place of ``m-light+documentation.compiled.css``:

.. code:: ini

    STYLESHEETS = [
        'https://fonts.googleapis.com/css?family=Libre+Baskerville:400,400i,700,700i%7CSource+Code+Pro:400,400i,600',
        '../css/m-light+documentation.compiled.css']
    THEME_COLOR = '#cb4b16'
    FAVICON = 'favicon-light.png'

See the `CSS files`_ section below for more information about customizing the
CSS files.

`Navbar links`_
---------------

The :py:`LINKS_NAVBAR1` and :py:`LINKS_NAVBAR2` options define which links are
shown on the top navbar, split into left and right column on small screen
sizes. These options take a list of :py:`(title, path, sub)` tuples ---
``title`` is the link title; ``path`` is either one of :py:`'index'`,
:py:`'pages'`, :py:`'modules'` or :py:`'classes'` (linking to the main page or
page / module / class index path), a full URL (pasted as-is) or a *path* to a
particular page or module/class (in the form of
:py:`['module', 'sub', 'ClassName']` for :py:`module.sub.ClassName`, which then
gets formatted according to `URL formatting rules <#custom-url-formatters>`_);
and ``sub`` is an optional submenu, containing :py:`(title, path)` tuples, with
``path`` being interpreted the same way.

By default the variables are defined like following --- there's just three
items in the left column, with no submenus and the right column is empty:

.. code:: py

    LINKS_NAVBAR1 = [
        ('Pages', 'pages', []),
        ('Modules', 'modules', []),
        ('Classes', 'classes', [])]
    LINKS_NAVBAR2 = []

A menu item is highlighted if a page with the same path is the current page.
The ``path`` can be also a full URL --- if it contains a scheme prefix (such as
``https://``), then it's taken as-is, without conversion.

`Search options`_
-----------------

Symbol search is implemented using JavaScript Typed Arrays and does not need
any server-side functionality to perform well --- the client automatically
downloads a tightly packed binary containing search data and performs search
directly on it.

However, due to `restrictions of Chromium-based browsers <https://bugs.chromium.org/p/chromium/issues/detail?id=40787&q=ajax%20local&colspec=ID%20Stars%20Pri%20Area%20Feature%20Type%20Status%20Summary%20Modified%20Owner%20Mstone%20OS>`_,
it's not possible to download data using :js:`XMLHttpRequest` when served from
a local file-system. Because of that, the search defaults to producing a
Base85-encoded representation of the search binary and loading that
asynchronously as a plain JavaScript file. This results in the search data
being 25% larger, but since this is for serving from a local filesystem, it's
not considered a problem. If your docs are accessed through a server (or you
don't need Chrome support), set the :py:`SEARCH_DOWNLOAD_BINARY` option to
:py:`True`. The search data are by default fetched from the current directory
on the webserver, if you want to supply a different location, set it to a
string and provide a `custom URL formatter <#custom-url-formatters>`_.

The site can provide search engine metadata using the `OpenSearch <http://www.opensearch.org/>`_
specification. On supported browsers this means you can add the search field to
search engines and search directly from the address bar. To enable search
engine metadata, point :py:`SEARCH_BASE_URL` to base URL of your documentation,
for example:

.. code:: py

    SEARCH_BASE_URL = 'https://doc.magnum.graphics/magnum/'

In general, even without the above setting, appending ``?q={query}#search`` to
the URL will directly open the search popup with results for ``{query}``.

.. note-info::

    OpenSearch also makes it possible to have autocompletion and search results
    directly in the browser address bar. However that requires a server-side
    search implementation and is not supported at the moment.

If :py:`SEARCH_EXTERNAL_URL` is specified, full-text search using an external
search engine is offered if nothing is found for given string or if the user
has JavaScript disabled. It's recommended to restrict the search to a
particular domain or add additional keywords to the search query to filter out
irrelevant results. Example, using Google search engine and restricting the
search to a subdomain:

.. code:: py

    SEARCH_EXTERNAL_URL = 'https://google.com/search?q=site:doc.magnum.graphics+{query}'

The search binary is implicitly made with the tightest packing possible for
smallest download sizes. On large projects with tens of thousands of symbols it
may however happen that the data won't fit and doc generation fails with an
exception such as the following, suggesting you to increase the packed type
sizes:

    OverflowError: Trie result ID too large to store in 16 bits, set
    SEARCH_RESULT_ID_BYTES = 3 in your conf.py.

The relevant `configuration`_ is :py:`SEARCH_RESULT_ID_BYTES`,
:py:`SEARCH_FILE_OFFSET_BYTES` and :py:`SEARCH_NAME_SIZE_BYTES`. Simply update
your ``conf.py`` with suggested values and restart the generator. Due to the
way the search data get processed during serialization it's unfortunately not
feasible to estimate the packing sizes beforehand.

`Custom URL formatters`_
------------------------

The :py:`URL_FORMATTER` option allows you to control how *all* filenames and
generated URLs look like. It takes an entry type and a "path" as a list of
strings (so for example :py:`my.module.Class` is represented as
:py:`['my', 'module', 'Class']`), returning a tuple of a filename and an URL.
Those can be the same, but also different (for example a file getting saved
into ``my/module/Class/index.html`` but the actual URL being
``https://docs.my.module/Class/``). The default implementation looks like this,
producing both filenames and URLs in the form of ``my.module.Class.html``:

.. include:: ../../../documentation/python.py
    :code: py
    :start-after: # [default-url-formatter]
    :end-before: # [/default-url-formatter]

The ``type`` is an enum, if you don't want to fiddle with imports, compare
:py:`type.name` against a string, which is one of :py:`'PAGE'`, :py:`'MODULE'`,
:py:`'CLASS'`, :py:`'SPECIAL'` or :py:`'STATIC'`. The :py:`'SPECIAL'` is for
index pages and in that case the ``path`` has always just one item, one of
:py:`'pages'`, :py:`'modules'` or :py:`'classes'`. The :py:`'STATIC'` is for
static data such as images or CSS files and the ``path`` is absolute input
filename including the extension and except for search data (which are
generated on-the-fly) it always exists. If the static path is an URL, the URL
formatter is not called.

The :py:`ID_FORMATTER` handles formatting of anchors on a page. Again it takes
an entry type (which in this case is always one of :py:`'ENUM'`,
:py:`'ENUM_VALUE'`, :py:`'FUNCTION'`, :py:`'PROPERTY'`, :py:`'DATA'` or, in
case of pybind11 code, :py:`'OVERLOADED_FUNCTION'`. The second parameter is
again a path, being always just one item except for :py:`'ENUM_VALUE'` (in
which case it's enum name and value name together) and for
:py:`'OVERLOADED_FUNCTION'`, in which case it contains also a llist of argument
types. The default implementation simply returns the the path concatenated with
dashes:

.. code:: py

    def default_id_formatter(type: EntryType, path: List[str]) -> str:
        return '-'.join(path)

`Module inspection`_
====================

By default, if a module contains the :py:`__all__` attribute, *all* names
listed there are exposed in the documentation. Otherwise, all module (and
class) members are extracted using :py:`inspect.getmembers()`, skipping names
:py:`import`\ ed from elsewhere and undocumented underscored names.
Additionally, class data members with type annotations (but with no values) are
pulled out from :py:`__annotations__`, allowing you to expose (and document)
also fields that might otherwise only be populated from :py:`__init__()`:

.. code:: py

    class MyClass:
        a_float: float
        string_value: str

Detecting if a module is a submodule of the current package or if it's
:py:`import`\ ed from elsewhere is tricky, the script thus includes only
submodules that have their :py:`__package__` property the same or one level
below the parent package. If a module's :py:`__package__` is empty, it's
assumed to be a plain module (instead of a package) and since those can't have
submodules, all found submodules in it are ignored.

`Documentation-only overrides`_
-------------------------------

While the inspection and autodetection follows the structure of the original
code, it might not be always desirable to show it exactly that way in the docs.
Fortunately, thanks to Python's dynamic nature, a lot can be done by
`monkey-patching <https://en.wikipedia.org/wiki/Monkey_patch>`_ during doc
generation.

In case the autodetection includes more than you want or, conversely, you need
to include names that would otherwise be excluded (such as underscored names),
you can temporarily override the :py:`__all__` attribute when generating the
docs. For example, the following will list just the :py:`pow()` and :py:`log()`
functions from the :py:`math` module, ignoring the rest:

.. code:: py

    import math
    math.__all__ = ['pow', 'log']

    INPUT_MODULES = [math]

In other cases, especially when native modules are involved, the inspected name locations might not be what you want. By putting the names into :py:`__all__`
you tell the script it should map the inspected location to the one provided.
Note you should also hide the original location from the script to avoid
duplicate definitions (unless it's underscored, in which case it'll get ignored
automatically).

.. code:: py

    # module math

    from _native_math import fast_sin as sin
    from _native_math import fast_cos as cos
    __all__ = ['sin', 'cos']

Additionally, for mapping types of external libraries where the autodetection
from :py:`__all__` can't be performed, you can use the :py:`NAME_MAPPING`
option:

.. code:: py

    NAME_MAPPING = {
        'fastmath._native.Vector3': 'fastmath.Vector3',
        'fastmath._native.Quaternion': 'fastmath.Quaternion',
        # or, equivalently, if the mapping is the same for all members:
        'fastmath._native': 'fastmath'
    }

.. block-warning:: Overrides based an environment variable

    When m.css is run, an environment variable named
    :sh:`$MCSS_GENERATING_OUTPUT` is set. This can be used for *really dirty*
    hacks when monkey-patching imported modules is not enough (for example in
    order to change behavior inside native modules).

`Docstrings`_
-------------

By default, the first paragraph of a module-level, class-level and
function-level docstring is used as a doc summary, copied as-is to the output
without formatting it in any way. What follows is put (again without
formatting) paragraph-by-paragraph into detailed docs.

.. code:: py

    """Module summary

    First paragraph of module detailed docs."""

    class Foo:
        """Class summary"""

        def bar(self):
            """Function summary"""

Using just docstrings, however, comes with a few limitations:

-   Class and module-level variables can't have a docstring attached due to how
    Python works
-   Because not every Python API can be documented using docstrings, the
    output contains everything, including undocumented names
-   Instance variables added inside :py:`__init__()` are not extracted, as this
    would require parsing Python code directly (which is what Sphinx has to do
    to support these). You can work around this by adding annotated
    "declarations" to the class as `shown above <#module-inspection>`_, however
    no docstrings can be specified for those either.

To overcome the limitations, `externally-supplied documentation <#external-documentation-content>`_
provides means to document names that can't have a docstring attached, and
together with the `m.sphinx`_ plugin expanding formatting capabilities beyond
plain text.

`Function and variable annotations`_
------------------------------------

The script uses :py:`inspect.signature()` to query function parameter / return
type annotations together with default values and displays them in the output.
Similar is for module and class variables, extracted from the
:py:`__annotations__` property. If a variable type implements :py:`__repr__()`,
a :py:`repr()` of it is printed as the value, otherwise the value is omitted.

.. code:: py

    from typing import Tuple, List

    def foo(a: str, be_nice: bool = True) -> Tuple[int, str]:
        pass

    SETTINGS: List[Tuple[str, bool]] = []

For better readability, if the function signature contains type annotations or
a default value, the arguments are printed each on one line. Otherwise, to
avoid wasting vertical space, the arguments are listed on a single line.

Similarly to how the builtin :py:`help()` in Python 3.7 started annotating
boundaries between position-only, position-or-keyword and keyword-only
arguments with ``/`` and ``*``, the same is done here --- it's especially
helpful for native functions, where you can for example call :py:`math.sin(0.3)`
but not :py:`math.sin(x=0.3)`, because the ``x`` argument is positional-only.
Currently, positional-only arguments are possible only with native functions,
`PEP570 <https://www.python.org/dev/peps/pep-0570/>`_ adds them for pure Python
functions as well.

In some cases, especially when documenting native functions, the signature
can't be extracted and the function signature shows just an ellipsis (``…``)
instead of the actual argument list.

`Class methods, static methods, dunder methods, properties`_
------------------------------------------------------------

Methods decorated with :py:`@classmethod` are put into a "Class methods"
section, :py:`@staticmethod`\ s into a "Static methods" section.
Double-underscored methods explicitly implemented in the class are put into a
"Special methods" section, otherwise they're ignored --- by default, Python
adds a large collection of dunder methods to each class and the only way to
know if the method is user-provided or implicit is by checking the docstring.

.. code:: py

    class MyClass:
        @classmethod
        def a_classmethod(cls):
            """A class method"""

        @staticmethod
        def a_staticmethod():
            """A static method"""

        def __init__(self, foo, bar):
            """A constructor"""

Properties added to classes either using the :py:`@property` decorator or
created with the :py:`property()` builtin are added to the "Properties"
section. Each property is annotated with :label-flat-success:`get set del` if
it has a getter, a setter and a :py:`del`\ eter or with :label-flat-warning:`get`
and other variants if it has just some. The docstring and type annotation is
extracted from the property getter.

.. code:: py

    from typing import Tuple

    class MyClass:
        @property
        def a_read_write_property(self) -> Tuple[int, int]:
            """A read-write tuple property"""

        @a_read_write_property.setter
        def a_read_write_property(self, a):
            # Docstring and type annotation taken from the getter, no need to
            # have it repeated here too
            pass

`Documenting enum values`_
--------------------------

Python supplies an implicit docstrings for enums derived from :py:`enum.Enum`
and enum values implicitly inherit the docstring of the enum class. If either
is detected to be the case, docstring of the enum or the value is ignored.
While it's possible to document enum classes the usual way, there's a
non-obvious way to document enum values as well.

.. code:: py

    import enum

    class MyEnum(enum.Enum):
        """My enum"""

        ZERO = 0
        TWO = 3
        CONSISTENCY = -73

    MyEnum.ZERO.__doc__ = "Zero value"
    MyEnum.TWO.__doc__ = "Three, but named TWO for compatibility"

The documentation output for enums includes enum value values and the class it
was derived from, so it's possible to know whether it's an enum or a flag.

`Including underscored names in the output`_
--------------------------------------------

By default, names starting with an underscore (except for :py:`__dunder__`
methods) are treated as private and not listed in the output. One way to expose
them is to list them in :py:`__all__`, however that works for module content
only. For exposing general underscored names, you either need to provide a
docstring or `external documentation content`_ (and in case of plain data,
external documentation content is the only option).

Note that at the point where modules and classes are crawled for members,
docstrings are *not* parsed yet --- so e.g. a data documentation via a
:rst:`:data:` option of the :rst:`.. py:class::` `m.sphinx`_ directive won't be
visible to the initial crawl and thus the data will stay hidden.

Sometimes, however, you'll want the inverse --- keeping an underscored name
hidden, even though it has a docstring. Solution is to remove the docstring
while generating the docs, directly in the ``conf.py`` file during module
import:

.. code:: py

    import mymodule
    mymodule._private_thing.__doc__ = None

    INPUT_MODULES = [mymodule]

`Pages`_
========

In addition to documentation generated by inspecting particular module, it's
possible to add dedicated documentation pages. Content is written in
:abbr:`reST <reStructuredText>` (see
`Writing reST content <{filename}/themes/writing-rst-content.rst>`_ for a short
introduction) and taken from files specified in :py:`INPUT_PAGES`. Filenames
are interpreted relative to configuration file path, output filename is input
basename with extension replaced to ``.html``. In particular, content of
a ``index.rst`` file is used for the documentation main page. Example:

.. code:: py

    INPUT_PAGES = ['pages/index.rst']

.. code:: rst

    My Python library
    =================

    :summary: Welcome on the main page!

    This is a documentation of the mypythonlib module. You can use it like
    this:

    .. code:: py

        import mypythonlib
        mypythonlib.foo()

Apart from :py:`:summary:`, the page can have any number of metadata, with all
of them exposed as properties of ``page`` in the `output templates`_. Fields
listed in :py:`FORMATTED_METADATA` (the :py:`:summary:` is among them) are
expected to be formatted as :abbr:`reST <reStructuredText>` and exposed as
HTML, otherwise as a plain text.

All referenced images are expected to have either an absolute URL or be
relative to :py:`INPUT`, the ones with relative paths are then copied directly
to :py:`OUTPUT` with the leading dirs stripped from the path.

`Plugins`_
==========

The :abbr:`reST <reStructuredText>` content is not limited to just the builtin
functionality and it's possible to extend it via plugins either
`from m.css itself <{filename}/plugins.rst>`_ or 3rd party ones. See
documentation of each plugin to see its usage; the
`m.htmlsanity <{filename}/plugins/htmlsanity.rst>`_ plugin is used
unconditionally while all others are optional. For example, enabling the common
m.css plugins might look like this:

.. code:: py

    PLUGINS = ['m.code', 'm.components', 'm.dox']

`External documentation content`_
=================================

Because it's often not feasible to have the whole documentation stored in
Python docstrings, the generator allows you to supply documentation from
external files. Similarly to `pages`_, the :py:`INPUT_DOCS` setting is a list
of :abbr:`reST <reStructuredText>` files that contain documentation for
particular names using custom directives. A set of custom directives is
provided by the `m.sphinx <{filename}/plugins/sphinx.rst>`_ plugin --- see its documentation for detailed description of all features. Below is a simple
example of using it to document a class:

.. code:: py

    PLUGINS = ['m.sphinx']
    INPUT_DOCS = ['docs.rst']

.. code:: rst

    .. py:class:: mymodule.sub.Class
        :summary: A pretty class

        This class is *pretty*.

`pybind11 compatibility`_
=========================

C++ bindings generated using `pybind11 <https://pybind11.readthedocs.io/>`_ do
not have all information accessible through introspection and thus the script
has to do a few pybind11-specific workarounds to generate expected output. This
behavior is not enabled by default as it *might* have unwanted consequences in
pure Python code, enable it using the :py:`PYBIND11_COMPATIBILITY` option.

`Function signatures, property annotations`_
--------------------------------------------

For reasons explained in :gh:`pybind/pybind11#990`, pybind11 is not able to
provide function signatures through introspection and thus the script falls
back to parsing argument names, type annotations and default values from the
docstring instead. By default, unless :cpp:`py::arg()` is used, function
arguments are positional-only (shown as :py:`arg0`, :py:`arg1`, ...) and marked
as such in the output.

Similarly, property types are extracted from getter docstrings.

Unlike Python, pybind11 has a builtin support for overloaded functions ---
depending on types passed to a function, it dispatches to a particular C++
overload. The overloads are expanded in the output as well, meaning you can see
one function mentioned more than once with different signatures.

Because static methods in pybind11 are not decorated with :py:`@staticmethod`,
they are detected based on presence of ``self`` as the first parameter --- if
it's there, it's an instance method, otherwise it's a static method.

.. block-warning:: Limitations

    The static / instance method autodetection may fail when you name the first
    argument of a static method as :cpp:`py::arg("self")`. Don't do that |wink|

    The signature parsing can't handle all cases and, especially when templated
    C++ type names leak through, it may fail to extract the argument names. If
    that happens, the function signature shows just an ellipsis (``…``). On the
    other hand, encountering a pure C++ type in a Python function signature
    most probably points to a problem with the bindings as the type can't be
    expressed with Python code.

`Enums`_
--------

Enums in pybind11 are not derived from :py:`enum.Enum`, but rather are plain
classes. The only reliable way to detect a pybind11 enum is by looking for a
``__members__`` member, which is a dict providing string names and their
corresponding values. With pybind 2.2, it's only possible to document the
enum class itself, not the values.

.. note-info::

    pybind 2.3 supports docstrings for enum values (see
    :gh:`pybind/pybind11#1160`). Support for this feature is not done on the
    script side yet.

`attrs compatibility`_
======================

If a codebase is using the `attrs <https://www.attrs.org/>`_ package and the
:py:`ATTRS_COMPATIBILITY` option is enabled, the script is able to extract the
(otherwise inaccessible by normal means) information about attributes defined
using :py:`attr.ib()` or via the :py:`@attr.s(auto_attribs=True)` decorator.
Note that attributes of classes using :py:`@attr.s(slots=True)` are visible
even without the compatibility enabled.

In all cases, there's no possibility of adding in-source docstrings for any of
these and you need to supply the documentation with the :rst:`.. py:property::`
directive as described in `External documentation content`_.

Additionally, various dunder methods that say just "*Automatically created by
attrs.*" in their docstring are implicitly hidden from the output if this
option is enabled. In order to show them again, override the docstring to
something meaningful.

`Command-line options`_
=======================

.. code:: sh

    ./python.py [-h] [--templates TEMPLATES] [--debug] conf

Arguments:

-   ``conf`` --- configuration file

Options:

-   ``-h``, ``--help`` --- show this help message and exit
-   ``--templates TEMPLATES`` --- template directory. Defaults to the
    ``templates/python/`` subdirectory if not set.
-   ``--debug`` --- verbose logging output. Useful for debugging.

`Implementing custom plugins`_
==============================

Third-party plugins can be loaded from paths specified in :py:`PLUGIN_PATHS`.
Custom plugins need to implement a registration function named
:py:`register_mcss()`. It gets passed the following named arguments and the
plugin might or might not use them.

.. class:: m-table

=============================== ===============================================
Keyword argument                Content
=============================== ===============================================
:py:`mcss_settings`             Dict containing all m.css settings
:py:`jinja_environment`         Jinja2 environment. Useful for adding new
                                filters etc.
:py:`module_doc_contents`       Module documentation contents
:py:`class_doc_contents`        Class documentation contents
:py:`enum_doc_contents`         Enum documentation contents
:py:`enum_value_doc_contents`   Enum documentation contents
:py:`function_doc_contents`     Function documentation contents
:py:`property_doc_contents`     Property documentation contents
:py:`data_doc_contents`         Data documentation contents
:py:`hooks_post_crawl`          Hooks to call after the initial name crawl
:py:`hooks_pre_scope`           Hooks to call on scope enter
:py:`hooks_post_scope`          Hooks to call on scope exit
:py:`hooks_docstring`           Hooks to call when parsing a docstring
:py:`hooks_pre_page`            Hooks to call before each page gets rendered
:py:`hooks_post_run`            Hooks to call at the very end of the script run
=============================== ===============================================

The :py:`module_doc_contents`, :py:`class_doc_contents`, :py:`enum_doc_contents`,
:py:`enum_value_doc_contents`, :py:`function_doc_contents`,
:py:`property_doc_contents` and :py:`data_doc_contents` variables are
:py:`Dict[str, Dict[str, str]]`, where the first level is a name and second
level are key/value pairs of the actual HTML documentation content. Plugins
that parse extra documentation inputs (such as `m.sphinx`_) are supposed to add
to the dict, which is then used to fill the actual documentation contents. The
following corresponds to the documentation source shown in the
`External documentation content`_ section below. Note that the dict can already
have existing entries added from elsewhere, so it's important to avoid fully
overwriting it:

.. code:: py

    docs = class_doc_contents.setdefault('mymodule.sub.Class', {})
    docs['summary'] = "A pretty class"
    docs['details'] = "This class is *pretty*."

The :py:`hooks_post_crawl`, :py:`hooks_docstring`, :py:`hooks_pre_page` and
:py:`hooks_post_run` variables are lists of functions. Plugins that need to do
something at specific points of the execution are supposed to add functions to
the list.

The :py:`hooks_post_crawl` is called once gathering of all names is done. It
gets passed the following arguments:

.. class:: m-table

=================== ===========================================================
Keyword argument    Content
=================== ===========================================================
:py:`name_map`      Map with all gathered module, class, enum, function,
                    property, data and page metadata. Plugins are allowed to
                    read from it (for example to serialize them to a file for
                    searching or linking from other projects) as well as write
                    to it (for example to allow linking to names from external
                    projects). Key is a name, value has at the following
                    properties:

                    .. class:: m-table

                    =================== =======================================
                    Property            Description
                    =================== =======================================
                    :py:`type`          Entry type. Same as the enum passed to
                                        `custom URL formatters`_.
                    :py:`object`        Object which the entry documents. This
                                        property being :py:`None` means this
                                        entry is external [1]_; if not present
                                        at all there's :py:`filename` instead.
                    :py:`filename`      File this entry documents. Present only
                                        for :py:`EntryType.PAGE` or
                                        :py:`EntryType.SPECIAL`.
                    :py:`path`          Path. Equivalent to :py:`key.split('.')`.
                    :py:`url`           URL to the entry documentation,
                                        formatted with `custom URL formatters`_.
                    :py:`css_classes`   List of CSS classes to add to the
                                        :html:`<a>` tag. Internal entries
                                        usually have :py:`['m-doc']` while
                                        external have :py:`['m-doc-external']`.
                    =================== =======================================
=================== ===========================================================

.. [1] As this distinguishes between internal and external entries, new entries
    added by the plugin *need* to have :py:`object` set to :py:`None` so the
    script as well as other plugins can correctly distinguish them.

The :py:`hooks_pre_scope` and :py:`hooks_post_scope` get called before entering
and after leaving a name scope (page, module, class, enum, enum value,
function, property or data), and are meant mainly to aid with context-sensitive
linking. Those scopes can be nested and can be called successively for the same
scope --- for example, when rendering module docs, :py:`hooks_pre_scope` gets
called first for the module scope, but then another :py:`hooks_pre_scope` gets
called when rendering a summary for reference to an inner class. Then,
:py:`hooks_post_scope` gets called in reverse order. The plugins are expected
to implement a stack-like data structure for maintaining information about
current scope. Both of those functions get passed the following arguments:

.. class:: m-table

=================== ===========================================================
Keyword argument    Content
=================== ===========================================================
:py:`type`          Type of the scope that's being entered or exited. Same as
                    the enum passed to `custom URL formatters`_.
:py:`path`          Path of the module / class / function / enum / enum value /
                    data scope that's being entered or exited. A list of names,
                    :py:`'.'.join(path)` is equivalent to the fully qualified
                    name.
:py:`param_names`   In case of functions, list of parameter names. This
                    argument is not present otherwise.
=================== ===========================================================

Hooks listed in :py:`hooks_docstring` are called when docstrings are parsed,
and always preceded by a corresponding :py:`hooks_pre_scope` call. The first
listed hook gets the raw docstring only processed by :py:`inspect.cleandoc()`
and each following gets the output of the previous. When a hook returns an
empty string, hooks later in the list are not called. String returned by the
last hook is processed, if any, the same way as if no hooks would be present
--- it gets partitioned into summary and content and those put to the output
as-is, each paragraph wrapped in :html:`<p>` tags. The hooks are free to do
anything with the docstring --- extracting metadata from it and returning it
as-is, transpiling it from one markup language to another, or fully consuming
it, populating the ``*_doc_contents`` variables mentioned above and returning
nothing back. Each hook gets passed the following arguments:

.. class:: m-table

=================== ===========================================================
Keyword argument    Content
=================== ===========================================================
:py:`type`          Name type. Same as the enum passed to
                    `custom URL formatters`_.
:py:`path`          Path of the module / class / function / enum / enum value /
                    data containing the docstring. A list of names,
                    :py:`'.'.join(path)` is equivalent to the fully qualified
                    name.
:py:`signature`     Signature of a function, for distinguishing between
                    particular overloads. In a form of
                    ``(param1: type1, param2: type2)``.
:py:`doc`           Docstring content. Always non-empty --- once a hook returns
                    nothing back, no further hooks are called.
=================== ===========================================================

The :py:`hooks_pre_page` is called before each page of output gets rendered.
Can be used for example for resetting some internal counter for page-wide
unique element IDs. The :py:`hooks_post_run` is called after the whole run is
done, useful for example to serialize cached internal state. Currently, those two functions get no arguments passed.

Registration function for a plugin that needs to query the :py:`OUTPUT` setting
might look like this --- the remaining keyword arguments will collapse into
the :py:`**kwargs` parameter. See code of various m.css plugins for actual
examples. The below example shows registration of a hypothetic HTML validator
plugin --- it saves the output path from settings and registers a post-run hook
that validates everything in given output directory.

.. code:: py

    output_dir = None


    def _validate_output():
        validate_all_html_files(output_dir)

    def register_mcss(mcss_settings, hooks_post_run, **kwargs):
        global output_dir
        output_dir = mcss_settings['OUTPUT']
        hooks_post_run += [_validate_output]

`Customizing the template`_
===========================

The rest of the documentation explains how to customize the builtin template to
better suit your needs. Each documentation file is generated from one of the
template files that are bundled with the script. However, it's possible to
provide your own Jinja2 template files for customized experience as well as
modify the CSS styling.

`CSS files`_
------------

By default, compiled CSS files are used to reduce amount of HTTP requests and
bandwidth needed for viewing the documentation. However, for easier
customization and debugging it's better to use the unprocessed stylesheets. The
:py:`STYLESHEETS` option lists all files that go to the
:html:`<link rel="stylesheet" />` in the resulting HTML markup, while
:py:`EXTRA_FILES` list the indirectly referenced files that need to be copied
to the output as well. Below is an example configuration corresponding to the
dark theme:

.. code:: py

    STYLESHEETS = [
        'https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600',
        '../css/m-dark.css',
        '../css/m-documentation.css']
    EXTRA_FILES = [
        '../css/m-grid.css',
        '../css/m-components.css',
        '../css/pygments-dark.css',
        '../css/pygments-console.css']
    THEME_COLOR = '#22272e'

After making desired changes to the source files, it's possible to postprocess
them back to the compiled version using the ``postprocess.py`` utility as
explained in the `CSS themes <{filename}/css/themes.rst#make-your-own>`_
documentation. In case of the dark theme, the ``m-dark+documentation.compiled.css``
and ``m-dark.documentation.compiled.css`` files are produced like this:

.. code:: sh

    cd css
    ./postprocess.py m-dark.css m-documentation.css -o m-dark+documentation.compiled.css
    ./postprocess.py m-dark.css m-documentation.css --no-import -o m-dark.documentation.compiled.css

`Output templates`_
-------------------

Each output file is rendered with one of these templates:

.. class:: m-table m-fullwidth

======================= =======================================================
Filename                Use
======================= =======================================================
``module.html``         Module documentation
``class.html``          Class documentation
``page.html``           Explicit documentation pages, including the main page
======================= =======================================================

Each template gets passed all configuration values from the `Configuration`_
table as-is, together with a :py:`URL` variable with URL of given output file.
In addition to builtin Jinja2 filters, the ``format_url`` filter returns either
a path formatted according to `custom URL formatters`_, if the path is relative;
or a full URL, if the argument is an absolute URL. It's useful in cases like
this:

.. code:: html+jinja

  {% for css in HTML_EXTRA_STYLESHEET %}
  <link rel="stylesheet" href="{{ css|format_url|e }}" />
  {% endfor %}

The actual page contents are provided in a :py:`page` object, which has the
following properties. All exposed data are meant to be passed directly to the
HTML markup without any additional escaping.

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`page.summary`                      Doc summary
:py:`page.filename`                     File name [4]_
:py:`page.url`                          File URL [4]_
:py:`page.breadcrumb`                   List of :py:`(title, URL)` tuples for
                                        breadcrumb navigation.
:py:`page.content`                      Detailed documentation, if any
======================================= =======================================

Each module page, rendered with ``module.html``, has the following additional
properties:

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`page.prefix_wbr`                   Fully-qualified symbol prefix for given
                                        compound with trailing ``.`` with
                                        :html:`<wbr/>` tag after every ``.``.
:py:`page.modules`                      List of inner modules. See
                                        `Module properties`_ for details.
:py:`page.classes`                      List of classes. See
                                        `Class properties`_ for details.
:py:`page.enums`                        List of enums. See
                                        `Enum properties`_ for details.
:py:`page.functions`                    List of module-level functions. See
                                        `Function properties`_ for details.
:py:`page.data`                         List of module-level data. See
                                        `Data properties`_ for details.
:py:`page.has_enum_details`             If there is at least one enum with full
                                        description block [3]_
:py:`page.has_function_details`         If there is at least one function (or
                                        method, in case of classes) with full
                                        description block [3]_
:py:`page.has_data_details`             If there is at least one data with full
                                        description block [3]_
======================================= =======================================

Each class page, rendered with ``class.html``, has the following additional
properties:

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`page.classmethods`                 List of class methods (annotated with
                                        :py:`@classmethod`). See
                                        `Function properties`_ for details.
:py:`page.staticmethods`                List of static methods (annotated with
                                        :py:`@staticmethod`). See
                                        `Function properties`_ for details.
:py:`page.methods`                      List of methods. See
                                        `Function properties`_ for details.
:py:`page.dunder_methods`               List of double-underscored special
                                        functions. See
                                        `Function properties`_ for details.
:py:`page.properties`                   List of properties. See
                                        `Property properties`_ for details.
:py:`page.has_property_details`         If there is at least one property with
                                        full description block [3]_
======================================= =======================================

Explicit documentation pages rendered with ``class.html`` have additional
properties taken from input metadata. If given metadata is listed in
:py:`FORMATTED_METADATA`, it's rendered into HTML, otherwise it's exposed as
plain text.

`Module properties`_
````````````````````

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`module.url`                        URL of detailed module documentation
:py:`module.name`                       Module name
:py:`module.summary`                    Doc summary
======================================= =======================================

`Class properties`_
```````````````````

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`class_.url`                        URL of detailed class documentation
:py:`class_.name`                       Class name
:py:`class_.summary`                    Doc summary
======================================= =======================================

`Enum properties`_
```````````````````

.. class:: m-table m-fullwidth

======================================= =======================================
Property                                Description
======================================= =======================================
:py:`enum.name`                         Enum name
:py:`enum.id`                           Enum ID [5]_
:py:`enum.summary`                      Doc summary
:py:`enum.content`                      Detailed documentation, if any
:py:`enum.base`                         Base class from which the enum is
                                        derived. Set to :py:`None` if no base
                                        class information is available.
:py:`enum.base_link`                    Like :py:`enum.base`, but with
                                        cross-linked types
:py:`enum.values`                       List of enum values
:py:`enum.has_details`                  If there is enough content for the full
                                        description block. [3]_
:py:`enum.has_value_details`            If the enum values have description.
                                        Impies :py:`enum.has_details`.
======================================= =======================================

Every item of :py:`enum.values` has the following properties:

.. class:: m-table m-fullwidth

=========================== ===================================================
Property                    Description
=========================== ===================================================
:py:`value.name`            Value name
:py:`value.id`              Value ID [5]_
:py:`value.value`           Value value. Set to :py:`None` if no value is
                            available.
:py:`value.content`         Value documentation, if any
=========================== ===================================================

`Function properties`_
``````````````````````

.. class:: m-table m-fullwidth

=================================== ===========================================
Property                            Description
=================================== ===========================================
:py:`function.name`                 Function name
:py:`function.id`                   Function ID [5]_
:py:`function.summary`              Doc summary
:py:`function.content`              Detailed documentation, if any
:py:`function.type`                 Function return type annotation [2]_
:py:`function.type_link`            Like :py:`function.type`, but with
                                    cross-linked types
:py:`function.params`               List of function parameters. See below for
                                    details.
:py:`function.exceptions`           List of exceptions raised by this function.
                                    See below for details.
:py:`function.has_complex_params`   Set to :py:`True` if the parameter list
                                    should be wrapped on several lines for
                                    better readability (for example when it
                                    contains type annotations or default
                                    arguments). Set to :py:`False` when
                                    wrapping on multiple lines would only
                                    occupy too much vertical space.
:py:`function.has_param_details`    If the function parameters are documented
:py:`function.return_value`         Return value documentation. Can be empty.
:py:`function.has_details`          If there is enough content for the full
                                    description block [3]_
:py:`function.is_classmethod`       Set to :py:`True` if the function is
                                    annotated with :py:`@classmethod`,
                                    :py:`False` otherwise.
:py:`function.is_staticmethod`      Set to :py:`True` if the function is
                                    annotated with :py:`@staticmethod`,
                                    :py:`False` otherwise.
=================================== ===========================================

The :py:`function.params` is a list of function parameters and their
description. Each item has the following properties:

.. class:: m-table m-fullwidth

=========================== ===================================================
Property                    Description
=========================== ===================================================
:py:`param.name`            Parameter name
:py:`param.type`            Parameter type annotation [2]_
:py:`param.type_link`       Like :py:`param.type`, but with cross-linked types
:py:`param.default`         Default parameter value, if any
:py:`param.kind`            Parameter kind, a string equivalent to one of the
                            `inspect.Parameter.kind <https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind>`_
                            values
:py:`param.content`         Detailed documentation, if any
=========================== ===================================================

In some cases (for example in case of native APIs), the parameters can't be
introspected. In that case, the parameter list is a single entry with ``name``
set to :py:`"..."` and the rest being empty.

The :py:`function.exceptions` is a list of exceptions types and descriptions.
Each item has the following properties:

.. class:: m-table m-fullwidth

=========================== ===================================================
Property                    Description
=========================== ===================================================
:py:`exception.type`        Exception type
:py:`exception.type_link`   Like :py:`exception`, but with a cross-linked type
:py:`exception.content`     Detailed documentation
=========================== ===================================================

`Property properties`_
``````````````````````

.. class:: m-table m-fullwidth

=================================== ===========================================
Property                            Description
=================================== ===========================================
:py:`property.name`                 Property name
:py:`property.id`                   Property ID [5]_
:py:`property.type`                 Property getter return type annotation [2]_
:py:`property.type_link`            Like :py:`property.type`, but with
                                    cross-linked types
:py:`property.summary`              Doc summary
:py:`property.content`              Detailed documentation, if any
:py:`property.exceptions`           List of exceptions raised when accessing
                                    this property. Same as
                                    :py:`function.exceptions` described in
                                    `function properties`_.
:py:`property.is_gettable`          If the property is gettable
:py:`property.is_settable`          If the property is settable
:py:`property.is_deletable`         If the property is deletable with :py:`del`
:py:`property.has_details`          If there is enough content for the full
                                    description block [3]_
=================================== ===========================================

`Data properties`_
``````````````````

.. class:: m-table m-fullwidth

=================================== ===========================================
Property                            Description
=================================== ===========================================
:py:`data.name`                     Data name
:py:`data.id`                       Data ID [5]_
:py:`data.type`                     Data type
:py:`data.type_link`                Like :py:`data.type_link`, but with
                                    cross-linked types
:py:`data.summary`                  Doc summary
:py:`data.content`                  Detailed documentation, if any
:py:`data.value`                    Data value representation
:py:`data.has_details`              If there is enough content for the full
                                    description block [3]_
=================================== ===========================================

`Index page templates`_
-----------------------

The following index pages are provided, showing a expandable tree of the
contents:

.. class:: m-table m-fullwidth

======================= =======================================================
Filename                Use
======================= =======================================================
``classes.html``        Class listing
``modules.html``        Module listing
``pages.html``          Page listing
======================= =======================================================

Each template is passed all configuration values from the `Configuration`_
table as-is, together with an :py:`URL`, as above. The navigation tree is
provided in an :py:`index` object, which has the following properties:

.. class:: m-table m-fullwidth

=========================== ===================================================
Property                    Description
=========================== ===================================================
:py:`index.classes`         List of all modules + classes
:py:`index.pages`           List of all pages
=========================== ===================================================

The form of each list entry is the same:

.. class:: m-table m-fullwidth

=============================== ===============================================
Property                        Description
=============================== ===============================================
:py:`i.kind`                    Entry kind (one of :py:`'module'`,
                                :py:`'class'` or :py:`'page'`)
:py:`i.name`                    Name
:py:`i.url`                     URL of the file with detailed documentation
:py:`i.summary`                 Doc summary
:py:`i.has_nestable_children`   If the list has nestable children (i.e., dirs
                                or namespaces)
:py:`i.children`                Recursive list of child entries
=============================== ===============================================

Module/class list is ordered in a way that all modules are before all classes.

-------------------------------

.. [2] :py:`i.type` is extracted out of function annotation. If the types
    aren't annotated, the annotation is empty.
.. [3] :py:`page.has_*_details` and :py:`i.has_details` are :py:`True` if
    there is detailed description, function parameter documentation or
    *documented* enum value listing that makes it worth to render the full
    description block. If :py:`False`, the member should be included only in
    the summary listing on top of the page to avoid unnecessary repetition.
.. [4] :py:`page.filename` and :py:`page.url` is generated by an URL formatter,
    see `Custom URL formatters`_ for more information
.. [5] :py:`i.id` is an ID used for linking to given entry on a page. Generated
    by an anchor formatter, see `Custom URL formatters`_ for more information.