mkdocs-apidescribed-plugin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mkdocs-apidescribed-plugin might be problematic. Click here for more details.
- mkdocs_apidescribed_plugin-0.1.0/.coveragerc +3 -0
- mkdocs_apidescribed_plugin-0.1.0/.gitignore +11 -0
- mkdocs_apidescribed_plugin-0.1.0/.readthedocs.yaml +12 -0
- mkdocs_apidescribed_plugin-0.1.0/AUTHORS +18 -0
- mkdocs_apidescribed_plugin-0.1.0/CHANGELOG +8 -0
- mkdocs_apidescribed_plugin-0.1.0/CONTRIBUTING +25 -0
- mkdocs_apidescribed_plugin-0.1.0/INSTALL +27 -0
- mkdocs_apidescribed_plugin-0.1.0/LICENSE +28 -0
- mkdocs_apidescribed_plugin-0.1.0/PKG-INFO +45 -0
- mkdocs_apidescribed_plugin-0.1.0/README.md +29 -0
- mkdocs_apidescribed_plugin-0.1.0/docs/config.md +25 -0
- mkdocs_apidescribed_plugin-0.1.0/docs/index.md +71 -0
- mkdocs_apidescribed_plugin-0.1.0/docs/showcase.md +33 -0
- mkdocs_apidescribed_plugin-0.1.0/mkdocs.yml +43 -0
- mkdocs_apidescribed_plugin-0.1.0/pyproject.toml +42 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/__init__.py +2 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/config.py +84 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/extension.py +104 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/formatter.py +304 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/inspector.py +205 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/parsers.py +229 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/plugin.py +8 -0
- mkdocs_apidescribed_plugin-0.1.0/src/mkdocs_apidescribed/probe.py +174 -0
- mkdocs_apidescribed_plugin-0.1.0/tests/__init__.py +0 -0
- mkdocs_apidescribed_plugin-0.1.0/tests/test_module.py +3 -0
- mkdocs_apidescribed_plugin-0.1.0/tools/buildme.py +13 -0
- mkdocs_apidescribed_plugin-0.1.0/uv.lock +648 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
mkdocs-apidescribed-plugin authors
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
Created by Igor `idle sign` Starikov.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Contributors
|
|
8
|
+
------------
|
|
9
|
+
|
|
10
|
+
Here could be your name.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Translators
|
|
15
|
+
-----------
|
|
16
|
+
|
|
17
|
+
Here could be your name.
|
|
18
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
mkdocs-apidescribed-plugin contributing
|
|
2
|
+
====================================
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Submit issues
|
|
6
|
+
-------------
|
|
7
|
+
|
|
8
|
+
If you spotted something weird in application behavior or want to propose a feature you are welcome.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Write code
|
|
12
|
+
----------
|
|
13
|
+
If you are eager to participate in application development and to work on an existing issue (whether it should
|
|
14
|
+
be a bugfix or a feature implementation), fork, write code, and make a pull request right from the forked project page.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Spread the word
|
|
18
|
+
---------------
|
|
19
|
+
|
|
20
|
+
If you have some tips and tricks or any other words that you think might be of interest for the others — publish it
|
|
21
|
+
wherever you find convenient.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
See also: https://github.com/idlesign/mkdocs-apidescribed-plugin
|
|
25
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
mkdocs-apidescribed-plugin installation
|
|
2
|
+
====================================
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Python ``pip`` package is required to install ``mkdocs-apidescribed-plugin``.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
From sources
|
|
9
|
+
------------
|
|
10
|
+
|
|
11
|
+
Use the following command line to install ``mkdocs-apidescribed-plugin`` from sources directory (containing setup.py):
|
|
12
|
+
|
|
13
|
+
pip install .
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
From PyPI
|
|
17
|
+
---------
|
|
18
|
+
|
|
19
|
+
Alternatively you can install ``mkdocs-apidescribed-plugin`` from PyPI:
|
|
20
|
+
|
|
21
|
+
pip install mkdocs-apidescribed-plugin
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Use `-U` flag for upgrade:
|
|
25
|
+
|
|
26
|
+
pip install -U mkdocs-apidescribed-plugin
|
|
27
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2025, Igor `idle sign` Starikov
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
* Neither the name of the mkdocs-apidescribed-plugin nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mkdocs-apidescribed-plugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: mkdocs plugin to generate API documentation for Python programs
|
|
5
|
+
Project-URL: Homepage, https://github.com/idlesign/mkdocs-apidescribed-plugin
|
|
6
|
+
Project-URL: Documentation, https://mkdocs-apidescribed-plugin.readthedocs.org/
|
|
7
|
+
Author-email: Igor Starikov <idlesign@yandex.ru>
|
|
8
|
+
License-Expression: BSD-3-Clause
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: api,mkdocs,plugin
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: griffe
|
|
13
|
+
Requires-Dist: mkdocs
|
|
14
|
+
Requires-Dist: pyyaml
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# mkdocs-apidescribed-plugin
|
|
18
|
+
|
|
19
|
+
https://github.com/idlesign/mkdocs-apidescribed-plugin
|
|
20
|
+
|
|
21
|
+
[](https://pypi.python.org/pypi/mkdocs-apidescribed-plugin)
|
|
22
|
+
[](https://pypi.python.org/pypi/mkdocs-apidescribed-plugin)
|
|
23
|
+
[](https://coveralls.io/r/idlesign/mkdocs-apidescribed-plugin)
|
|
24
|
+
|
|
25
|
+
## Description
|
|
26
|
+
|
|
27
|
+
*mkdocs plugin to generate API documentation for Python programs*
|
|
28
|
+
|
|
29
|
+
* Made to autodocument Python code
|
|
30
|
+
* Plays well with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
|
|
31
|
+
* Configurable
|
|
32
|
+
* Easy to use
|
|
33
|
+
|
|
34
|
+
Just add ``::: apidescribed:`` directive into your documentation followed by a module path:
|
|
35
|
+
|
|
36
|
+
```md title="index.md"
|
|
37
|
+
This is my documentation
|
|
38
|
+
|
|
39
|
+
::: apidescribed: somepackage.somemodule
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Documentation
|
|
44
|
+
|
|
45
|
+
https://mkdocs-apidescribed-plugin.readthedocs.org/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# mkdocs-apidescribed-plugin
|
|
2
|
+
|
|
3
|
+
https://github.com/idlesign/mkdocs-apidescribed-plugin
|
|
4
|
+
|
|
5
|
+
[](https://pypi.python.org/pypi/mkdocs-apidescribed-plugin)
|
|
6
|
+
[](https://pypi.python.org/pypi/mkdocs-apidescribed-plugin)
|
|
7
|
+
[](https://coveralls.io/r/idlesign/mkdocs-apidescribed-plugin)
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
*mkdocs plugin to generate API documentation for Python programs*
|
|
12
|
+
|
|
13
|
+
* Made to autodocument Python code
|
|
14
|
+
* Plays well with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
|
|
15
|
+
* Configurable
|
|
16
|
+
* Easy to use
|
|
17
|
+
|
|
18
|
+
Just add ``::: apidescribed:`` directive into your documentation followed by a module path:
|
|
19
|
+
|
|
20
|
+
```md title="index.md"
|
|
21
|
+
This is my documentation
|
|
22
|
+
|
|
23
|
+
::: apidescribed: somepackage.somemodule
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
https://mkdocs-apidescribed-plugin.readthedocs.org/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
To configure ``apidescribed`` one can use yaml just after ``::: apidescribed: `` directive:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
::: apidescribed: mkdocs_apidescribed.config
|
|
7
|
+
debug: true
|
|
8
|
+
categorize: false
|
|
9
|
+
only:
|
|
10
|
+
- DEFAULT_CONFIG
|
|
11
|
+
location:
|
|
12
|
+
mode: module
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
----
|
|
16
|
+
|
|
17
|
+
**All available configuration options are listed below:**
|
|
18
|
+
|
|
19
|
+
::: apidescribed: mkdocs_apidescribed.config
|
|
20
|
+
debug: true
|
|
21
|
+
categorize: false
|
|
22
|
+
only:
|
|
23
|
+
- DEFAULT_CONFIG
|
|
24
|
+
location:
|
|
25
|
+
mode: module
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
*mkdocs plugin to generate API documentation for Python programs*
|
|
4
|
+
|
|
5
|
+
* Made to autodocument Python code
|
|
6
|
+
* Plays well with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
|
|
7
|
+
* Configurable
|
|
8
|
+
* Easy to use
|
|
9
|
+
|
|
10
|
+
!!! tip
|
|
11
|
+
See demo in ``Showcase`` section.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
1. Python 3.10+
|
|
16
|
+
2. `mkdocs` package
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
``` shell
|
|
21
|
+
pip install mkdocs-apidescribed-plugin
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
1. Add ``apidescribed`` into ``mkdocs.yml``:
|
|
27
|
+
|
|
28
|
+
```yaml title="mkdocs.yml"
|
|
29
|
+
theme:
|
|
30
|
+
...
|
|
31
|
+
features:
|
|
32
|
+
...
|
|
33
|
+
- content.code.annotate # for parameter descriptions
|
|
34
|
+
|
|
35
|
+
markdown_extensions:
|
|
36
|
+
- mkdocs_apidescribed.extension # this is our extention
|
|
37
|
+
- admonition # nice admonitions
|
|
38
|
+
- pymdownx.superfences
|
|
39
|
+
- pymdownx.details # collapsible blocks
|
|
40
|
+
- md_in_html # for proper indentation
|
|
41
|
+
- pymdownx.emoji: # for icons
|
|
42
|
+
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
|
43
|
+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. Add ``::: apidescribed:`` directive into your documentation followed by a module path:
|
|
48
|
+
|
|
49
|
+
```md title="index.md"
|
|
50
|
+
This is my documentation
|
|
51
|
+
|
|
52
|
+
::: apidescribed: somepackage.somemodule
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Get involved into mkdocs-apidescribed
|
|
58
|
+
|
|
59
|
+
!!! success "Submit issues"
|
|
60
|
+
If you spotted something weird in application behavior or want to propose a feature you can do
|
|
61
|
+
that at <https://github.com/idlesign/mkdocs-apidescribed-plugin/issues>
|
|
62
|
+
|
|
63
|
+
!!! tip "Write code"
|
|
64
|
+
If you are eager to participate in application development,
|
|
65
|
+
fork it at <https://github.com/idlesign/mkdocs-apidescribed-plugin>, write
|
|
66
|
+
your code, whether it should be a bugfix or a feature implementation,
|
|
67
|
+
and make a pull request right from the forked project page.
|
|
68
|
+
|
|
69
|
+
!!! info "Spread the word"
|
|
70
|
+
If you have some tips and tricks or any other words in mind that
|
|
71
|
+
you think might be of interest for the others --- publish it.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Showcase
|
|
2
|
+
|
|
3
|
+
Let's document module ``mkdocs_apidescribed.probe``.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
::: apidescribed: mkdocs_apidescribed.probe
|
|
7
|
+
debug: true
|
|
8
|
+
ignore:
|
|
9
|
+
- "_*"
|
|
10
|
+
- "*ignore*"
|
|
11
|
+
```
|
|
12
|
+
**Below is automated documentation below.**
|
|
13
|
+
|
|
14
|
+
----
|
|
15
|
+
|
|
16
|
+
::: apidescribed: mkdocs_apidescribed.probe
|
|
17
|
+
debug: true
|
|
18
|
+
ignore:
|
|
19
|
+
- "_*"
|
|
20
|
+
- "*ignore*"
|
|
21
|
+
|
|
22
|
+
## Error example
|
|
23
|
+
|
|
24
|
+
Now let's try to document an unknown module ``somepackage.somemodule``,
|
|
25
|
+
using ``debug: true`` option for troubleshooting:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
::: apidescribed: somepackage.somemodule
|
|
29
|
+
debug: true
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
::: apidescribed: somepackage.somemodule
|
|
33
|
+
debug: true
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
site_name: mkdocs-apidescribed
|
|
2
|
+
site_url: !ENV READTHEDOCS_CANONICAL_URL
|
|
3
|
+
|
|
4
|
+
copyright: Copyright © 2025, Igor Starikov
|
|
5
|
+
|
|
6
|
+
repo_url: https://github.com/idlesign/mkdocs-apidescribed-plugin
|
|
7
|
+
edit_uri: edit/master/docs/
|
|
8
|
+
|
|
9
|
+
extra:
|
|
10
|
+
social:
|
|
11
|
+
- icon: fontawesome/brands/github
|
|
12
|
+
link: https://github.com/idlesign
|
|
13
|
+
|
|
14
|
+
plugins:
|
|
15
|
+
- search
|
|
16
|
+
|
|
17
|
+
theme:
|
|
18
|
+
name: material
|
|
19
|
+
palette:
|
|
20
|
+
primary: green
|
|
21
|
+
features:
|
|
22
|
+
- navigation.top
|
|
23
|
+
- toc.follow
|
|
24
|
+
- content.action.edit
|
|
25
|
+
- content.code.copy
|
|
26
|
+
- content.code.annotate
|
|
27
|
+
|
|
28
|
+
markdown_extensions:
|
|
29
|
+
- mkdocs_apidescribed.extension
|
|
30
|
+
- admonition
|
|
31
|
+
- pymdownx.highlight:
|
|
32
|
+
anchor_linenums: true
|
|
33
|
+
line_spans: __span
|
|
34
|
+
pygments_lang_class: true
|
|
35
|
+
- pymdownx.inlinehilite
|
|
36
|
+
- pymdownx.snippets
|
|
37
|
+
- pymdownx.superfences
|
|
38
|
+
- pymdownx.details
|
|
39
|
+
- attr_list
|
|
40
|
+
- md_in_html
|
|
41
|
+
- pymdownx.emoji:
|
|
42
|
+
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
|
43
|
+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mkdocs-apidescribed-plugin"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "mkdocs plugin to generate API documentation for Python programs"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name = "Igor Starikov", email = "idlesign@yandex.ru" }
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "BSD-3-Clause"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
keywords = ["mkdocs", "api", "plugin"]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"mkdocs",
|
|
15
|
+
"griffe",
|
|
16
|
+
"PyYAML",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/idlesign/mkdocs-apidescribed-plugin"
|
|
21
|
+
Documentation = "https://mkdocs-apidescribed-plugin.readthedocs.org/"
|
|
22
|
+
|
|
23
|
+
[project.entry-points."mkdocs.plugins"]
|
|
24
|
+
"apidescribed" = "mkdocs_apidescribed.plugin:ApiDescribedPlugin"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"mkdocs",
|
|
29
|
+
"mkdocs-material",
|
|
30
|
+
"pytest",
|
|
31
|
+
"ruff",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.version]
|
|
39
|
+
path = "src/mkdocs_apidescribed/__init__.py"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/mkdocs_apidescribed"]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import yaml
|
|
2
|
+
from mkdocs.plugins import get_plugin_logger
|
|
3
|
+
|
|
4
|
+
log = get_plugin_logger(__name__)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
DEFAULT_CONFIG = {
|
|
8
|
+
'debug': False, # show traceback
|
|
9
|
+
'skip': False, # do not describe (allows instructions to be ignored)
|
|
10
|
+
'format': 'auto', # docstrings format (sphinx, google, numpy)
|
|
11
|
+
|
|
12
|
+
'heading_base': 2, # headings base level
|
|
13
|
+
'autolinks': True, # automatically create hyperlinks
|
|
14
|
+
'categorize': True, # show symbol types (categories) titles
|
|
15
|
+
|
|
16
|
+
'location': {
|
|
17
|
+
# signature block title options
|
|
18
|
+
# hidden - do not show the block
|
|
19
|
+
# module - show module "path"
|
|
20
|
+
# file - show filepath
|
|
21
|
+
'mode': 'hidden',
|
|
22
|
+
'line': False, # show line number of source file
|
|
23
|
+
},
|
|
24
|
+
'icons': {
|
|
25
|
+
'attr': ':material-alpha:', # for attributes
|
|
26
|
+
'func': ':material-function:', # for functions
|
|
27
|
+
'cls': ':material-delta:', # for classes
|
|
28
|
+
'property': ':material-alpha-p-box-outline:', # for class properties
|
|
29
|
+
'classmethod': ':material-alpha-c-box-outline:', # for class properties
|
|
30
|
+
'staticmethod': ':material-alpha-s-box-outline:', # for class properties
|
|
31
|
+
'inherited': ':material-subdirectory-arrow-left:', # for class inherited items
|
|
32
|
+
'raises': ':material-lightning-bolt:', # for descriptions of raised exceptions
|
|
33
|
+
'returns': ':material-arrow-right-thin:', # for descriptions of returned value
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
'undocumented': False, # describe items without docstrings
|
|
37
|
+
'types': [
|
|
38
|
+
# symbol types to describe (order respected)
|
|
39
|
+
'attributes',
|
|
40
|
+
'functions',
|
|
41
|
+
'classes',
|
|
42
|
+
],
|
|
43
|
+
'ignore': [
|
|
44
|
+
# patterns of symbol names to ignore
|
|
45
|
+
'_*',
|
|
46
|
+
],
|
|
47
|
+
'only': [
|
|
48
|
+
# symbol names to describe (others will be ignored)
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
"""Default configuration for mkdocs-apidescribed."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def config_parse(src: str) -> dict:
|
|
55
|
+
try:
|
|
56
|
+
cfg = yaml.load(src, yaml.SafeLoader)
|
|
57
|
+
except yaml.MarkedYAMLError:
|
|
58
|
+
log.exception('Unable to parse options.')
|
|
59
|
+
cfg = {}
|
|
60
|
+
|
|
61
|
+
return cfg or {}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def config_merge(base: dict, *, upd: dict) -> dict:
|
|
65
|
+
out = {}
|
|
66
|
+
|
|
67
|
+
for key, val in base.items():
|
|
68
|
+
|
|
69
|
+
if (upd_val := upd.get(key)) is not None:
|
|
70
|
+
|
|
71
|
+
if isinstance(val, dict) and isinstance(upd_val, dict):
|
|
72
|
+
upd_val = config_merge(val, upd=upd_val)
|
|
73
|
+
|
|
74
|
+
val = upd_val
|
|
75
|
+
|
|
76
|
+
out[key] = val
|
|
77
|
+
|
|
78
|
+
return out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def get_config(src: str) -> dict:
|
|
82
|
+
parsed = config_parse(src)
|
|
83
|
+
merged = config_merge(DEFAULT_CONFIG, upd=parsed)
|
|
84
|
+
return merged
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from markdown import Extension
|
|
4
|
+
from markdown.preprocessors import Preprocessor
|
|
5
|
+
from mkdocs.plugins import get_plugin_logger
|
|
6
|
+
|
|
7
|
+
from .config import get_config
|
|
8
|
+
from .formatter import Formatter
|
|
9
|
+
from .inspector import inspect
|
|
10
|
+
|
|
11
|
+
log = get_plugin_logger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ApidescribedProcessor(Preprocessor):
|
|
15
|
+
|
|
16
|
+
RE_START = re.compile(r'^::: apidescribed:(.*)')
|
|
17
|
+
|
|
18
|
+
cls_fmt = Formatter
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def process_instruction(cls, *, target: str, config: dict) -> list[str]:
|
|
22
|
+
cls_fmt = cls.cls_fmt
|
|
23
|
+
out = []
|
|
24
|
+
last_type = ''
|
|
25
|
+
|
|
26
|
+
root, symbols = inspect(target, types=config['types'], ignore=config['ignore'], only=config['only'])
|
|
27
|
+
formatter = cls_fmt(symbol=root, config=config)
|
|
28
|
+
|
|
29
|
+
if prolog := formatter.run():
|
|
30
|
+
out.append(prolog)
|
|
31
|
+
|
|
32
|
+
for symbol in symbols:
|
|
33
|
+
formatter = cls_fmt(symbol=symbol, config=config)
|
|
34
|
+
|
|
35
|
+
if symbol.depth == 0:
|
|
36
|
+
if last_type != symbol.type.name and (categorized := formatter.format_category()):
|
|
37
|
+
out.append(categorized)
|
|
38
|
+
|
|
39
|
+
last_type = symbol.type.name
|
|
40
|
+
|
|
41
|
+
formatted = formatter.run()
|
|
42
|
+
out.append(formatted)
|
|
43
|
+
|
|
44
|
+
return out
|
|
45
|
+
|
|
46
|
+
def run(self, lines: list[str]) -> list[str]:
|
|
47
|
+
out = []
|
|
48
|
+
|
|
49
|
+
re_start = self.RE_START
|
|
50
|
+
process_instruction = self.process_instruction
|
|
51
|
+
instruction = []
|
|
52
|
+
|
|
53
|
+
for line in lines:
|
|
54
|
+
|
|
55
|
+
to_add = [line]
|
|
56
|
+
|
|
57
|
+
if matched := re_start.search(line):
|
|
58
|
+
instruction.append(matched[1].strip())
|
|
59
|
+
to_add = []
|
|
60
|
+
|
|
61
|
+
elif instruction:
|
|
62
|
+
if line.startswith(' '):
|
|
63
|
+
# new option for instruction
|
|
64
|
+
instruction.append(line)
|
|
65
|
+
to_add = []
|
|
66
|
+
else:
|
|
67
|
+
# end of an instruction options block
|
|
68
|
+
debug = False
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
target = instruction[0]
|
|
72
|
+
config = get_config('\n'.join(instruction[1:]))
|
|
73
|
+
|
|
74
|
+
skip = config['skip']
|
|
75
|
+
debug = config['debug']
|
|
76
|
+
|
|
77
|
+
if skip:
|
|
78
|
+
log.debug(f'Skipped instruction for: {target}')
|
|
79
|
+
|
|
80
|
+
else:
|
|
81
|
+
to_add = process_instruction(target=target, config=config)
|
|
82
|
+
|
|
83
|
+
except Exception as e:
|
|
84
|
+
|
|
85
|
+
to_add = [Formatter.format_error(e, instruction=instruction, debug=debug)]
|
|
86
|
+
log.exception('Automated API documentation error')
|
|
87
|
+
|
|
88
|
+
finally:
|
|
89
|
+
instruction.clear()
|
|
90
|
+
|
|
91
|
+
out.extend(to_add)
|
|
92
|
+
|
|
93
|
+
return out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ApiDescribedExtension(Extension):
|
|
97
|
+
|
|
98
|
+
def extendMarkdown(self, md):
|
|
99
|
+
md.registerExtension(self)
|
|
100
|
+
md.preprocessors.register(ApidescribedProcessor(md.parser), "apidescribed", 110)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def makeExtension(**kwargs):
|
|
104
|
+
return ApiDescribedExtension(**kwargs)
|