MCPcopy Create free account
hub / github.com/apache/tvm / format_script

Function format_script

tests/python/tvmscript/test_tvmscript_printer_underlining.py:46–63  ·  view source on GitHub ↗

Remove leading and trailing blank lines, and make the minimum idention 0

(s: str)

Source from the content-addressed store, hash-verified

44
45
46def format_script(s: str) -> str:
47 """
48 Remove leading and trailing blank lines, and make the minimum idention 0
49 """
50 s = s.strip("\n")
51
52 non_empty_lines = [line for line in s.splitlines() if line and not line.isspace()]
53 if not non_empty_lines:
54 # no actual content
55 return "\n"
56
57 line_indents = [len(line) - len(line.lstrip(" ")) for line in non_empty_lines]
58 spaces_to_remove = min(line_indents)
59
60 cleaned_lines = "\n".join(line[spaces_to_remove:] for line in s.splitlines())
61 if not cleaned_lines.endswith("\n"):
62 cleaned_lines += "\n"
63 return cleaned_lines.strip()
64
65
66def test_underline_basic():

Calls 2

minFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…