MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / extract_triton_code

Function extract_triton_code

export_hf.py:237–262  ·  view source on GitHub ↗

Extract the Triton kernel code from a Python file. Returns everything from the first import statement onward, skipping the module docstring and KERNEL_TYPE/BACKEND declarations.

(source: str)

Source from the content-addressed store, hash-verified

235# ---------------------------------------------------------------------------
236
237def extract_triton_code(source: str) -> str:
238 """
239 Extract the Triton kernel code from a Python file.
240
241 Returns everything from the first import statement onward, skipping
242 the module docstring and KERNEL_TYPE/BACKEND declarations.
243 """
244 lines = source.split("\n")
245
246 # Find the first import line
247 import_idx = None
248 for i, line in enumerate(lines):
249 stripped = line.strip()
250 if stripped.startswith("import ") or stripped.startswith("from "):
251 import_idx = i
252 break
253
254 if import_idx is not None:
255 return "\n".join(lines[import_idx:])
256
257 # Fallback: return everything after KERNEL_TYPE line
258 for i, line in enumerate(lines):
259 if line.strip().startswith("KERNEL_TYPE"):
260 return "\n".join(lines[i + 1 :])
261
262 return source
263
264
265# ---------------------------------------------------------------------------

Callers 1

_export_triton_kernelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected