From 30f51d9cc01a7e5a99fa2d76c7d5b7c9aa8259cc Mon Sep 17 00:00:00 2001 From: Frankie Robertson Date: Mon, 14 Aug 2023 17:00:38 +0300 Subject: [PATCH] Only run __init__ when not precompling --- src/setup.jl | 87 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/src/setup.jl b/src/setup.jl index 06b3d86e..6eab5db6 100644 --- a/src/setup.jl +++ b/src/setup.jl @@ -173,56 +173,59 @@ include(joinpath(dirname(@__FILE__),"..","deps","setup.jl")) currently_compiling() = ccall(:jl_generating_output, Cint, ()) != 0 function __init__() - if !currently_compiling() && Rhome == "" - error( - "No R installation was detected as RCall installation time. " * - "Please provided the location of R by setting the Rhome and libR preferences or " * - "else set R_HOME='*' and rerun Pkg.build(\"RCall\") to use Conda.jl." - ) - end - validate_libR(libR) - - # Check if R already running - # for some reaons, cglobal((:R_NilValue, libR)) doesn't work on rstudio/linux - # https://github.com/Non-Contradiction/JuliaCall/issues/34 - Rinited, from_libR = try - unsafe_load(cglobal(:R_NilValue, Ptr{Cvoid})) != C_NULL, false - catch - unsafe_load(cglobal((:R_NilValue, libR), Ptr{Cvoid})) != C_NULL, true - end + if !currently_compiling() + if Rhome == "" + error( + "No R installation was detected as RCall installation time. " * + "Please provided the location of R by setting the Rhome and libR preferences or " * + "else set R_HOME='*' and rerun Pkg.build(\"RCall\") to use Conda.jl." + ) + end - if !Rinited - initEmbeddedR() - end + validate_libR(libR) - ip = ccall((:Rf_ScalarInteger, libR),Ptr{Cvoid},(Cint,),0) + # Check if R already running + # for some reaons, cglobal((:R_NilValue, libR)) doesn't work on rstudio/linux + # https://github.com/Non-Contradiction/JuliaCall/issues/34 + Rinited, from_libR = try + unsafe_load(cglobal(:R_NilValue, Ptr{Cvoid})) != C_NULL, false + catch + unsafe_load(cglobal((:R_NilValue, libR), Ptr{Cvoid})) != C_NULL, true + end - Const.load(from_libR) + if !Rinited + initEmbeddedR() + end - # set up function callbacks - setup_callbacks() + ip = ccall((:Rf_ScalarInteger, libR),Ptr{Cvoid},(Cint,),0) - if !Rinited - # print warnings as they arise - # we can't use Rf_PrintWarnings as not exported on all platforms. - rcall_p(:options,warn=1) + Const.load(from_libR) - # disable menu on windows - rcall_p(:options; Symbol("menu.graphics") => false) + # set up function callbacks + setup_callbacks() - # R gui eventloop - isinteractive() && rgui_init() - end + if !Rinited + # print warnings as they arise + # we can't use Rf_PrintWarnings as not exported on all platforms. + rcall_p(:options,warn=1) - @require AxisArrays="39de3d68-74b9-583c-8d2d-e117c070f3a9" begin - include("convert/axisarray.jl") - end + # disable menu on windows + rcall_p(:options; Symbol("menu.graphics") => false) + + # R gui eventloop + isinteractive() && rgui_init() + end - # R REPL mode - isdefined(Base, :active_repl) && - isinteractive() && typeof(Base.active_repl) != REPL.BasicREPL && - !RPrompt.repl_inited(Base.active_repl) && RPrompt.repl_init(Base.active_repl) + @require AxisArrays="39de3d68-74b9-583c-8d2d-e117c070f3a9" begin + include("convert/axisarray.jl") + end + + # R REPL mode + isdefined(Base, :active_repl) && + isinteractive() && typeof(Base.active_repl) != REPL.BasicREPL && + !RPrompt.repl_inited(Base.active_repl) && RPrompt.repl_init(Base.active_repl) - # # IJulia hooks - isdefined(Main, :IJulia) && Main.IJulia.inited && ijulia_init() + # # IJulia hooks + isdefined(Main, :IJulia) && Main.IJulia.inited && ijulia_init() + end end