@@ -9,7 +9,7 @@ import Conda
99
1010isyes (s) = isempty (s) || lowercase (strip (s)) in (" y" , " yes" )
1111
12- function find_jupyter_subcommand (subcommand:: AbstractString )
12+ function find_jupyter_subcommand (subcommand:: AbstractString , port :: Union{Nothing,Int} = nothing )
1313 jupyter = JUPYTER
1414 if jupyter == " jupyter" || jupyter == " jupyter.exe" # look in PATH
1515 jupyter = Sys. which (exe (" jupyter" ))
@@ -26,7 +26,8 @@ function find_jupyter_subcommand(subcommand::AbstractString)
2626 end
2727 end
2828
29- cmd = ` $jupyter $subcommand `
29+ port_flag = ! isnothing (port) ? ` --port=$(port) ` : ` `
30+ cmd = ` $(jupyter) $(subcommand) $(port_flag) `
3031
3132 # fails in Windows if jupyter directory is not in PATH (jupyter/jupyter_core#62)
3233 pathsep = Sys. iswindows () ? ' ;' : ' :'
@@ -69,7 +70,7 @@ function launch(cmd, dir, detached)
6970end
7071
7172"""
72- notebook(; dir=homedir(), detached=false)
73+ notebook(; dir=homedir(), detached=false, port::Union{Nothing,Int}=nothing )
7374
7475The `notebook()` function launches the Jupyter notebook, and is
7576equivalent to running `jupyter notebook` at the operating-system
@@ -90,22 +91,28 @@ the `jupyter notebook` will launch in the background, and will
9091continue running even after you quit Julia. (The only way to
9192stop Jupyter will then be to kill it in your operating system's
9293process manager.)
94+
95+ When the optional keyword `port` is not `nothing`, open the notebook on the
96+ given port number.
97+
98+ For launching a JupyterLab instance, see [`IJulia.jupyterlab()`](@ref).
9399"""
94- function notebook (; dir= homedir (), detached= false )
100+ function notebook (; dir= homedir (), detached= false , port :: Union{Nothing,Int} = nothing )
95101 inited && error (" IJulia is already running" )
96- notebook = find_jupyter_subcommand (" notebook" )
102+ notebook = find_jupyter_subcommand (" notebook" , port)
103+ @show notebook
97104 return launch (notebook, dir, detached)
98105end
99106
100107"""
101- jupyterlab(; dir=homedir(), detached=false)
108+ jupyterlab(; dir=homedir(), detached=false, port::Union{Nothing,Int}=nothing )
102109
103- Similar to `IJulia.notebook()` but launches JupyterLab instead
110+ Similar to [ `IJulia.notebook()`](@ref) but launches JupyterLab instead
104111of the Jupyter notebook.
105112"""
106- function jupyterlab (; dir= homedir (), detached= false )
113+ function jupyterlab (; dir= homedir (), detached= false , port :: Union{Nothing,Int} = nothing )
107114 inited && error (" IJulia is already running" )
108- lab = find_jupyter_subcommand (" lab" )
115+ lab = find_jupyter_subcommand (" lab" , port )
109116 jupyter = first (lab)
110117 if dirname (jupyter) == abspath (Conda. SCRIPTDIR) &&
111118 ! Sys. isexecutable (exe (jupyter, " -lab" )) &&
0 commit comments