import logging


def MpiVars(vm) -> str:
  """Returns the path to the mpivars.sh file.

  With different versions of Intel software installed the mpivars.sh for
  2019.6 can be under compilers_and_libraries_2020.0.166 while the symlink
  for compilers_and_libraries points to compilers_and_libraries_2018

  Args:
    vm: Virtual machine to look for mpivars.sh on.
  """
  txt, _ = vm.RemoteCommand('readlink -f /opt/intel/compilers_and_libraries*/'
                            'linux/mpi/intel64/bin/mpivars.sh | sort | uniq')
  files = txt.splitlines()
  if not files:
    raise ValueError('Could not find the mpivars.sh file')
  if len(files) > 1:
    logging.info('More than 1 mpivars.sh found, returning first: %s', files)
  return files[0]