code: def _ensure_license(lines, path):
      # 1. Keep existing
      license_idx = np.where(
          [line.startswith("# License: ") for line in lines]
      )[0]
      assert len(license_idx) <= 1, len(license_idx)
      if len(license_idx):  # If existing, ensure it's correct
          lines[license_idx[0]] = LICENSE_LINE
          return
      # 2. First non-comment line after author line
      author_idx = np.where(
          [re.match(r"^# Authors? ?: .*$", line) for line in lines]
      )[0]
      assert len(author_idx) <= 1, len(author_idx)
      if len(author_idx):
          insert = author_idx[0]
          for extra in range(1, 100):
              if not lines[insert + extra].startswith("#"):
                  break
          else:
              raise RuntimeError(
                  "Failed to find non-comment line within 100 of end of author line"
              )
          lines.insert(insert + extra, LICENSE_LINE)
          return
      # 3. First line after docstring
      insert = 0
      max_len = 100
      if lines[0].startswith('"""'):
          if lines[0].count('"""') != 2:
              for insert in range(1, max_len):
                  if '"""' in lines[insert]:
                      # Find next non-blank line:
                      for extra in range(1, 3):  # up to 2 blank lines
                          if lines[insert + extra].strip():
                              break
                      else:
                          raise RuntimeError(
                              "Failed to find non-blank line within 2 of end of "
                              f"docstring at line {insert + 1}"
                          )
                      insert += extra
                      break
              else:
                  raise RuntimeError(
                      f"Failed to find end of file docstring within {max_len} lines"
                  )
          lines.insert(insert, LICENSE_LINE)
          return
      # 4. First non-comment line
      for insert in range(100):
          if not lines[insert].startswith("#"):
              lines.insert(insert, LICENSE_LINE)
              return
      else:
          raise RuntimeError(
              "Failed to find non-comment line within 100 lines"
          )
  
imports: import re
  from pathlib import Path
  import numpy
  from git import Repo
label_desc: Use image node_id 2 for calling a global function with example usage: _ensure_license(lines, path) without return types