1616
1717
1818def build_binder (repo ,
19- ref = 'master' ,
20- filepath = None ,
19+ ref ,
2120 * ,
2221 binder_url = 'https://mybinder.org' ):
2322 """Launch a binder
@@ -38,9 +37,12 @@ def build_binder(repo,
3837 parser = argparse .ArgumentParser (description = __doc__ )
3938 parser .add_argument ('repo' , type = str , help = "The GitHub repo to build" )
4039 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 (
4343 '--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." )
4446 parser .add_argument (
4547 '--binder' ,
4648 default = 'https://mybinder.org' ,
@@ -53,15 +55,19 @@ def build_binder(repo,
5355 for evt in build_binder (
5456 opts .repo ,
5557 ref = opts .ref ,
56- filepath = opts .filepath ,
5758 binder_url = opts .binder ):
5859 if 'message' in evt :
5960 print ("[{phase}] {message}" .format (
6061 phase = evt .get ('phase' , '' ),
6162 message = evt ['message' ].rstrip (),
6263 ))
6364 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 )
6571 print ("Opening %s" % url )
6672 webbrowser .open (url )
6773 break
0 commit comments