MCPcopy
hub / github.com/deepspeedai/DeepSpeed / get_header_py

Function get_header_py

scripts/replace_copyright.py:65–99  ·  view source on GitHub ↗
(fp)

Source from the content-addressed store, hash-verified

63
64# These get_header_* functions are ugly, but they work :)
65def get_header_py(fp):
66 with open(fp, "r") as f:
67 lines = iter(l for l in f.readlines())
68
69 header = []
70 rest = []
71 in_multiline = False
72 multiline_type = None
73
74 while (l := next(lines, None)) is not None:
75 l = l.strip()
76 if l.startswith(PY_ML_SINGLE) or l.startswith(PY_ML_DOUBLE):
77 # Detected multiline comment
78 if in_multiline and multiline_type == l[:3]:
79 # Ended a multiline comment
80 in_multiline = False
81 else:
82 # Started a multiline comment
83 in_multiline = True
84 multiline_type = l[:3]
85 if l.endswith(multiline_type) and len(l) >= 6:
86 # Opened and closed multiline comment on single line
87 in_multiline = False
88 elif in_multiline and l.endswith(multiline_type):
89 # Ended a multiline comment
90 in_multiline = False
91 elif not (in_multiline or l.startswith(PY_SL_COMMENT) or l == ""):
92 # Not in a comment
93 rest += [l + "\n"]
94 break
95 header.append(l)
96
97 rest += list(lines)
98
99 return header, rest
100
101
102def get_header_c(fp):

Callers 1

mainFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…