import importlib


def import_reader(reader):
    """Import the reader backend.

    Import a reader library from the available libraries stored in the
     "readers". This function allows modularity by enabling to switch library
      to import the satellite images. Currently "esa_snap" and "pytroll_satpy"
      are implemented. Please refer to the Readme for more information on how
      to create a reader. Currently the pysat and snappy libraries are not
      compatible, so one or the other have to be installed in the conda
      environement. Snappy should be renamed in the upcoming releases:
      (https://step.esa.int/main/toolboxes/snap/)

    :param reader: Name of the library to try to import
    :type reader: str
    :return: Satellite reader class located in the readers
    :rtype: class
    """
    # Try to import the reader located in the readers folder of the project.
    # Return the reader class in the module.
    try:
        module = importlib.import_module("redress.readers.%s" % reader)
    except ImportError as e:
        raise IOError("Unable to find the reader: %s" % e)

    return module