Skip to content

Commit 5a0da89

Browse files
committed
Delay TempDirectory.delete resolution to cleanup
1 parent fed360a commit 5a0da89

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/pip/_internal/utils/temp_dir.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ def __init__(
107107
):
108108
super(TempDirectory, self).__init__()
109109

110-
if path is None and delete is None:
111-
# If we were not given an explicit directory, and we were not given
112-
# an explicit delete option, then we'll default to deleting unless
113-
# the tempdir_registry says otherwise.
110+
# If we were given an explicit directory, resolve delete option now.
111+
# Otherwise we wait until cleanup and see what tempdir_registry says.
112+
if path is not None and delete is None:
114113
delete = True
115-
if _tempdir_registry:
116-
delete = _tempdir_registry.get_delete(kind)
117114

118115
if path is None:
119116
path = self._create(kind)
@@ -145,7 +142,14 @@ def __enter__(self):
145142

146143
def __exit__(self, exc, value, tb):
147144
# type: (Any, Any, Any) -> None
148-
if self.delete:
145+
if self.delete is not None:
146+
delete = self.delete
147+
elif _tempdir_registry:
148+
delete = _tempdir_registry.get_delete(self.kind)
149+
else:
150+
delete = True
151+
152+
if delete:
149153
self.cleanup()
150154

151155
def _create(self, kind):

0 commit comments

Comments
 (0)