Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pkg mode in 1.11 #1124

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading