code: def hexlify(script, minify=False):
      
      if not script:
          return ''
      # Convert line endings in case the file was created on Windows.
      script = script.replace(b'\r\n', b'\n')
      script = script.replace(b'\r', b'\n')
      if minify:
          if not can_minify:
              raise ValueError("No minifier is available")
          script = nudatus.mangle(script.decode('utf-8')).encode('utf-8')
      # Add header, pad to multiple of 16 bytes.
      data = b'MP' + struct.pack('<H', len(script)) + script
      # Padding with null bytes in a 2/3 compatible way
      data = data + (b'\x00' * (16 - len(data) % 16))
      if len(data) > _MAX_SIZE:
          # 'MP' = 2 bytes, script length is another 2 bytes.
          raise ValueError("Python script must be less than 8188 bytes.")
      # Convert to .hex format.
      output = [':020000040003F7']  # extended linear address, 0x0003.
      addr = _SCRIPT_ADDR
      for i in range(0, len(data), 16):
          chunk = data[i:min(i + 16, len(data))]
          chunk = struct.pack('>BHB', len(chunk), addr & 0xffff, 0) + chunk
          checksum = (-(sum(bytearray(chunk)))) & 0xff
          hexline = ':%s%02X' % (strfunc(binascii.hexlify(chunk)).upper(),
                                 checksum)
          output.append(hexline)
          addr += 16
      return '\n'.join(output)
docs: Takes the byte content of a Python script and returns a hex encoded
      version of it.
  
      Based on the hexlify script in the microbit-micropython repository.