|
2 | 2 | import os
|
3 | 3 | from pathlib import Path
|
4 | 4 | from textwrap import dedent
|
| 5 | +from typing import Any |
5 | 6 |
|
6 | 7 | root_dir = Path(__file__).parent
|
7 | 8 |
|
|
24 | 25 | )
|
25 | 26 | )
|
26 | 27 |
|
| 28 | + algo_sections: dict[str, list[str]] = {} |
| 29 | + |
27 | 30 | for function in functions:
|
28 | 31 | name, sig, ret_type = (
|
29 | 32 | function["function"]["name"],
|
30 | 33 | function["function"]["signature"],
|
31 | 34 | function["function"]["return_type"],
|
32 | 35 | )
|
33 |
| - fw.write(f".. py:function:: {name}({sig}) -> {ret_type}\n\n") |
| 36 | + algo_lines = [] |
| 37 | + |
| 38 | + algo_lines.append(f".. py:function:: {name}({sig}) -> {ret_type}\n\n") |
34 | 39 |
|
35 | 40 | if "description" in function:
|
36 | 41 | description = function["description"].strip()
|
37 | 42 | for desc in description.split("\n"):
|
38 |
| - fw.write(f" {desc}\n") |
| 43 | + algo_lines.append(f" {desc}\n") |
39 | 44 |
|
40 |
| - fw.write("\n") |
| 45 | + algo_lines.append("\n") |
41 | 46 |
|
42 | 47 | if "deprecated" in function:
|
43 | 48 | version, message = function["deprecated"]["version"], function["deprecated"]["message"]
|
44 |
| - fw.write(f".. deprecated:: {version}\n") |
45 |
| - fw.write(f" {message}\n\n") |
| 49 | + algo_lines.append(f".. deprecated:: {version}\n") |
| 50 | + algo_lines.append(f" {message}\n\n") |
| 51 | + |
| 52 | + algo_sections[name] = algo_lines |
| 53 | + |
| 54 | + # sort by name |
| 55 | + sorted_section = sorted(algo_sections.items(), key=lambda x: x[0]) |
| 56 | + |
| 57 | + for name, section in sorted_section: |
| 58 | + fw.writelines(section) |
0 commit comments