def get_writer(file_format, writers, writer_base_class):
    """Returns a writer class for the given file format. This function mainly
    exists to catch ImportErrors, if a writer requires a missing library, and
    trying to find a writer, for which all dependencies are available.

    :param file_format: the file format flag from the enumeration, that lists
                        all available formats for the given data set class.
    :param writers: a dictionary, that maps file format flags to already existing
                    writer instances. If this function instantiates a new writer,
                    it will be added to that dictionary.
    :param writer_base_class: the base class for all writers. This function may
                              iterate over all sub-classes of this class, when
                              trying to create a suitable writer.
    :returns: a writer object, that can be called with the data set and the
              file path, in which the data set shall be saved.
    """
    if file_format in writers:
        return writers[file_format]
    else:
        for cls in writer_base_class.__subclasses__():
            if file_format in cls.formats:
                try:
                    writer = cls(file_format)
                except ImportError:
                    continue
                else:
                    writers[file_format] = writer
                    return writer
        raise ValueError(f'file format cannot be written: {file_format}')
