mkdocs-apidescribed-plugin 1.1.0__tar.gz → 1.3.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.
@@ -8,3 +8,4 @@ __pycache__
8
8
  *.pyo
9
9
  *.egg-info
10
10
 
11
+ *.lock
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: mkdocs-apidescribed-plugin
3
- Version: 1.1.0
3
+ Version: 1.3.0
4
4
  Summary: mkdocs plugin to generate API documentation for Python programs
5
5
  Project-URL: Homepage, https://github.com/idlesign/mkdocs-apidescribed-plugin
6
6
  Project-URL: Documentation, https://mkdocs-apidescribed-plugin.readthedocs.org/
@@ -0,0 +1,2 @@
1
+
2
+ VERSION = '1.3.0'
@@ -7,6 +7,7 @@ log = get_plugin_logger(__name__)
7
7
  DEFAULT_CONFIG = {
8
8
  'debug': False, # show traceback
9
9
  'skip': False, # do not describe (allows instructions to be ignored)
10
+ 'error': 'describe', # error handling mode: ignore, describe, break
10
11
  'format': 'auto', # docstrings format (sphinx, google, numpy)
11
12
 
12
13
  'heading_base': 2, # headings base level
@@ -80,7 +81,15 @@ def config_merge(base: dict, *, upd: dict) -> dict:
80
81
  return out
81
82
 
82
83
 
83
- def get_config(src: str) -> dict:
84
- parsed = config_parse(src)
85
- merged = config_merge(DEFAULT_CONFIG, upd=parsed)
84
+ def get_config(src: str, *, base: dict | None = None) -> dict:
85
+ """Returns configuration built from the default one,
86
+ updated with the given base (e.g. a global config),
87
+ updated with the options parsed from the given source.
88
+
89
+ :param src: Options source (YAML).
90
+
91
+ :param base: Base configuration to use instead of the default one.
92
+
93
+ """
94
+ merged = config_merge(config_merge(DEFAULT_CONFIG, upd=base or {}), upd=config_parse(src))
86
95
  return merged
@@ -4,7 +4,7 @@ from markdown import Extension
4
4
  from markdown.preprocessors import Preprocessor
5
5
  from mkdocs.plugins import get_plugin_logger
6
6
 
7
- from .config import get_config
7
+ from .config import DEFAULT_CONFIG, get_config
8
8
  from .formatter import Formatter
9
9
  from .inspector import inspect
10
10
 
@@ -17,6 +17,10 @@ class ApidescribedProcessor(Preprocessor):
17
17
 
18
18
  cls_fmt = Formatter
19
19
 
20
+ def __init__(self, parser, *, global_config: dict | None = None):
21
+ super().__init__(parser)
22
+ self._global_config = global_config or {}
23
+
20
24
  @classmethod
21
25
  def process_instruction(cls, *, target: str, config: dict) -> list[str]:
22
26
  cls_fmt = cls.cls_fmt
@@ -72,13 +76,15 @@ class ApidescribedProcessor(Preprocessor):
72
76
  else:
73
77
  # end of an instruction options block
74
78
  debug = False
79
+ error_mode = "describe"
75
80
 
76
81
  try:
77
82
  target = instruction[0]
78
- config = get_config('\n'.join(instruction[1:]))
83
+ config = get_config('\n'.join(instruction[1:]), base=self._global_config)
79
84
 
80
85
  skip = config['skip']
81
86
  debug = config['debug']
87
+ error_mode = config['error']
82
88
 
83
89
  if skip:
84
90
  log.debug(f'Skipped instruction for: {target}')
@@ -86,10 +92,14 @@ class ApidescribedProcessor(Preprocessor):
86
92
  else:
87
93
  to_add = process_instruction(target=target, config=config)
88
94
 
89
- except Exception as e:
95
+ except Exception as error:
96
+
97
+ if error_mode == "break":
98
+ raise
90
99
 
91
- to_add = [Formatter.format_error(e, instruction=instruction, debug=debug)]
92
- log.exception('Automated API documentation error')
100
+ if error_mode == "describe":
101
+ to_add = [Formatter.format_error(error, instruction=instruction, debug=debug)]
102
+ log.exception('Automated API documentation error')
93
103
 
94
104
  finally:
95
105
  instruction.clear()
@@ -101,9 +111,15 @@ class ApidescribedProcessor(Preprocessor):
101
111
 
102
112
  class ApiDescribedExtension(Extension):
103
113
 
114
+ def __init__(self, **kwargs):
115
+ # Predeclare known options to allow arbitrary values via setConfig.
116
+ self.config = {key: [val, ""] for key, val in DEFAULT_CONFIG.items()}
117
+ super().__init__(**kwargs)
118
+
104
119
  def extendMarkdown(self, md):
105
120
  md.registerExtension(self)
106
- md.preprocessors.register(ApidescribedProcessor(md.parser), "apidescribed", 110)
121
+ md.preprocessors.register(
122
+ ApidescribedProcessor(md.parser, global_config=self.getConfigs()), "apidescribed", 110)
107
123
 
108
124
 
109
125
  def makeExtension(**kwargs):
@@ -0,0 +1,46 @@
1
+ import mkdocs
2
+ from material.extensions.emoji import twemoji, to_svg
3
+ from mkdocs.config import config_options
4
+ from mkdocs.config.defaults import MkDocsConfig
5
+ from mkdocs.plugins import get_plugin_logger
6
+
7
+ log = get_plugin_logger(__name__)
8
+
9
+
10
+ class ApiDescribedPlugin(mkdocs.plugins.BasePlugin):
11
+
12
+ config_scheme = (
13
+ ("config", config_options.Type(dict, default={})),
14
+ )
15
+
16
+ _required_extensions = [
17
+ 'mkdocs_apidescribed.extension', # this is our extension
18
+ 'admonition', # nice admonitions
19
+ 'md_in_html', # for proper indentation
20
+ 'pymdownx.details', # collapsible blocks
21
+ 'pymdownx.superfences', # for block embedding
22
+ 'pymdownx.emoji', # for icons
23
+ ]
24
+
25
+ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
26
+ extensions = config['markdown_extensions']
27
+ current_extensions = set(extensions)
28
+
29
+ for ext in self._required_extensions:
30
+ if ext not in current_extensions:
31
+ extensions.append(ext)
32
+
33
+ mdx_conf = config['mdx_configs'].setdefault('mkdocs_apidescribed.extension', {})
34
+ mdx_conf.update(self.config['config'])
35
+
36
+ icons_conf = config['mdx_configs'].setdefault('pymdownx.emoji', {})
37
+ icons_conf['emoji_index'] = twemoji
38
+ icons_conf['emoji_generator'] = to_svg
39
+
40
+ theme_features = config['theme']._vars.setdefault('features', [])
41
+
42
+ feature_annotate = 'content.code.annotate'
43
+ if feature_annotate not in theme_features:
44
+ theme_features.append(feature_annotate)
45
+
46
+ return config
@@ -1,2 +0,0 @@
1
-
2
- VERSION = '1.1.0'
@@ -1,8 +0,0 @@
1
- import mkdocs
2
- from mkdocs.plugins import get_plugin_logger
3
-
4
- log = get_plugin_logger(__name__)
5
-
6
-
7
- class ApiDescribedPlugin(mkdocs.plugins.BasePlugin):
8
- ...