Skip to content

Commit e7d1c1c

Browse files
author
KristofferC
committed
updates based on review
1 parent 5605638 commit e7d1c1c

File tree

4 files changed

+46
-67
lines changed

4 files changed

+46
-67
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
@@ -575,11 +575,8 @@ include("precompile.jl")
575575
#######################################################################
576576
# App entry point for `ijulia` command
577577

578-
# Mutable function references for testing - allows tests to mock these functions
579-
notebook_cmd::Function = notebook
580-
jupyterlab_cmd::Function = jupyterlab
581-
582-
function (@main)(ARGS)
578+
if VERSION >= v"1.11"
579+
function (@main)(ARGS; notebook_cmd::Function = notebook, jupyterlab_cmd::Function = jupyterlab)
583580
# Show help if help flag
584581
if !isempty(ARGS) && ARGS[1] in ("--help", "-h", "help")
585582
println("""
@@ -609,8 +606,8 @@ function (@main)(ARGS)
609606
return 0
610607
end
611608

612-
# Parse subcommand (default to "notebook")
613-
subcommand = "notebook"
609+
# Parse subcommand (default to "lab")
610+
subcommand = "lab"
614611
args_start = 1
615612
if !isempty(ARGS)
616613
first_arg = ARGS[1]
@@ -648,7 +645,7 @@ function (@main)(ARGS)
648645
# Launch the appropriate command
649646
launch_func = subcommand == "notebook" ? notebook_cmd : jupyterlab_cmd
650647
try
651-
launch_func(Cmd(extra_args); dir=dir, detached=detached, port=port, verbose=verbose)
648+
launch_func(Cmd(extra_args); dir, detached, port, verbose)
652649
return 0
653650
catch e
654651
if e isa InterruptException
@@ -659,5 +656,6 @@ function (@main)(ARGS)
659656
end
660657
end
661658
end
659+
end # if VERSION
662660

663661
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import Aqua
33
import IJulia
44

55
const TEST_FILES = [
6-
"install.jl", "comm.jl", "msg.jl", "execute_request.jl", "stdio.jl",
7-
"inline.jl", "completion.jl", "jsonx.jl"
6+
# "install.jl", "comm.jl", "msg.jl", "execute_request.jl", "stdio.jl",
7+
# "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)