Skip to content

Commit d5f291b

Browse files
committed
move cleanup_checkout / local repo, dry_run/push/run relationships to app
so app behaves more consistently when run without cli
1 parent 2a9dab1 commit d5f291b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

repo2docker/__main__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,6 @@ def make_r2d(argv=None):
447447
# extend any environment config from a config file
448448
r2d.environment.extend(args.environment)
449449

450-
# if the source exists locally we don't want to delete it at the end
451-
# FIXME: Find a better way to figure out if repo is 'local'. Push this into ContentProvider?
452-
if os.path.exists(args.repo):
453-
r2d.cleanup_checkout = False
454450
elif args.clean is not None:
455451
r2d.cleanup_checkout = args.clean
456452

repo2docker/app.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import entrypoints
2121
import escapism
2222
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
2424
from traitlets.config import Application
2525

2626
from . import __version__, contentproviders
@@ -304,7 +304,7 @@ def _user_name_default(self):
304304
)
305305

306306
cleanup_checkout = Bool(
307-
False,
307+
True,
308308
help="""
309309
Delete source repository after building is done.
310310
@@ -313,6 +313,12 @@ def _user_name_default(self):
313313
config=True,
314314
)
315315

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+
316322
output_image_spec = Unicode(
317323
"",
318324
help="""
@@ -349,6 +355,12 @@ def _user_name_default(self):
349355
config=True,
350356
)
351357

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+
352364
# FIXME: Refactor classes to separate build & run steps
353365
run_cmd = List(
354366
[],
@@ -727,6 +739,8 @@ def build(self):
727739
# making a copy of it as it might contain large files that would be
728740
# expensive to copy.
729741
if os.path.isdir(self.repo):
742+
# never cleanup when we are working in a local repo
743+
self.cleanup_checkout = False
730744
checkout_path = self.repo
731745
else:
732746
if self.git_workdir is None:
@@ -828,6 +842,7 @@ def build(self):
828842

829843
finally:
830844
# Cleanup checkout if necessary
845+
# never cleanup when checking out a local repo
831846
if self.cleanup_checkout:
832847
shutil.rmtree(checkout_path, ignore_errors=True)
833848

0 commit comments

Comments
 (0)