Clean up temporary directory at exit
from __future__ import absolute_import
+import atexit
import logging
import os
import shutil
@@ -552,15 +553,23 @@ class InstallRequirement(object):
)
self.req = Requirement(metadata_name)
+ def cleanup(self):
+ # type: () -> None
+ if self._temp_dir is not None:
+ self._temp_dir.cleanup()
+
def prepare_pep517_metadata(self):
# type: () -> None
assert self.pep517_backend is not None
- with TempDirectory(delete=False) as temp_dir:
+ self._temp_dir = TempDirectory(delete=False, kind="req-install")
+ self._temp_dir.create()
metadata_dir = os.path.join(
- temp_dir.path,
+ self._temp_dir.path,
'pip-wheel-metadata',
)
+ atexit.register(self.cleanup)
+
ensure_dir(metadata_dir)
with self.build_env:
