def METHOD_NAME(
    files: List[str], archive_name: str, rel_to: str, compression: Optional[str] = "gz"
) -> str:
    """Writes the given set of files into a tar archive (using compression, if desired)"""
    top_level_dir: str = os.path.basename(archive_name)
    archive_name += ".tar"
    if compression:
        archive_name += "." + compression
    with tarfile.open(
        archive_name, mode="x:" + (compression if compression else "")
    ) as archive:
        for current_file in files:
            archive.add(
                current_file,
                arcname=os.path.join(
                    top_level_dir, os.path.relpath(current_file, rel_to)
                ),
                recursive=False,
            )
    return archive_name