|
1 | 1 | """Plugin for generate API docs.""" |
2 | 2 |
|
3 | 3 | # Import built-in modules |
| 4 | +from __future__ import annotations |
| 5 | + |
4 | 6 | import os |
5 | 7 | from pathlib import Path |
6 | 8 |
|
7 | | -# Import third-party modules |
8 | | -from jinja2 import Template |
9 | 9 | import mkdocs_gen_files |
10 | 10 | import stringcase |
11 | 11 |
|
| 12 | +# Import third-party modules |
| 13 | +from jinja2 import Template |
12 | 14 |
|
13 | 15 | template = Template( |
14 | 16 | r""" |
|
22 | 24 | ``` |
23 | 25 | {% endfor %} |
24 | 26 |
|
25 | | -""" |
| 27 | +""", |
26 | 28 | ) |
27 | 29 |
|
28 | 30 |
|
29 | | -class Examples(object): |
30 | | - def __init__(self, root: Path): |
| 31 | +class Examples: |
| 32 | + def __init__(self, root: Path) -> None: |
31 | 33 | self._root = root |
32 | 34 |
|
33 | | - def get_examples(self): |
34 | | - files = [file_ for file_ in self._root.glob("*.py") if "_psd_files.py" not in file_.as_posix()] |
35 | | - return files |
| 35 | + def get_examples(self) -> list[Path]: |
| 36 | + return [file_ for file_ in self._root.glob("*.py") if "_psd_files.py" not in file_.as_posix()] |
36 | 37 |
|
37 | 38 | @staticmethod |
38 | | - def convert_relative_path(file): |
| 39 | + def convert_relative_path(file: str) -> str: |
39 | 40 | path = file.split("examples")[1] |
40 | 41 | return "../examples{}".format(path.replace("\\", "/")) |
41 | 42 |
|
42 | 43 | @staticmethod |
43 | | - def get_name(file): |
44 | | - name = os.path.basename(file).split(".py")[0] |
| 44 | + def get_name(file: str) -> str: |
| 45 | + name = Path(file).name.split(".py")[0] |
45 | 46 | return stringcase.titlecase(name) |
46 | 47 |
|
47 | 48 | @staticmethod |
48 | | - def get_line(name): |
| 49 | + def get_line(name: str) -> str: |
49 | 50 | return "-" * len(name) |
50 | 51 |
|
51 | 52 | @staticmethod |
52 | | - def get_content(file_): |
53 | | - with open(file_, "r") as f: |
| 53 | + def get_content(file_: str) -> str: |
| 54 | + with Path(file_).open() as f: |
54 | 55 | return "".join(f.readlines()) |
55 | 56 |
|
56 | 57 |
|
57 | | -def main(): |
| 58 | +def main() -> None: |
58 | 59 | root = Path(__file__).parent.parent |
59 | 60 | with mkdocs_gen_files.open("examples.md", "w") as nav_file: |
60 | 61 | examples_data = Examples(root.joinpath("examples")) |
61 | 62 | nav_file.write(template.render(Examples=examples_data)) |
62 | 63 |
|
63 | 64 |
|
64 | | -if __name__ == "<run_path>": |
| 65 | +if __name__ == "__main__": |
65 | 66 | main() |
0 commit comments