parameters: (exe_name: str)
return_statement: return candidate_exe
docstring: Finds a tool by its (extension-less) executable name.
  
    Args:
      exe_name: The name of the executable (extension-less).
    Returns:
      An absolute path to the tool.
    Raises:
      ValueError: If the tool is not known or not found.
docstring_summary: Finds a tool by its (extension-less) executable name.
docstring_tokens: Finds a tool by its ( extension - less ) executable name .
function: def find_tool(exe_name: str) -> str:
    """Finds a tool by its (extension-less) executable name.
  
    Args:
      exe_name: The name of the executable (extension-less).
    Returns:
      An absolute path to the tool.
    Raises:
      ValueError: If the tool is not known or not found.
    """
    is_builtin = exe_name in _BUILTIN_TOOLS
    if not is_builtin and exe_name not in _TOOL_MODULE_MAP:
      raise ValueError(f"IREE compiler tool '{exe_name}' is not a known tool")
  
    # First search an explicit tool path (from environment).
    tool_path = get_tool_path()
    for path_entry in tool_path:
      if not path_entry:
        continue
      candidate_exe = os.path.join(path_entry, exe_name)
      if _is_executable(candidate_exe):
        return candidate_exe
  
    if is_builtin:
      # Get builtin tool.
      candidate_exe = _get_builtin_tool(exe_name)
      if _is_executable(candidate_exe):
        return candidate_exe
  
    # Fall-through and attempt to find it via a tools module.
    # Attempt to load the tool module.
    tool_module_name = _TOOL_MODULE_MAP[exe_name]
    tool_module_package = _TOOL_MODULE_PACKAGES[tool_module_name]
    try:
      tool_module = importlib.import_module(tool_module_name)
    except ModuleNotFoundError:
      raise ValueError(
          f"IREE compiler tool '{exe_name}' is not installed (it should have been "
          f"found in the python module '{tool_module_name}', typically installed "
          f"via the package {tool_module_package}).\n\n"
          f"Either install the package or set the {_TOOL_PATH_ENVVAR} environment "
          f"variable to contain the path of the tool executable "
          f"(current {_TOOL_PATH_ENVVAR} = {repr(tool_path)}).") from None
  
    # Ask the module for its tool.
    candidate_exe = tool_module.get_tool(exe_name)
  
    if (not _is_executable(candidate_exe)):
      raise ValueError(
          f"IREE compiler tool '{exe_name}' was located in module "
          f"'{tool_module_name}' but the file was not found or not executable: "
          f"{candidate_exe}")
    return candidate_exe
function_tokens: def find_tool ( exe_name : str ) -> str : is_builtin = exe_name in _BUILTIN_TOOLS if not is_builtin and exe_name not in _TOOL_MODULE_MAP : raise ValueError ( f"IREE compiler tool '{exe_name}' is not a known tool" ) # First search an explicit tool path (from environment). tool_path = get_tool_path ( ) for path_entry in tool_path : if not path_entry : continue candidate_exe = os . path . join ( path_entry , exe_name ) if _is_executable ( candidate_exe ) : return candidate_exe if is_builtin : # Get builtin tool. candidate_exe = _get_builtin_tool ( exe_name ) if _is_executable ( candidate_exe ) : return candidate_exe # Fall-through and attempt to find it via a tools module. # Attempt to load the tool module. tool_module_name = _TOOL_MODULE_MAP [ exe_name ] tool_module_package = _TOOL_MODULE_PACKAGES [ tool_module_name ] try : tool_module = importlib . import_module ( tool_module_name ) except ModuleNotFoundError : raise ValueError ( f"IREE compiler tool '{exe_name}' is not installed (it should have been " f"found in the python module '{tool_module_name}', typically installed " f"via the package {tool_module_package}).\n\n" f"Either install the package or set the {_TOOL_PATH_ENVVAR} environment " f"variable to contain the path of the tool executable " f"(current {_TOOL_PATH_ENVVAR} = {repr(tool_path)})." ) from None # Ask the module for its tool. candidate_exe = tool_module . get_tool ( exe_name ) if ( not _is_executable ( candidate_exe ) ) : raise ValueError ( f"IREE compiler tool '{exe_name}' was located in module " f"'{tool_module_name}' but the file was not found or not executable: " f"{candidate_exe}" ) return candidate_exe