Remove maybe_cleanup util function
It was used in exactly one place, and could be inlined with
minimal loss of clarity
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -35,7 +35,7 @@ from .buildpacks import (
)
from . import contentproviders
from .utils import (
- ByteSpecification, maybe_cleanup, is_valid_docker_image_name,
+ ByteSpecification, is_valid_docker_image_name,
validate_and_generate_port_mapping, chdir
)
@@ -703,9 +703,7 @@ class Repo2Docker(Application):
else:
checkout_path = self.git_workdir
- # keep as much as possible in the context manager to make sure we
- # cleanup if things go wrong
- with maybe_cleanup(checkout_path, self.cleanup_checkout):
+ try:
self.fetch(self.repo, self.ref, checkout_path)
if self.subdir:
@@ -751,6 +749,10 @@ class Repo2Docker(Application):
else:
self.log.info(json.dumps(l),
extra=dict(phase='building'))
+ finally:
+ # Cheanup checkout if necessary
+ if self.cleanup_checkout:
+ shutil.rmtree(checkout_path, ignore_errors=True)
if self.push:
self.push_image()

MODIFY
repo2docker/utils.py
repo2docker/utils.py
@@ -69,14 +69,6 @@ def chdir(path):
os.chdir(old_dir)
-@contextmanager
-def maybe_cleanup(path, cleanup=False):
- """Delete the directory at passed path if cleanup flag is True."""
- yield
- if cleanup:
- shutil.rmtree(path, ignore_errors=True)
-
-
def validate_and_generate_port_mapping(port_mapping):
"""
Validate the port mapping list and return a list of validated tuples.

Remove maybe_cleanup util function

It was used in exactly one place, and could be inlined with
minimal loss of clarity