Skip to content

Commit

Permalink
fix pkg mode in 1.11 (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Oct 14, 2024
1 parent dfa8f21 commit f0f0027
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
11 changes: 9 additions & 2 deletions src/execute_request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
# returning results.

import Base.Libc: flush_cstdio

import Pkg
if VERSION < v"1.11"
do_pkg_cmd(cmd::AbstractString) =
Pkg.REPLMode.do_cmd(minirepl[], cmd; do_rethrow=true)
else # Pkg.jl#3777
do_pkg_cmd(cmd::AbstractString) =
Pkg.REPLMode.do_cmds(cmd, stdout)
end

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

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

# a cell beginning with "? ..." is interpreted as a help request
Expand Down
25 changes: 15 additions & 10 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ const read_stdout = Ref{Base.PipeEndpoint}()
const read_stderr = Ref{Base.PipeEndpoint}()
const socket_locks = Dict{Socket,ReentrantLock}()

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

function init(args)
inited && error("IJulia is already running")
Expand Down Expand Up @@ -108,7 +111,9 @@ function init(args)
redirect_stderr(IJuliaStdio(stderr,"stderr"))
end
redirect_stdin(IJuliaStdio(stdin,"stdin"))
minirepl[] = MiniREPL(TextDisplay(stdout))
@static if VERSION < v"1.11"
minirepl[] = MiniREPL(TextDisplay(stdout))
end

logger = ConsoleLogger(Base.stderr)
Base.CoreLogging.global_logger(logger)
Expand Down

0 comments on commit f0f0027

Please sign in to comment.