diff --git a/repo2docker/app.py b/repo2docker/app.py index fbddf8c8..ad0effe3 100644 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -19,7 +19,7 @@ import escapism from traitlets.config import Application, LoggingConfigurable -from traitlets import Type, Bool, Unicode, Dict, List, default +from traitlets import Type, Bool, Unicode, Dict, List, default, Tuple import docker from docker.utils import kwargs_from_env @@ -81,6 +81,15 @@ class Repo2Docker(Application): """ ) + default_buildpack = Tuple( + (BaseImage, PythonBuildPack), + config=True, + help=""" + The build pack to use when no buildpacks are found + """ + ) + + cleanup_checkout = Bool( True, config=True, @@ -299,21 +308,23 @@ class Repo2Docker(Application): ) os.chdir(checkout_path) + picked_buildpack = c(self.default_buildpack) + for bp_spec in self.buildpacks: bp = c(bp_spec) if bp.detect(): - self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building')) - for l in bp.build(self.output_image_spec): - if 'stream' in l: - self.log.info(l['stream'], extra=dict(phase='building')) - elif 'error' in l: - self.log.info(l['error'], extra=dict(phase='failure')) - sys.exit(1) - else: - self.log.info(json.dumps(l), extra=dict(phase='building')) + picked_buildpack = bp break - else: - raise Exception("No builder found!") + + self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building')) + for l in picked_buildpack.build(self.output_image_spec): + if 'stream' in l: + self.log.info(l['stream'], extra=dict(phase='building')) + elif 'error' in l: + self.log.info(l['error'], extra=dict(phase='failure')) + sys.exit(1) + else: + self.log.info(json.dumps(l), extra=dict(phase='building')) if self.repo_type != 'local' and self.cleanup_checkout: shutil.rmtree(checkout_path) diff --git a/repo2docker/detectors.py b/repo2docker/detectors.py index 7530a910..29ed5394 100644 --- a/repo2docker/detectors.py +++ b/repo2docker/detectors.py @@ -537,7 +537,7 @@ class PythonBuildPack(BuildPack): return [] def detect(self): - return os.path.exists('requirements.txt') and super() + return os.path.exists('requirements.txt') and super().detect() class CondaBuildPack(BuildPack): name = "conda" diff --git a/tests/default/verify b/tests/default/verify new file mode 100755 index 00000000..73190acb --- /dev/null +++ b/tests/default/verify @@ -0,0 +1,6 @@ +#!/usr/bin/env python +# Verify that the default just provides a py3 environment with jupyter +import sys + +assert sys.version_info[:2] == (3, 5) +import jupyter