MCPcopy Create free account
hub / github.com/ElementsProject/lightning / load_bolt

Function load_bolt

devtools/bolt-coverage.py:64–95  ·  view source on GitHub ↗

Load a BOLT file, split into sections. Returns (boltpath, sections) where sections is a list of (collapsed_text, linemap) pairs; linemap[i] is the original line number for collapsed_text[i].

(boltdir: str, num: int)

Source from the content-addressed store, hash-verified

62
63
64def load_bolt(boltdir: str, num: int) -> Tuple[str, List[Tuple[str, List[int]]]]:
65 """Load a BOLT file, split into sections.
66
67 Returns (boltpath, sections) where sections is a list of
68 (collapsed_text, linemap) pairs; linemap[i] is the original line number
69 for collapsed_text[i].
70 """
71 boltfile = glob.glob("{}/{}-*md".format(boltdir, str(num).zfill(2)))
72 if not boltfile:
73 print("Cannot find bolt {} in {}".format(num, boltdir), file=sys.stderr)
74 sys.exit(1)
75 if len(boltfile) > 1:
76 print("More than one bolt {} in {}? {}".format(num, boltdir, boltfile),
77 file=sys.stderr)
78 sys.exit(1)
79
80 boltpath = boltfile[0]
81 with open(boltpath) as f:
82 raw = list(enumerate(f.readlines(), 1)) # [(lineno, line), ...]
83
84 # Split into sections on lines that start with '#'.
85 raw_sections: List[List[Tuple[int, str]]] = []
86 cur: List[Tuple[int, str]] = []
87 for lineno, line in raw:
88 if line.startswith("#"):
89 raw_sections.append(cur)
90 cur = []
91 cur.append((lineno, line))
92 raw_sections.append(cur)
93
94 sections = [collapse_with_linemap(s) for s in raw_sections]
95 return boltpath, sections
96
97
98def is_requirements_section(text: str) -> bool:

Callers 1

mainFunction · 0.70

Calls 1

collapse_with_linemapFunction · 0.85

Tested by

no test coverage detected