Skip to content

Commit

Permalink
checkpoint recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 12, 2024
1 parent 63ab36f commit 0de8c73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 16 additions & 4 deletions PlotsBase/ext/PythonPlotExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ end
const mpl_toolkits = PythonCall.pynew()
const numpy = PythonCall.pynew()
const mpl = PythonCall.pynew()
const Gcf = PythonCall.pynew()
const orig_gcf = PythonCall.pynew()
const orig_figure = PythonCall.pynew()

using PlotsBase.Annotations
using PlotsBase.DataSeries
Expand Down Expand Up @@ -48,7 +45,7 @@ function PlotsBase.extension_init(::PythonPlotBackend)
backend_gui = PythonPlot.find_backend(mpl)
PythonPlot.backend = backend_gui[1]
PythonPlot.gui = backend_gui[2]
PythonCall.pycopy!(PythonPlot.pyplot, PythonCall.pyimport("matplotlib.pyplot")) # raw Python module
PythonCall.pycopy!(PythonPlot.pyplot, PythonCall.pyimport("matplotlib.pyplot")) # raw Python module
PythonCall.pycopy!(PythonPlot.Gcf, PythonCall.pyimport("matplotlib._pylab_helpers").Gcf)
PythonCall.pycopy!(PythonPlot.orig_gcf, PythonPlot.pyplot.gcf)
PythonCall.pycopy!(PythonPlot.orig_figure, PythonPlot.pyplot.figure)
Expand Down Expand Up @@ -79,6 +76,21 @@ function PlotsBase.extension_init(::PythonPlotBackend)
end
end

function PlotsBase.extension_cleanup(::PythonPlotBackend)
mpl_toolkits = PythonCall.pynew()
numpy = PythonCall.pynew()
mpl = PythonCall.pynew()
PythonPlot.pyplot.gcf = PythonCall.pynew()
PythonPlot.pyplot.figure = PythonCall.pynew()
PythonPlot.pyplot = PythonCall.pynew()
PythonPlot.Gcf = PythonCall.pynew()
PythonPlot.orig_gcf = PythonCall.pynew()
PythonPlot.orig_figure = PythonCall.pynew()
PythonPlot.backend = PythonCall.pynew()
PythonPlot.gui = PythonCall.pynew()
nothing
end

PlotsBase.@extension_static PythonPlotBackend pythonplot

const _pythonplot_attrs = PlotsBase.merge_with_base_supported([
Expand Down
2 changes: 2 additions & 0 deletions PlotsBase/src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ end
"extra init step for an extension"
extension_init(::AbstractBackend) = nothing

extension_cleanup(::AbstractBackend) = nothing

"generate extension `__init__` function, and common defines"
macro extension_static(be_type, be)
be_sym = QuoteNode(be)
Expand Down
9 changes: 5 additions & 4 deletions PlotsBase/src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ function diagnostics(io::IO = stdout)
end

macro precompile_backend(backend_package)
abstract_backend = Symbol(backend_package, :Backend)
quote
PrecompileTools.@setup_workload begin
using PlotsBase # for extensions
backend($(Symbol(backend_package, :Backend)))
__init__() # must call init !!
# PlotsBase.extension_init($be_type()) # because `__init__` has `ccall(:jl_generating_output, Cint, ()) == 1 && return`
backend($abstract_backend())
__init__() # call extension module init !!
@debug PlotsBase.backend_package_name()
n = length(PlotsBase._examples)
imports = sizehint!(Expr[], n)
Expand Down Expand Up @@ -164,9 +164,10 @@ macro precompile_backend(backend_package)
PrecompileTools.@compile_workload begin
eval.(imports)
eval.(examples)
PlotsBase.CURRENT_PLOT.nullableplot = nothing
PlotsBase.extension_cleanup($abstract_backend())
end
end
PlotsBase.CURRENT_PLOT.nullableplot = nothing
end
end |> esc
end

0 comments on commit 0de8c73

Please sign in to comment.