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 Julia 1.11 errors #191

Merged
merged 4 commits into from
Oct 16, 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
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
MichaelHatherly marked this conversation as resolved.
Show resolved Hide resolved
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 @@
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"

Check warning on line 123 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L123

Added line #L123 was not covered by tests
# 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

Check warning on line 129 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L127-L129

Added lines #L127 - L129 were not covered by tests
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

Check warning on line 137 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L135-L137

Added lines #L135 - L137 were not covered by tests
else
return :(Core.eval($(mod), $(REPL).helpmode(stdout, $(code), $(mod))))

Check warning on line 139 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L139

Added line #L139 was not covered by tests
MichaelHatherly marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand All @@ -138,15 +150,6 @@
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 @@
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, :(

Check warning on line 172 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L172

Added line #L172 was not covered by tests
let printed = $(Pkg).REPLMode.PRINTED_REPL_WARNING[]
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = true
try
$(Pkg).REPLMode.@pkg_str $code

Check warning on line 176 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L174-L176

Added lines #L174 - L176 were not covered by tests
finally
$(Pkg).REPLMode.PRINTED_REPL_WARNING[] = printed

Check warning on line 178 in src/QuartoNotebookWorker/src/render.jl

View check run for this annotation

Codecov / codecov/patch

src/QuartoNotebookWorker/src/render.jl#L178

Added line #L178 was not covered by tests
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
Loading