Skip to content

Commit

Permalink
Fix Julia 1.11 errors (#191)
Browse files Browse the repository at this point in the history
* Fix Julia 1.11 errors

Fixes #190.

* Fixup pkg mode

* Adjust which versions are run in the matrix

* Rewrite comment and move to be more clear
  • Loading branch information
MichaelHatherly authored Oct 16, 2024
1 parent 8915e8f commit 5332bc5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
matrix:
version:
- "1.6"
- "1.10"
- "1.11"
os:
- ubuntu-latest
- macos-13
Expand All @@ -58,11 +58,17 @@ jobs:
os: macos-13
- version: "1.6"
os: windows-latest
# Performance regressions on Julia 1.11 on Windows. Currently not
# viable to run the test suite there.
- version: "1.11"
os: windows-latest
include:
- version: "1.7"
os: macos-13
- version: "1.7"
os: windows-latest
- version: "1.10"
os: windows-latest
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
Expand Down
1 change: 0 additions & 1 deletion src/QuartoNotebookWorker/src/NotebookState.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function __init__()
if ccall(:jl_generating_output, Cint, ()) == 0
PROJECT[] = Base.active_project()
OPTIONS[] = task_local_storage(:QUARTO_NOTEBOOK_WORKER_OPTIONS, Dict{String,Any}())
define_notebook_module!()
end
end

Expand Down
52 changes: 26 additions & 26 deletions src/QuartoNotebookWorker/src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,24 @@ function _render_thunk(
end
end

# Setting the `helpmode` module isn't an option on Julia 1.6 so we need to
# manually replace `Main` with the module we want.
function _helpmode(code::AbstractString, mod::Module)
ex = REPL.helpmode(code)
return postwalk(ex) do x
return x == Main ? mod : x
@static if VERSION < v"1.11.0"
# Earlier versions of Julia don't have the `helpmode` method that takes
# `io`, `code`, `mod` and so we have to manually alter the returned
# expression instead.
ex = REPL.helpmode(code)
ex = postwalk(ex) do x
return x == Main ? mod : x
end
# helpmode embeds object references to `stdout` into the expression, but
# since we are capturing the output it refers to a different stream. We
# need to replace the first `stdout` reference with `:stdout` and remove
# the argument from the other call so that it uses the redirected one.
ex.args[2] = :stdout
deleteat!(ex.args[end].args, 3)
return ex
else
return :(Core.eval($(mod), $(REPL).helpmode(stdout, $(code), $(mod))))
end
end

Expand All @@ -138,15 +150,6 @@ function _process_code(
if startswith(code, help_regex)
code = String(chomp(replace(code, help_regex => ""; count = 1)))
ex = _helpmode(code, mod)

# helpmode embeds object references to `stdout` into the
# expression, but since we are capturing the output it refers to
# a different stream. We need to replace the first `stdout`
# reference with `:stdout` and remove the argument from the
# other call so that it uses the redirected one.
ex.args[2] = :stdout
deleteat!(ex.args[end].args, 3)

return Expr(:toplevel, ex)
end

Expand All @@ -166,19 +169,16 @@ function _process_code(
pkg_regex = r"^\s*\]"
if startswith(code, pkg_regex)
code = String(chomp(replace(code, pkg_regex => ""; count = 1)))
return Expr(
:toplevel,
:(
let printed = $(Pkg).REPLMode.PRINTED_REPL_WARNING[]
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = true
try
$(Pkg).REPLMode.do_cmd($(Pkg).REPLMode.MiniREPL(), $code)
finally
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = printed
end
return Expr(:toplevel, :(
let printed = $(Pkg).REPLMode.PRINTED_REPL_WARNING[]
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = true
try
$(Pkg).REPLMode.@pkg_str $code
finally
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = printed
end
),
)
end
))
end

return _parseall(code; filename, lineno)
Expand Down
1 change: 1 addition & 0 deletions src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function worker_init(f::File, options::Dict)
),
)
end
QNW.NotebookState.define_notebook_module!(Main)
global refresh!(args...) = QNW.refresh!($(f.path), $(options), args...)
global render(args...; kwargs...) = QNW.render(args...; kwargs...)
end
Expand Down

0 comments on commit 5332bc5

Please sign in to comment.