20
20
import entrypoints
21
21
import escapism
22
22
from pythonjsonlogger import jsonlogger
23
- from traitlets import Any , Bool , Dict , Int , List , Unicode , default
23
+ from traitlets import Any , Bool , Dict , Int , List , Unicode , default , observe
24
24
from traitlets .config import Application
25
25
26
26
from . import __version__ , contentproviders
@@ -304,7 +304,7 @@ def _user_name_default(self):
304
304
)
305
305
306
306
cleanup_checkout = Bool (
307
- False ,
307
+ True ,
308
308
help = """
309
309
Delete source repository after building is done.
310
310
@@ -313,6 +313,12 @@ def _user_name_default(self):
313
313
config = True ,
314
314
)
315
315
316
+ @default ("cleanup_checkout" )
317
+ def _defaut_cleanup_checkout (self ):
318
+ # if the source exists locally we don't want to delete it at the end
319
+ # FIXME: Find a better way to figure out if repo is 'local'. Push this into ContentProvider?
320
+ return not os .path .exists (self .repo )
321
+
316
322
output_image_spec = Unicode (
317
323
"" ,
318
324
help = """
@@ -349,6 +355,12 @@ def _user_name_default(self):
349
355
config = True ,
350
356
)
351
357
358
+ @observe ("dry_run" )
359
+ def _dry_run_changed (self , change ):
360
+ if change .new :
361
+ # dry_run forces run and push to be False
362
+ self .push = self .run = False
363
+
352
364
# FIXME: Refactor classes to separate build & run steps
353
365
run_cmd = List (
354
366
[],
@@ -727,6 +739,8 @@ def build(self):
727
739
# making a copy of it as it might contain large files that would be
728
740
# expensive to copy.
729
741
if os .path .isdir (self .repo ):
742
+ # never cleanup when we are working in a local repo
743
+ self .cleanup_checkout = False
730
744
checkout_path = self .repo
731
745
else :
732
746
if self .git_workdir is None :
@@ -828,6 +842,7 @@ def build(self):
828
842
829
843
finally :
830
844
# Cleanup checkout if necessary
845
+ # never cleanup when checking out a local repo
831
846
if self .cleanup_checkout :
832
847
shutil .rmtree (checkout_path , ignore_errors = True )
833
848
0 commit comments