Skip to content

Commit f0c5341

Browse files
KristofferCKristofferC
authored andcommitted
updates based on review
1 parent 54861c4 commit f0c5341

File tree

4 files changed

+44
-65
lines changed

4 files changed

+44
-65
lines changed

docs/src/manual/running.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
## Command-Line Launcher
55

6-
Starting with Julia 1.12, you can launch IJulia directly from the command line using the `ijulia` command. First, you need to install the app entry point by running in the Julia REPL:
6+
Starting with Julia 1.12, you can launch IJulia directly from the command line using the `ijulia` command. First, you need to install the app entry point (see [Julia app documentation](https://pkgdocs.julialang.org/v1/apps/)) by running in the Julia REPL:
77

88
```julia
99
pkg> app add IJulia
1010
```
1111

12+
You may need to add `~/.julia/bin` to your PATH if it's not already there.
13+
1214
Then you can use the `ijulia` command from your terminal:
1315

1416
```bash

src/IJulia.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,8 @@ include("precompile.jl")
587587
#######################################################################
588588
# App entry point for `ijulia` command
589589

590-
# Mutable function references for testing - allows tests to mock these functions
591-
notebook_cmd::Function = notebook
592-
jupyterlab_cmd::Function = jupyterlab
593-
594-
function (@main)(ARGS)
590+
@static if VERSION >= v"1.11"
591+
function (@main)(ARGS; notebook_cmd::Function = notebook, jupyterlab_cmd::Function = jupyterlab)
595592
# Show help if help flag
596593
if !isempty(ARGS) && ARGS[1] in ("--help", "-h", "help")
597594
println("""
@@ -621,8 +618,8 @@ function (@main)(ARGS)
621618
return 0
622619
end
623620

624-
# Parse subcommand (default to "notebook")
625-
subcommand = "notebook"
621+
# Parse subcommand (default to "lab")
622+
subcommand = "lab"
626623
args_start = 1
627624
if !isempty(ARGS)
628625
first_arg = ARGS[1]
@@ -660,7 +657,7 @@ function (@main)(ARGS)
660657
# Launch the appropriate command
661658
launch_func = subcommand == "notebook" ? notebook_cmd : jupyterlab_cmd
662659
try
663-
launch_func(Cmd(extra_args); dir=dir, detached=detached, port=port, verbose=verbose)
660+
launch_func(Cmd(extra_args); dir, detached, port, verbose)
664661
return 0
665662
catch e
666663
if e isa InterruptException
@@ -671,5 +668,6 @@ function (@main)(ARGS)
671668
end
672669
end
673670
end
671+
end # if VERSION
674672

675673
end # IJulia

test/main.jl

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -33,95 +33,70 @@ import IJulia
3333
end
3434

3535
# Test argument parsing without actually launching
36-
# We use mutable function references (notebook_cmd/jupyterlab_cmd) to test parsing
3736
@testset "argument parsing" begin
38-
# Save original functions
39-
orig_notebook = IJulia.notebook_cmd
40-
orig_jupyterlab = IJulia.jupyterlab_cmd
41-
42-
# Test notebook (default)
37+
# Test default subcommand (lab)
4338
called_with = nothing
44-
IJulia.notebook_cmd = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
39+
mock_jupyterlab = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
4540
called_with = (; args, dir, detached, port, verbose)
4641
return nothing
4742
end
4843

49-
try
50-
ret = IJulia.main(["--dir=/test", "--port=9999", "--detached", "--verbose", "--no-browser"])
51-
@test ret == 0
52-
@test !isnothing(called_with)
53-
@test called_with.dir == "/test"
54-
@test called_with.port == 9999
55-
@test called_with.detached == true
56-
@test called_with.verbose == true
57-
@test "--no-browser" in called_with.args
58-
finally
59-
IJulia.notebook_cmd = orig_notebook
60-
end
44+
ret = IJulia.main(["--dir=/test", "--port=9999", "--detached", "--verbose", "--no-browser"]; jupyterlab_cmd=mock_jupyterlab)
45+
@test ret == 0
46+
@test !isnothing(called_with)
47+
@test called_with.dir == "/test"
48+
@test called_with.port == 9999
49+
@test called_with.detached == true
50+
@test called_with.verbose == true
51+
@test "--no-browser" in called_with.args
6152

6253
# Test explicit notebook subcommand
6354
called_with = nothing
64-
IJulia.notebook_cmd = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
55+
mock_notebook = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
6556
called_with = (; args, dir, detached, port, verbose)
6657
return nothing
6758
end
6859

69-
try
70-
ret = IJulia.main(["notebook", "--port=8888"])
71-
@test ret == 0
72-
@test !isnothing(called_with)
73-
@test called_with.port == 8888
74-
@test called_with.dir == homedir()
75-
@test called_with.detached == false
76-
finally
77-
IJulia.notebook_cmd = orig_notebook
78-
end
60+
ret = IJulia.main(["notebook", "--dir=/test", "--port=9999", "--detached", "--verbose", "--no-browser"]; notebook_cmd=mock_notebook)
61+
@test ret == 0
62+
@test !isnothing(called_with)
63+
@test called_with.dir == "/test"
64+
@test called_with.port == 9999
65+
@test called_with.detached == true
66+
@test called_with.verbose == true
67+
@test "--no-browser" in called_with.args
7968

8069
# Test lab subcommand
8170
called_with = nothing
82-
IJulia.jupyterlab_cmd = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
71+
mock_jupyterlab = function(args=``; dir=homedir(), detached=false, port=nothing, verbose=false)
8372
called_with = (; args, dir, detached, port, verbose)
8473
return nothing
8574
end
8675

87-
try
88-
ret = IJulia.main(["lab", "--dir=/lab", "--verbose"])
89-
@test ret == 0
90-
@test !isnothing(called_with)
91-
@test called_with.dir == "/lab"
92-
@test called_with.verbose == true
93-
finally
94-
IJulia.jupyterlab_cmd = orig_jupyterlab
95-
end
76+
ret = IJulia.main(["lab", "--dir=/lab", "--verbose"]; jupyterlab_cmd=mock_jupyterlab)
77+
@test ret == 0
78+
@test !isnothing(called_with)
79+
@test called_with.dir == "/lab"
80+
@test called_with.verbose == true
9681
end
9782

9883
# Test InterruptException handling
9984
@testset "interrupt handling" begin
100-
orig_notebook = IJulia.notebook_cmd
101-
IJulia.notebook_cmd = function(args=``; kwargs...)
85+
mock_notebook = function(args=``; kwargs...)
10286
throw(InterruptException())
10387
end
10488

105-
try
106-
ret = IJulia.main([])
107-
@test ret == 0 # InterruptException should return 0
108-
finally
109-
IJulia.notebook_cmd = orig_notebook
110-
end
89+
ret = IJulia.main(["notebook"]; notebook_cmd=mock_notebook)
90+
@test ret == 0 # InterruptException should return 0
11191
end
11292

11393
# Test error handling
11494
@testset "error handling" begin
115-
orig_notebook = IJulia.notebook_cmd
116-
IJulia.notebook_cmd = function(args=``; kwargs...)
95+
mock_notebook = function(args=``; kwargs...)
11796
error("Test error")
11897
end
11998

120-
try
121-
ret = @test_logs (:error, r"Failed to launch") IJulia.main([])
122-
@test ret == 1 # Errors should return 1
123-
finally
124-
IJulia.notebook_cmd = orig_notebook
125-
end
99+
ret = @test_logs (:error, r"Failed to launch") IJulia.main(["notebook"]; notebook_cmd=mock_notebook)
100+
@test ret == 1 # Errors should return 1
126101
end
127102
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const TEST_FILES = [
77
"inline.jl", "completion.jl", "jsonx.jl"
88
]
99

10+
if VERSION >= v"1.11"
11+
push!(TEST_FILES, "main.jl")
12+
end
13+
1014
for file in TEST_FILES
1115
println(file)
1216
include(file)

0 commit comments

Comments
 (0)