Skip to content

Commit 9c4e37c

Browse files
authored
Docstring markdown render overhaul (preserves markdown syntax), new features and bugfixes including no find_module AttributeError fix (#85)
* Revert workaround as sync-label bug was fixed in labeler-v5.0.0 * Updated missing documentation for mdx support * Fixes functions not rendered during markdown generation and no "find_module" AttributeError Caused by modules not correctly loaded into namespace from commit due to Issue #57. Modules now correctly loaded into namespace. Fixes AttributeError("'FileFinder' object has no attribute 'find_module'") (#69) Prioritized "find_spec" and falls back to "find_module" from loader if find_spec not available. Some whitespace removal. * Overhauled docstring render and added Github flavour admonition support Modify argument regex Fix Colon use in docstring in arguments blocks now formatted correctly. Change argument detection to last colon in line. Added support for "Reference" as a block header. Convert quote block to admonition blocks Added Github admonition quote block support. Added start line anchor to regex Changed "```" code snippet boundary detection from startswith to regex to prevent false positives. Rework docstring markdown render. Solves issue #80 Improved whitespace and newline rendering. Accepts more native markdown syntax without garbling render. Solves Issue #82 Enumerate the docstring to detect end of docstring to appropriately close literal blocks, doctest and code blocks Update literal blocks logic and format. Syntax is same as reStructured text * Render class __init__ method as constructor using class name * Support including private modules with, aka files with "_" prefix. Add private_modules arg * Add table of contents feature to module file * Fixed incorrect and unsafe src href link * Added feature for user override of url line anchor notation (#74) * Forced generated markdown file to be platform independent * Crude workaround for AttributeError, no attribute "__create_fn__" (#72) Observed in python 3.8, constructor for dataclasses had different function signature * Added rendering support for enum, dataclass, and exception * Updated API document example and bump version to 0.6.0
1 parent 5a645ab commit 9c4e37c

File tree

6 files changed

+540
-197
lines changed

6 files changed

+540
-197
lines changed

.github/workflows/pr-labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
repo-token: "${{ secrets.GITHUB_TOKEN }}"
1313
configuration-path: .github/pr-labeler-file-path.yml
1414
# workaround for problem: https://github.com/wesnoth/wesnoth/commit/958c82d0867568057caaf58356502ec8c87d8366
15-
sync-labels: ""
15+
sync-labels: false
1616
- uses: TimonVS/pr-labeler-action@v3
1717
with:
1818
configuration-path: .github/pr-labeler-branch-name.yml

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ lazydocs [OPTIONS] PATHS...
171171

172172
* `--output-path TEXT`: The output path for the creation of the markdown files. Set this to `stdout` to print all markdown to stdout. [default: ./docs/]
173173
* `--src-base-url TEXT`: The base repo link used as prefix for all source links. Should also include the branch name.
174+
* `--url-line-prefix TEXT`: Line prefix for git repository line url anchors #{prefix}line. If None provided, defaults to Github style notation.
174175
* `--overview-file TEXT`: Filename of overview file. If not provided, no API overview file will be generated.
175176
* `--remove-package-prefix / --no-remove-package-prefix`: If `True`, the package prefix will be removed from all functions and methods. [default: True]
176177
* `--ignored-modules TEXT`: A list of modules that should be ignored. [default: ]
177178
* `--watermark / --no-watermark`: If `True`, add a watermark with a timestamp to bottom of the markdown files. [default: True]
178179
* `--validate / --no-validate`: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed. [default: False]
180+
* `--output-format TEXT`: The output format for the creation of the markdown files. This may be 'md' or 'mdx'. Defaults to md.
181+
* `--private-modules / --no-private-modules`: If `True`, includes modules with "_" prefix. [default: False]
182+
* `--toc / --no-toc`: If `True`, includes table of contents in generated module markdown files. [default: False]
179183
* `--install-completion`: Install completion for the current shell.
180184
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
181185
* `--help`: Show this message and exit.

docs/lazydocs.generation.md

Lines changed: 146 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
<!-- markdownlint-disable -->
22

3-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
3+
<a href="../src/lazydocs/generation.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
44

55
# <kbd>module</kbd> `lazydocs.generation`
6-
Main module for markdown generation.
6+
Main module for markdown generation.
7+
8+
9+
## Table of Contents
10+
- [`MarkdownGenerator`](./lazydocs.generation.md#class-markdowngenerator)
11+
- [`__init__`](./lazydocs.generation.md#constructor-__init__)
12+
- [`class2md`](./lazydocs.generation.md#method-class2md)
13+
- [`func2md`](./lazydocs.generation.md#method-func2md)
14+
- [`import2md`](./lazydocs.generation.md#method-import2md)
15+
- [`module2md`](./lazydocs.generation.md#method-module2md)
16+
- [`overview2md`](./lazydocs.generation.md#method-overview2md)
17+
- [`toc2md`](./lazydocs.generation.md#method-toc2md)
18+
- [`generate_docs`](./lazydocs.generation.md#function-generate_docs)
19+
- [`to_md_file`](./lazydocs.generation.md#function-to_md_file)
20+
721

822

923
---
1024

11-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L197"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
25+
<a href="../src/lazydocs/generation.py#L223"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
1226

1327
## <kbd>function</kbd> `to_md_file`
1428

@@ -18,26 +32,28 @@ to_md_file(
1832
filename: str,
1933
out_path: str = '.',
2034
watermark: bool = True,
21-
disable_markdownlint: bool = True
35+
disable_markdownlint: bool = True,
36+
is_mdx: bool = False
2237
) → None
2338
```
2439

25-
Creates an API docs file from a provided text.
26-
40+
Creates an API docs file from a provided text.
2741

2842

2943
**Args:**
30-
31-
- <b>`markdown_str`</b> (str): Markdown string with line breaks to write to file.
32-
- <b>`filename`</b> (str): Filename without the .md
33-
- <b>`watermark`</b> (bool): If `True`, add a watermark with a timestamp to bottom of the markdown files.
34-
- <b>`disable_markdownlint`</b> (bool): If `True`, an inline tag is added to disable markdownlint for this file.
35-
- <b>`out_path`</b> (str): The output directory
44+
45+
- <b>`markdown_str`</b> (str): Markdown string with line breaks to write to file.
46+
- <b>`filename`</b> (str): Filename without the .md
47+
- <b>`out_path`</b> (str): The output directory.
48+
- <b>`watermark`</b> (bool): If `True`, add a watermark with a timestamp to bottom of the markdown files.
49+
- <b>`disable_markdownlint`</b> (bool): If `True`, an inline tag is added to disable markdownlint for this file.
50+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
51+
3652

3753

3854
---
3955

40-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L889"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
56+
<a href="../src/lazydocs/generation.py#L1158"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
4157

4258
## <kbd>function</kbd> `generate_docs`
4359

@@ -49,173 +65,225 @@ generate_docs(
4965
src_base_url: Optional[str] = None,
5066
remove_package_prefix: bool = False,
5167
ignored_modules: Optional[List[str]] = None,
68+
output_format: Optional[str] = None,
5269
overview_file: Optional[str] = None,
5370
watermark: bool = True,
54-
validate: bool = False
71+
validate: bool = False,
72+
private_modules: bool = False,
73+
include_toc: bool = False,
74+
url_line_prefix: Optional[str] = None
5575
) → None
5676
```
5777

58-
Generates markdown documentation for provided paths based on Google-style docstrings.
59-
78+
Generates markdown documentation for provided paths based on Google-style docstrings.
6079

6180

6281
**Args:**
63-
64-
- <b>`paths`</b>: Selected paths or import name for markdown generation.
65-
- <b>`output_path`</b>: The output path for the creation of the markdown files. Set this to `stdout` to print all markdown to stdout.
66-
- <b>`src_root_path`</b>: The root folder name containing all the sources. Fallback to git repo root.
67-
- <b>`src_base_url`</b>: The base url of the github link. Should include branch name. All source links are generated with this prefix.
68-
- <b>`remove_package_prefix`</b>: If `True`, the package prefix will be removed from all functions and methods.
69-
- <b>`ignored_modules`</b>: A list of modules that should be ignored.
70-
- <b>`overview_file`</b>: Filename of overview file. If not provided, no overview file will be generated.
71-
- <b>`watermark`</b>: If `True`, add a watermark with a timestamp to bottom of the markdown files.
72-
- <b>`validate`</b>: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed.
82+
83+
- <b>`paths`</b>: Selected paths or import name for markdown generation.
84+
- <b>`output_path`</b>: The output path for the creation of the markdown files. Set this to `stdout` to print all markdown to stdout.
85+
- <b>`src_root_path`</b>: The root folder name containing all the sources. Fallback to git repo root.
86+
- <b>`src_base_url`</b>: The base url of the github link. Should include branch name. All source links are generated with this prefix.
87+
- <b>`remove_package_prefix`</b>: If `True`, the package prefix will be removed from all functions and methods.
88+
- <b>`ignored_modules`</b>: A list of modules that should be ignored.
89+
- <b>`output_format`</b>: Markdown file extension and format.
90+
- <b>`overview_file`</b>: Filename of overview file. If not provided, no overview file will be generated.
91+
- <b>`watermark`</b>: If `True`, add a watermark with a timestamp to bottom of the markdown files.
92+
- <b>`validate`</b>: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed.
93+
- <b>`private_modules`</b>: If `True`, includes modules with `_` prefix.
94+
- <b>`url_line_prefix: Line prefix for git repository line url anchors. Default`</b>: None - github "L".
95+
7396

7497

7598
---
7699

77-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L454"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
100+
<a href="../src/lazydocs/generation.py#L627"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
78101

79102
## <kbd>class</kbd> `MarkdownGenerator`
80-
Markdown generator class.
103+
Markdown generator class.
81104

82-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L457"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
83105

84-
### <kbd>method</kbd> `__init__`
106+
<a href="../src/lazydocs/generation.py#L630"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
107+
108+
### <kbd>constructor</kbd> `__init__`
85109

86110
```python
87-
__init__(
111+
MarkdownGenerator(
88112
src_root_path: Optional[str] = None,
89113
src_base_url: Optional[str] = None,
90-
remove_package_prefix: bool = False
114+
remove_package_prefix: bool = False,
115+
url_line_prefix: Optional[str] = None
91116
)
92117
```
93118

94-
Initializes the markdown API generator.
95-
119+
Initializes the markdown API generator.
96120

97121

98122
**Args:**
99-
100-
- <b>`src_root_path`</b>: The root folder name containing all the sources.
101-
- <b>`src_base_url`</b>: The base github link. Should include branch name. All source links are generated with this prefix.
102-
- <b>`remove_package_prefix`</b>: If `True`, the package prefix will be removed from all functions and methods.
123+
124+
- <b>`src_root_path`</b>: The root folder name containing all the sources.
125+
- <b>`src_base_url`</b>: The base github link. Should include branch name.
126+
All source links are generated with this prefix.
127+
- <b>`remove_package_prefix`</b>: If `True`, the package prefix will be removed from all functions and methods.
128+
- <b>`url_line_prefix: Line prefix for git repository line url anchors. Default`</b>: None - github "L".
129+
103130

104131

105132

106133

107134
---
108135

109-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L609"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
136+
<a href="../src/lazydocs/generation.py#L795"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
110137

111138
### <kbd>method</kbd> `class2md`
112139

113140
```python
114-
class2md(cls: Any, depth: int = 2) → str
141+
class2md(cls: Any, depth: int = 2, is_mdx: bool = False) → str
115142
```
116143

117-
Takes a class and creates markdown text to document its methods and variables.
118-
144+
Takes a class and creates markdown text to document its methods and variables.
119145

120146

121147
**Args:**
122-
123-
- <b>`cls`</b> (class): Selected class for markdown generation.
124-
- <b>`depth`</b> (int, optional): Number of # to append to function name. Defaults to 2.
125148

149+
- <b>`cls`</b> (class): Selected class for markdown generation.
150+
- <b>`depth`</b> (int, optional): Number of # to append to function name. Defaults to 2.
151+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
126152

127153

128154
**Returns:**
129-
130-
- <b>`str`</b>: Markdown documentation for selected class.
155+
156+
- <b>`str`</b>: Markdown documentation for selected class.
157+
131158

132159
---
133160

134-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L524"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
161+
<a href="../src/lazydocs/generation.py#L706"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
135162

136163
### <kbd>method</kbd> `func2md`
137164

138165
```python
139-
func2md(func: Callable, clsname: str = '', depth: int = 3) → str
166+
func2md(
167+
func: Callable,
168+
clsname: str = '',
169+
depth: int = 3,
170+
is_mdx: bool = False
171+
) → str
140172
```
141173

142-
Takes a function (or method) and generates markdown docs.
143-
174+
Takes a function (or method) and generates markdown docs.
144175

145176

146177
**Args:**
147-
148-
- <b>`func`</b> (Callable): Selected function (or method) for markdown generation.
149-
- <b>`clsname`</b> (str, optional): Class name to prepend to funcname. Defaults to "".
150-
- <b>`depth`</b> (int, optional): Number of # to append to class name. Defaults to 3.
151178

179+
- <b>`func`</b> (Callable): Selected function (or method) for markdown generation.
180+
- <b>`clsname`</b> (str, optional): Class name to prepend to funcname. Defaults to "".
181+
- <b>`depth`</b> (int, optional): Number of # to append to class name. Defaults to 3.
182+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
152183

153184

154185
**Returns:**
155-
156-
- <b>`str`</b>: Markdown documentation for selected function.
186+
187+
- <b>`str`</b>: Markdown documentation for selected function.
188+
157189

158190
---
159191

160-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L815"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
192+
<a href="../src/lazydocs/generation.py#L1046"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
161193

162194
### <kbd>method</kbd> `import2md`
163195

164196
```python
165-
import2md(obj: Any, depth: int = 1) → str
197+
import2md(
198+
obj: Any,
199+
depth: int = 1,
200+
is_mdx: bool = False,
201+
include_toc: bool = False
202+
) → str
166203
```
167204

168-
Generates markdown documentation for a selected object/import.
169-
205+
Generates markdown documentation for a selected object/import.
170206

171207

172208
**Args:**
173-
174-
- <b>`obj`</b> (Any): Selcted object for markdown docs generation.
175-
- <b>`depth`</b> (int, optional): Number of # to append before heading. Defaults to 1.
176209

210+
- <b>`obj`</b> (Any): Selcted object for markdown docs generation.
211+
- <b>`depth`</b> (int, optional): Number of # to append before heading. Defaults to 1.
212+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
213+
- <b>`include_toc`</b> (bool, Optional): Include table of contents for module file. Defaults to False.
177214

178215

179216
**Returns:**
180-
181-
- <b>`str`</b>: Markdown documentation of selected object.
217+
218+
- <b>`str`</b>: Markdown documentation of selected object.
219+
182220

183221
---
184222

185-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L720"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
223+
<a href="../src/lazydocs/generation.py#L943"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
186224

187225
### <kbd>method</kbd> `module2md`
188226

189227
```python
190-
module2md(module: module, depth: int = 1) → str
228+
module2md(
229+
module: module,
230+
depth: int = 1,
231+
is_mdx: bool = False,
232+
include_toc: bool = False
233+
) → str
191234
```
192235

193-
Takes an imported module object and create a Markdown string containing functions and classes.
194-
236+
Takes an imported module object and create a Markdown string containing functions and classes.
195237

196238

197239
**Args:**
198-
199-
- <b>`module`</b> (types.ModuleType): Selected module for markdown generation.
200-
- <b>`depth`</b> (int, optional): Number of # to append before module heading. Defaults to 1.
201240

241+
- <b>`module`</b> (types.ModuleType): Selected module for markdown generation.
242+
- <b>`depth`</b> (int, optional): Number of # to append before module heading. Defaults to 1.
243+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
244+
- <b>`include_toc`</b> (bool, optional): Include table of contents in module file. Defaults to False.
202245

203246

204247
**Returns:**
205-
206-
- <b>`str`</b>: Markdown documentation for selected module.
248+
249+
- <b>`str`</b>: Markdown documentation for selected module.
250+
207251

208252
---
209253

210-
<a href="https://github.com/ml-tooling/lazydocs/blob/main/src/lazydocs/generation.py#L835"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
254+
<a href="../src/lazydocs/generation.py#L1068"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
211255

212256
### <kbd>method</kbd> `overview2md`
213257

214258
```python
215-
overview2md() → str
259+
overview2md(is_mdx: bool = False) → str
260+
```
261+
262+
Generates a documentation overview file based on the generated docs.
263+
264+
265+
**Args:**
266+
267+
- <b>`is_mdx`</b> (bool, optional): JSX support. Default to False.
268+
269+
270+
**Returns:**
271+
272+
- <b>`str`</b>: Markdown documentation of overview file.
273+
274+
275+
---
276+
277+
<a href="../src/lazydocs/generation.py#L1137"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>
278+
279+
### <kbd>method</kbd> `toc2md`
280+
281+
```python
282+
toc2md(module: module = None, is_mdx: bool = False) → str
216283
```
217284

218-
Generates a documentation overview file based on the generated docs.
285+
Generates table of contents for imported object.
286+
219287

220288

221289

src/lazydocs/_about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Information about this library. This file will automatically changed."""
22

3-
__version__ = "0.5.1"
3+
__version__ = "0.6.0"
44
# __author__
55
# __email__

0 commit comments

Comments
 (0)