"""Make temporary directories nicely."""importatexitimportos.pathimportshutilimporttempfiledefmkdtemp_clean(suffix="",prefix="tmp",dir=None):"""Just like mkdtemp, but the directory will be deleted when the process ends."""the_dir=tempfile.mkdtemp(suffix=suffix,prefix=prefix,dir=dir)atexit.register(cleanup_tempdir,the_dir)returnthe_dirdefcleanup_tempdir(the_dir):"""Called on process exit to remove a temp directory."""ifos.path.exists(the_dir):shutil.rmtree(the_dir)