Skip to content

Commit e8ee48f

Browse files
committed
feat(doc): adding support for @Changed and @deprecated
1 parent 5a10801 commit e8ee48f

File tree

4 files changed

+73
-13
lines changed

4 files changed

+73
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ python3 -m arkdoc --help
2727
## Syntax
2828

2929
- `@brief <description>`: a single brief declaration is expected
30-
- `@param <name> <description>`: multiple `@param` declaration can be written
30+
- `@param <name> <description>`: multiple `@param` declarations can be written
3131
- `@details <description>`: a single detailed declaration is expected
32+
- `@deprecated <description>`: an optional deprecation notice
33+
- `@changed <version> <description>`: multiple `@changed` declarations can be written. Creates an optional change list to document when and how a function changed
3234
- `=begin` / code block / `=end`: a single code block (it can contain multiple lines) is expected
3335
- `@author <url>,<url>,...`: the url to the profiles of the authors must be separated by commas, spaces can be added
3436
- any line not starting with a `@<keyword>` will be ignored, unless it is enclosed in a `=begin`/`=end` block

arkdoc/generator/base.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _create_files_list(self, parsers: List[Parser]):
5656
def generate_index(self):
5757
raise NotImplementedError
5858

59-
def generate_sections(self, functions: List[spec.Function], with_hr: bool=False):
59+
def generate_sections(self, functions: List[spec.Function], with_hr: bool = False):
6060
sections = ""
6161

6262
for func in functions:
@@ -84,10 +84,38 @@ def generate_sections(self, functions: List[spec.Function], with_hr: bool=False)
8484
if func.desc.params
8585
else ""
8686
)
87+
maybe_deprecated_notice = (
88+
self.formatter.div(
89+
self.formatter.b("Deprecated"),
90+
": ",
91+
func.desc.deprecation_notice,
92+
self.formatter.new_line()
93+
)
94+
if func.desc.deprecation_notice
95+
else ""
96+
)
97+
maybe_changelists = (
98+
self.formatter.div(
99+
self.formatter.b("Changes"),
100+
":",
101+
self.formatter.new_line(),
102+
self.formatter.ul(
103+
[
104+
f"{self.formatter.b(c.version)}: {c.desc}"
105+
for c in sorted(func.desc.changelist, key=lambda change: change.version, reverse=True)
106+
]
107+
),
108+
self.formatter.new_line()
109+
)
110+
if func.desc.changelist
111+
else ""
112+
)
87113
content = self.formatter.div(
88114
self.formatter.div(self.formatter.inline_code(func.signature)),
89115
self.formatter.div(func.desc.brief),
90116
self.formatter.new_line(),
117+
maybe_deprecated_notice,
118+
maybe_changelists,
91119
self.formatter.div(self.formatter.b("Note"), ": ", func.desc.details) if func.desc.details else "",
92120
self.formatter.new_line(),
93121
authors,

arkdoc/generator/specification.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ class Param:
1515
desc: str
1616

1717

18+
@dataclass
19+
class Change:
20+
version: str
21+
desc: str
22+
23+
1824
@dataclass
1925
class Description:
2026
brief: str
2127
details: str
2228
params: List[Param]
2329
code: str
2430
authors: List[str]
31+
deprecation_notice: str
32+
changelist: List[Change]
2533

2634

2735
@dataclass

arkdoc/generator/utils.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
import re
44
from typing import Tuple, Dict
5+
from copy import deepcopy
56

67
from . import specification as spec
78
from ..parser import Documentation, Source
89
from .. import logger
910

11+
DEFAULT_KEYS = {
12+
"brief": "",
13+
"details": "",
14+
"param": [],
15+
"author": "",
16+
"deprecated": "",
17+
"changed": []
18+
}
19+
1020

1121
def extractor(data: Dict, doc: Documentation) -> Tuple[Dict, str]:
1222
in_code = False
@@ -42,42 +52,54 @@ def extractor(data: Dict, doc: Documentation) -> Tuple[Dict, str]:
4252
for i, param in enumerate(data["param"]):
4353
param_name, desc = param.split(" ", 1)
4454
data["param"][i] = spec.Param(param_name, desc)
55+
if "changed" in data:
56+
for i, changed in enumerate(data["changed"]):
57+
version, desc = changed.split(" ", 1)
58+
data["changed"][i] = spec.Change(version, desc)
4559
if "author" in data:
4660
data["author"] = [el.strip() for el in data["author"].split(",") if data["author"]]
4761

4862
return data, "\n".join(code)
4963

5064

65+
def describe(data: Dict, code: str) -> spec.Description:
66+
return spec.Description(
67+
brief=data["brief"],
68+
details=data["details"],
69+
params=data["param"],
70+
code=code,
71+
authors=data["author"],
72+
deprecation_notice=data["deprecated"],
73+
changelist=data["changed"]
74+
)
75+
76+
5177
def from_ark(doc: Documentation) -> spec.Function:
5278
_, name, args = doc.signature()
53-
data, code = extractor({"brief": "", "details": "", "param": [], "author": ""}, doc)
79+
data, code = extractor(deepcopy(DEFAULT_KEYS), doc)
5480

5581
if args is not None and len(data["param"]) != len(args):
5682
logger.warn(
57-
f"Function {name} was defined with {len(args)} arguments, "
83+
f"Function {name} was defined with {len(args)} argument(s), "
5884
f"but {len(data['param'])} are documented"
5985
)
6086

6187
return spec.Function(
6288
name,
6389
doc.pretty_signature,
64-
spec.Description(
65-
data["brief"], data["details"], data["param"], code, data["author"]
66-
),
90+
describe(data, code),
6791
)
6892

6993

7094
def from_cpp(doc: Documentation) -> spec.Function:
71-
data, code = extractor(
72-
{"name": "", "brief": "", "details": "", "param": [], "author": ""}, doc
73-
)
95+
parameters = {"name": ""}
96+
parameters.update(deepcopy(DEFAULT_KEYS))
97+
data, code = extractor(parameters, doc)
7498

7599
return spec.Function(
76100
data["name"],
77101
f"Builtin ({data['name']} {' '.join(e.name for e in data['param'])})",
78-
spec.Description(
79-
data["brief"], data["details"], data["param"], code, data["author"]
80-
),
102+
describe(data, code),
81103
)
82104

83105

0 commit comments

Comments
 (0)