-
Notifications
You must be signed in to change notification settings - Fork 191
/
add_import_names.py
33 lines (28 loc) · 1.2 KB
/
add_import_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Creates updated_drivers.rst which includes import names for each module.
"""
if __name__ == "__main__":
with open("docs/drivers.rst", "r") as drivers_rst:
with open("updated_drivers.rst", "w") as updated_drivers_rst:
lines = drivers_rst.readlines()
for line in lines:
if "<https://docs.circuitpython.org/" in line:
docs_url = line.split("<")[1].split(">")[0]
# print(docs_url)
short_name = line.split("https://docs.circuitpython.org/projects/")[
1
].split("/en/latest/")[0]
insert_index = line.index("<") - 1
# print(f"adafruit_{short_name} | {insert_index}")
modified = (
line[:insert_index]
+ f" (adafruit_{short_name})"
+ line[insert_index:]
)
# print(modified)
updated_drivers_rst.write(modified)
else:
updated_drivers_rst.write(line)