MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / load_command_blocks_from_readme

Function load_command_blocks_from_readme

tools/Polygraphy/tests/test_examples.py:123–143  ·  view source on GitHub ↗
(readme)

Source from the content-addressed store, hash-verified

121# Extract any ``` blocks from the README
122# NOTE: This parsing logic is not smart enough to handle multiple separate commands in a single block.
123def load_command_blocks_from_readme(readme) -> List[CommandBlock]:
124 with open(readme, "r") as f:
125 contents = f.read()
126 # Check that the README has all the expected sections.
127 assert "## Introduction" in contents, "All example READMEs should have an 'Introduction' section!"
128 assert "## Running The Example" in contents, "All example READMEs should have a 'Running The Example' section!"
129
130 cmd_blocks = []
131 with MarkerTracker(readme) as tracker:
132 for line in tracker:
133 if tracker.is_in(VALID_MARKERS["ignore"]):
134 continue
135
136 if tracker.entering(VALID_MARKERS["command"]):
137 current_block = CommandBlock(xfail=tracker.is_in(VALID_MARKERS["xfail"]))
138 elif tracker.exiting(VALID_MARKERS["command"]):
139 cmd_blocks.append(copy.copy(current_block))
140 elif tracker.is_in(VALID_MARKERS["command"]):
141 current_block.add(line)
142
143 return cmd_blocks
144
145
146class Example:

Callers 1

__enter__Method · 0.85

Calls 9

addMethod · 0.95
MarkerTrackerClass · 0.85
CommandBlockClass · 0.85
readMethod · 0.80
is_inMethod · 0.80
enteringMethod · 0.80
exitingMethod · 0.80
appendMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected