code: def cleanup_endpoint_files(
      name,
      query_path,
      logger=logging.getLogger(__name__),
      retain_versions=None,
  ):
      """
      Cleanup the disk space a certain endpiont uses.
  
      Parameters
      ----------
      name : str
          The endpoint name
  
      retain_version : int, optional
          If given, then all files for this endpoint are removed except the
          folder for the given version, otherwise, all files for that endpoint
          are removed.
      """
      _check_endpoint_name(name, logger=logger)
      local_dir = os.path.join(query_path, name)
  
      # nothing to clean, this is true for state file path where we load
      # Query Object directly from the state path instead of downloading
      # to temporary location
      if not os.path.exists(local_dir):
          return
  
      if not retain_versions:
          shutil.rmtree(local_dir)
      else:
          retain_folders = [
              os.path.join(local_dir, str(version))
              for version in retain_versions
          ]
          logger.log(logging.INFO, f"Retain folders: {retain_folders}")
  
          for file_or_dir in os.listdir(local_dir):
              candidate_dir = os.path.join(local_dir, file_or_dir)
              if os.path.isdir(candidate_dir) and (
                  candidate_dir not in retain_folders
              ):
                  shutil.rmtree(candidate_dir)
  
imports: import logging
  import os
  import shutil
  from re import compile
label_desc: Use image node_id 3 for calling a global function with example usage: cleanup_endpoint_files(name, query_path, logger, retain_versions) without return types