code: def cleanup():
      """
      Delete keys in old format from the compiledir.
  
      Old clean up include key in old format or with old version of the c_code:
      1) keys that have an ndarray in them.
         Now we use a hash in the keys of the constant data.
      2) key that don't have the numpy ABI version in them
      3) They do not have a compile version string
  
      If there is no key left for a compiled module, we delete the module.
  
      """
      compiledir = config.compiledir
      for directory in os.listdir(compiledir):
          try:
              filename = os.path.join(compiledir, directory, "key.pkl")
              # print file
              with open(filename, "rb") as file:
                  try:
                      keydata = pickle.load(file)
  
                      for key in list(keydata.keys):
                          have_npy_abi_version = False
                          have_c_compiler = False
                          for obj in flatten(key):
                              if isinstance(obj, np.ndarray):
                                  # Reuse have_npy_abi_version to
                                  # force the removing of key
                                  have_npy_abi_version = False
                                  break
                              elif isinstance(obj, str):
                                  if obj.startswith(
                                      "NPY_ABI_VERSION=0x"
                                  ):
                                      have_npy_abi_version = True
                                  elif obj.startswith(
                                      "c_compiler_str="
                                  ):
                                      have_c_compiler = True
                              elif isinstance(
                                  obj, (Op, CType)
                              ) and hasattr(
                                  obj, "c_code_cache_version"
                              ):
                                  v = obj.c_code_cache_version()
                                  if (
                                      v not in [(), None]
                                      and v not in key[0]
                                  ):
                                      # Reuse have_npy_abi_version to
                                      # force the removing of key
                                      have_npy_abi_version = False
                                      break
  
                          if (
                              not have_npy_abi_version
                              or not have_c_compiler
                          ):
                              try:
                                  # This can happen when we move the compiledir.
                                  if keydata.key_pkl != filename:
                                      keydata.key_pkl = filename
                                  keydata.remove_key(key)
                              except OSError:
                                  _logger.error(
                                      f"Could not remove file '{filename}'. To complete "
                                      "the clean-up, please remove manually "
                                      "the directory containing it."
                                  )
                      if len(keydata.keys) == 0:
                          shutil.rmtree(
                              os.path.join(compiledir, directory)
                          )
  
                  except (EOFError, AttributeError):
                      _logger.error(
                          f"Could not read key file '{filename}'. To complete "
                          "the clean-up, please remove manually "
                          "the directory containing it."
                      )
          except OSError:
              _logger.error(
                  f"Could not clean up this directory: '{directory}'. To complete "
                  "the clean-up, please remove it manually."
              )
  
file_path: pytensor/pytensor/compile/compiledir.py
imports: import logging
  import os
  import pickle
  import shutil
  import numpy
  from pytensor.configdefaults import config
  from pytensor.graph.op import Op
  from pytensor.link.c.type import CType
  from pytensor.utils import flatten
label_desc: Use image node_id 1 for calling a global function with example usage: cleanup() without return types