Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgianaElena committed Apr 7, 2023
1 parent 4982efc commit 0abd3ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions examples/binder-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
import requests


def build_binder(repo, ref, *, binder_url="https://mybinder.org", no_launch):
def build_binder(repo, ref, *, binder_url="https://mybinder.org", build_only):
"""Launch a binder
Yields Binder's event-stream events (dicts)
"""
print(f"Building binder for {repo}@{ref}")
url = binder_url + f"/build/gh/{repo}/{ref}"
params = {}
if no_launch:
params = {"no-launch": "True"}
if build_only:
params = {"build_only": "true"}

r = requests.get(url, stream=True, params=params)
r.raise_for_status()
Expand All @@ -39,7 +39,7 @@ def build_binder(repo, ref, *, binder_url="https://mybinder.org", no_launch):
parser.add_argument("repo", type=str, help="The GitHub repo to build")
parser.add_argument("--ref", default="HEAD", help="The ref of the repo to build")
parser.add_argument(
"--no-launch",
"--build-only",
action="store_true",
help="When passed, the image will not be launched after build",
)
Expand All @@ -57,7 +57,7 @@ def build_binder(repo, ref, *, binder_url="https://mybinder.org", no_launch):
opts = parser.parse_args()

for evt in build_binder(
opts.repo, ref=opts.ref, binder_url=opts.binder, no_launch=opts.no_launch
opts.repo, ref=opts.ref, binder_url=opts.binder, build_only=opts.build_only
):
if "message" in evt:
print(
Expand All @@ -67,7 +67,9 @@ def build_binder(repo, ref, *, binder_url="https://mybinder.org", no_launch):
)
)
if evt.get("phase") == "ready":
if opts.filepath:
if opts.build_only:
break
elif opts.filepath:
url = "{url}notebooks/{filepath}?token={token}".format(
**evt, filepath=opts.filepath
)
Expand Down
2 changes: 1 addition & 1 deletion testing/local-binder-mocked-hub/binderhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
c.BinderHub.repo_providers = {"gh": FakeProvider}
c.BinderHub.build_class = FakeBuild
# Uncomment the following line to enable BinderHub to not launch the image after build
# c.BinderHub.no_launch = True
# c.BinderHub.require_build_only = True

c.BinderHub.about_message = "<blink>Hello world.</blink>"
c.BinderHub.banner_message = 'This is headline <a href="#">news.</a>'

0 comments on commit 0abd3ba

Please sign in to comment.