Use "local" label for local directory
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -745,8 +745,10 @@ class Repo2Docker(Application):
picked_buildpack = self.default_buildpack()
picked_buildpack.appendix = self.appendix
+ # Add metadata labels
picked_buildpack.labels['repo2docker.version'] = self.version
- picked_buildpack.labels['repo2docker.repo'] = self.repo
+ repo_label = 'local' if os.path.isdir(self.repo) else self.repo
+ picked_buildpack.labels['repo2docker.repo'] = repo_label
picked_buildpack.labels['repo2docker.ref'] = self.ref
self.log.debug(picked_buildpack.render(),

MODIFY
tests/test_labels.py
tests/test_labels.py
"""
Test if labels are supplied correctly to the container
"""
-import time
-from unittest.mock import Mock
from repo2docker.app import Repo2Docker
from repo2docker.buildpacks import BuildPack
from repo2docker import __version__
import pytest
+from unittest.mock import Mock
+
+
+URL = "https://github.com/binderhub-ci-repos/repo2docker-ci-clone-depth"
def test_buildpack_labels_rendered():
@@ -18,8 +20,13 @@ def test_buildpack_labels_rendered():
assert 'LABEL second_label="anotherlabel"\n' in bp.render()
-@pytest.mark.parametrize('ref', ['some-branch', None])
-def test_labels(ref, tmpdir):
+@pytest.mark.parametrize('ref, repo, expected_repo_label', [
+ (None, URL, URL),
+ ('some-ref', None, 'local'),
+ (None, None, 'local'),
+])
+def test_Repo2Docker_labels(ref, repo, expected_repo_label, tmpdir):
+ if repo is None:
repo = str(tmpdir)
if ref is not None:
argv = ['--ref', ref, repo]
@@ -38,7 +45,7 @@ def test_labels(ref, tmpdir):
app.start()
expected_labels = {
'repo2docker.ref': ref,
- 'repo2docker.repo': repo,
+ 'repo2docker.repo': expected_repo_label,
'repo2docker.version': __version__,
}

Use "local" label for local directory