MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / insert_header

Function insert_header

scripts/update_license_headers.py:244–259  ·  view source on GitHub ↗

Insert the SPDX header into file content, returning the new content.

(content: str, comment: str, path: Path)

Source from the content-addressed store, hash-verified

242
243
244def insert_header(content: str, comment: str, path: Path) -> str:
245 """Insert the SPDX header into file content, returning the new content."""
246 header = make_header(comment)
247 lines = content.splitlines(keepends=True)
248 insert_at = find_insertion_point(lines, path)
249
250 if insert_at == 0:
251 # Header at top, blank line before existing content (if any).
252 if lines:
253 return header + "\n" + content
254 return header
255 else:
256 # Insert after a first-line directive (shebang / # syntax=).
257 before = lines[:insert_at]
258 after = lines[insert_at:]
259 return "".join(before) + "\n" + header + "\n" + "".join(after)
260
261
262# ---------------------------------------------------------------------------

Callers 1

process_fileFunction · 0.85

Calls 2

make_headerFunction · 0.85
find_insertion_pointFunction · 0.85

Tested by

no test coverage detected