def copy_to_tmp(source):
    """
    Copies ``source`` to a temporary directory, and returns the copied
    location.

    If source is a file, the copied location is also a file.
    """
    tmp_dir = tempfile.mkdtemp()
    # Use pathlib because os.path.basename is different depending on whether
    # the path ends in a /
    p = pathlib.Path(source)
    dirname = p.name or 'temp'
    new_dir = os.path.join(tmp_dir, dirname)
    if os.path.isdir(source):
        shutil.copytree(source, new_dir)
    else:
        shutil.copy2(source, new_dir)
    return new_dir
def copy_to_tmp ( source ) : tmp_dir = tempfile . mkdtemp ( ) p = pathlib . Path ( source ) dirname = p . name or 'temp' new_dir = os . path . join ( tmp_dir , dirname ) if os . path . isdir ( source ) : shutil . copytree ( source , new_dir ) else : shutil . copy2 ( source , new_dir ) return new_dir
Copies ``source`` to a temporary directory, and returns the copied
    location.

    If source is a file, the copied location is also a file.