Skip to content

Commit 193b758

Browse files
committed
attempt to clean up after an exception. Fix #413.
1 parent 9bdf120 commit 193b758

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pip/basecommand.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def main(self, args, initial_options):
138138
logger.fatal('Exception:\n%s' % format_exc())
139139
store_log = True
140140
exit = UNKNOWN_ERROR
141+
finally:
142+
# try to clean eventual files that got caught up
143+
if not self.done_cleaning:
144+
try:
145+
self.req_set.cleanup_files(bundle=self.bundle)
146+
except:
147+
pass # go unnoticed if there is nothing to clean
148+
141149
if log_fp is not None:
142150
log_fp.close()
143151
if store_log:

pip/commands/install.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def _build_package_finder(self, options, index_urls):
184184

185185
def run(self, options, args):
186186
fix_git_urls(args)
187+
self.done_cleaning = False
187188
if options.download_dir:
188189
options.no_install = True
189190
options.ignore_installed = True
@@ -229,6 +230,8 @@ def run(self, options, args):
229230
for filename in options.requirements:
230231
for req in parse_requirements(filename, finder=finder, options=options):
231232
requirement_set.add_requirement(req)
233+
# save the requirement set for cleaning in case of error
234+
self.req_set = requirement_set
232235
if not requirement_set.has_requirements and not options.requirements:
233236
opts = {'name': self.name}
234237
if options.find_links:
@@ -274,6 +277,7 @@ def run(self, options, args):
274277
# Clean up
275278
if not options.no_install or options.download_dir:
276279
requirement_set.cleanup_files(bundle=self.bundle)
280+
self.done_cleaning = True
277281
if options.target_dir:
278282
if not os.path.exists(options.target_dir):
279283
os.makedirs(options.target_dir)

0 commit comments

Comments
 (0)