Skip to content

Commit f0f0027

Browse files
authored
fix pkg mode in 1.11 (#1124)
1 parent dfa8f21 commit f0f0027

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/execute_request.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
# returning results.
44

55
import Base.Libc: flush_cstdio
6+
67
import Pkg
8+
if VERSION < v"1.11"
9+
do_pkg_cmd(cmd::AbstractString) =
10+
Pkg.REPLMode.do_cmd(minirepl[], cmd; do_rethrow=true)
11+
else # Pkg.jl#3777
12+
do_pkg_cmd(cmd::AbstractString) =
13+
Pkg.REPLMode.do_cmds(cmd, stdout)
14+
end
715

816
# global variable so that display can be done in the correct Msg context
917
execute_msg = Msg(["julia"], Dict("username"=>"jlkernel", "session"=>uuid4()), Dict())
@@ -47,8 +55,7 @@ function execute_request(socket, msg)
4755

4856
# "] ..." cells are interpreted as pkg shell commands
4957
if occursin(r"^\].*$", code)
50-
code = "IJulia.Pkg.REPLMode.do_cmd(IJulia.minirepl[], \"" *
51-
escape_string(code[2:end]) * "\"; do_rethrow=true)"
58+
code = "IJulia.do_pkg_cmd(\"" * escape_string(code[2:end]) * "\")"
5259
end
5360

5461
# a cell beginning with "? ..." is interpreted as a help request

src/init.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ const read_stdout = Ref{Base.PipeEndpoint}()
3030
const read_stderr = Ref{Base.PipeEndpoint}()
3131
const socket_locks = Dict{Socket,ReentrantLock}()
3232

33-
# similar to Pkg.REPLMode.MiniREPL, a minimal REPL-like emulator
34-
# for use with Pkg.do_cmd. We have to roll our own to
35-
# make sure it uses the redirected stdout, and because
36-
# we don't have terminal support.
37-
import REPL
38-
struct MiniREPL <: REPL.AbstractREPL
39-
display::TextDisplay
33+
# needed for executing pkg commands on earlier Julia versions
34+
@static if VERSION < v"1.11"
35+
# similar to Pkg.REPLMode.MiniREPL, a minimal REPL-like emulator
36+
# for use with Pkg.do_cmd. We have to roll our own to
37+
# make sure it uses the redirected stdout, and because
38+
# we don't have terminal support.
39+
import REPL
40+
struct MiniREPL <: REPL.AbstractREPL
41+
display::TextDisplay
42+
end
43+
REPL.REPLDisplay(repl::MiniREPL) = repl.display
44+
const minirepl = Ref{MiniREPL}()
4045
end
41-
REPL.REPLDisplay(repl::MiniREPL) = repl.display
42-
const minirepl = Ref{MiniREPL}()
4346

4447
function init(args)
4548
inited && error("IJulia is already running")
@@ -108,7 +111,9 @@ function init(args)
108111
redirect_stderr(IJuliaStdio(stderr,"stderr"))
109112
end
110113
redirect_stdin(IJuliaStdio(stdin,"stdin"))
111-
minirepl[] = MiniREPL(TextDisplay(stdout))
114+
@static if VERSION < v"1.11"
115+
minirepl[] = MiniREPL(TextDisplay(stdout))
116+
end
112117

113118
logger = ConsoleLogger(Base.stderr)
114119
Base.CoreLogging.global_logger(logger)

0 commit comments

Comments
 (0)