def create_tar_file(source_files, target=None):
    """Create a tar file containing all the source_files

    Args:
        source_files (List[str]): List of file paths that will be contained in the tar file

    Returns:
         (str): path to created tar file

    """
    if target:
        filename = target
    else:
        _, filename = tempfile.mkstemp()

    with tarfile.open(filename, mode='w:gz') as t:
        for sf in source_files:
            # Add all files from the directory into the root of the directory structure of the tar
            t.add(sf, arcname=os.path.basename(sf))
    return filename
def create_tar_file ( source_files , target = None ) : if target : filename = target else : _ , filename = tempfile . mkstemp ( ) with tarfile . open ( filename , mode = 'w:gz' ) as t : for sf in source_files : t . add ( sf , arcname = os . path . basename ( sf ) ) return filename
Create a tar file containing all the source_files

    Args:
        source_files (List[str]): List of file paths that will be contained in the tar file

    Returns:
         (str): path to created tar file