16
16
17
17
18
18
def build_binder (repo ,
19
- ref = 'master' ,
20
- filepath = None ,
19
+ ref ,
21
20
* ,
22
21
binder_url = 'https://mybinder.org' ):
23
22
"""Launch a binder
@@ -38,9 +37,12 @@ def build_binder(repo,
38
37
parser = argparse .ArgumentParser (description = __doc__ )
39
38
parser .add_argument ('repo' , type = str , help = "The GitHub repo to build" )
40
39
parser .add_argument (
41
- '--ref' , default = 'master' , help = "The ref of the repo to build" )
42
- parser .add_argument (
40
+ '--ref' , default = 'HEAD' , help = "The ref of the repo to build" )
41
+ file_or_url = parser .add_mutually_exclusive_group ()
42
+ file_or_url .add_argument (
43
43
'--filepath' , type = str , help = "The file to open, if any." )
44
+ file_or_url .add_argument (
45
+ '--urlpath' , type = str , help = "The url to open, if any." )
44
46
parser .add_argument (
45
47
'--binder' ,
46
48
default = 'https://mybinder.org' ,
@@ -53,15 +55,19 @@ def build_binder(repo,
53
55
for evt in build_binder (
54
56
opts .repo ,
55
57
ref = opts .ref ,
56
- filepath = opts .filepath ,
57
58
binder_url = opts .binder ):
58
59
if 'message' in evt :
59
60
print ("[{phase}] {message}" .format (
60
61
phase = evt .get ('phase' , '' ),
61
62
message = evt ['message' ].rstrip (),
62
63
))
63
64
if evt .get ('phase' ) == 'ready' :
64
- url = "{url}?token={token}" .format (** evt )
65
+ if opts .filepath :
66
+ url = "{url}notebooks/{filepath}?token={token}" .format (** evt , filepath = opts .filepath )
67
+ elif opts .urlpath :
68
+ url = "{url}{urlpath}?token={token}" .format (** evt , urlpath = opts .urlpath )
69
+ else :
70
+ url = "{url}?token={token}" .format (** evt )
65
71
print ("Opening %s" % url )
66
72
webbrowser .open (url )
67
73
break
0 commit comments