MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / extract_code_blocks

Function extract_code_blocks

tools/check_code_block_format.py:153–178  ·  view source on GitHub ↗
(
    file: io.TextIOWrapper,
)

Source from the content-addressed store, hash-verified

151
152
153def extract_code_blocks(
154 file: io.TextIOWrapper,
155) -> Iterator[CodeBlock]:
156 lines_iter = iter(enumerate(file))
157
158 while True:
159 next_item = next(lines_iter, None)
160 if next_item is None:
161 break
162 lineno, line = next_item
163 match = REGEX_CODE_BLOCK.match(line)
164 if match:
165 indent = match.group('indent')
166 indent_size = len(indent)
167 code_block_start_lineno = lineno + 1
168 code_block_lines = [line]
169 indent_regex = re.compile(rf"\s{{{indent_size + 1}}}")
170 while True:
171 next_item = next(lines_iter, None)
172 if next_item is None:
173 break
174 lineno, line = next_item
175 if not indent_regex.match(line) and not is_blank_line(line):
176 break
177 code_block_lines.append(line)
178 yield CodeBlock(code_block_lines, code_block_start_lineno)
179
180
181def check_code_block_indentation(

Callers 1

check_code_block_formatFunction · 0.85

Calls 6

iterFunction · 0.85
is_blank_lineFunction · 0.85
CodeBlockClass · 0.85
groupMethod · 0.45
compileMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected