-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_docs_easier.py
More file actions
74 lines (58 loc) · 2.25 KB
/
make_docs_easier.py
File metadata and controls
74 lines (58 loc) · 2.25 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Set shebang if needed
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 5 19:33:41 2025
@author: mano
"""
import ast
def extract_info(filename):
with open(filename, "r", encoding="utf-8") as file:
tree = ast.parse(file.read(), filename)
classes = []
functions = []
for node in ast.iter_child_nodes(tree):
if isinstance(node, ast.FunctionDef):
# Funciones a nivel de módulo
func_name = node.name
args = [arg.arg for arg in node.args.args]
docstring = ast.get_docstring(node)
functions.append((func_name, args, docstring))
elif isinstance(node, ast.ClassDef):
class_name = node.name
class_doc = ast.get_docstring(node)
methods = []
for item in node.body:
if isinstance(item, ast.FunctionDef):
method_name = item.name
args = [arg.arg for arg in item.args.args if arg.arg != 'self']
method_doc = ast.get_docstring(item)
methods.append((method_name, args, method_doc))
classes.append((class_name, class_doc, methods))
return classes, functions
def format_markdown(classes, functions):
md = []
if functions:
md.append("## Funciones a nivel de módulo\n")
for name, args, doc in functions:
md.append(f"### def {name}({', '.join(args)})\n")
if doc:
md.append(f"> {doc}\n")
md.append("") # Línea en blanco
if classes:
md.append("## Clases\n")
for class_name, class_doc, methods in classes:
md.append(f"### class {class_name}\n")
if class_doc:
md.append(f"> {class_doc}\n")
for method_name, args, doc in methods:
md.append(f"##### {method_name}({', '.join(args)})\n")
if doc:
md.append(f"> {doc}\n")
md.append("") # Línea en blanco
return "\n".join(md)
# Cambia el nombre del archivo por tu módulo
if __name__ == "__main__":
archivo = "INEAPIpy/INE_functions.py" # Reemplaza con tu archivo real
clases, funciones = extract_info(archivo)
markdown = format_markdown(clases, funciones)
print(markdown)