diff --git a/Project.toml b/Project.toml index e4fd1c4d..03b95974 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" UnsafePointers = "e17b2a0c-0bdf-430a-bd0c-3a23cae4ff39" @@ -21,7 +20,6 @@ Dates = "1" Libdl = "1" MacroTools = "0.5" Markdown = "1" -Pkg = "1" PyCall = "1" Serialization = "1" Tables = "1" diff --git a/src/C/C.jl b/src/C/C.jl index a8e7d5f8..c6573604 100644 --- a/src/C/C.jl +++ b/src/C/C.jl @@ -7,8 +7,6 @@ module C using Base: @kwdef using UnsafePointers: UnsafePtr -using CondaPkg: CondaPkg -using Pkg: Pkg using Libdl: dlpath, dlopen, dlopen_e, dlclose, dlsym, dlsym_e, RTLD_LAZY, RTLD_DEEPBIND, RTLD_GLOBAL diff --git a/src/C/context.jl b/src/C/context.jl index 4d83cf2a..d2fda14f 100644 --- a/src/C/context.jl +++ b/src/C/context.jl @@ -102,6 +102,16 @@ Execute `f()` on the main thread. """ on_main_thread +# CondaPkg is a rather heavy dependency so we go to some effort to load it lazily +const CondaPkg_pkgid = Base.PkgId(Base.UUID("992eb4ea-22a4-4c89-a5bb-47a3300528ab"), "CondaPkg") + +function load_CondaPkg(f::Function) + if !haskey(Base.loaded_modules, CondaPkg_pkgid) + Base.require(@__MODULE__, :CondaPkg) + end + + @invokelatest f(Base.loaded_modules[CondaPkg_pkgid]) +end function init_context() @@ -125,22 +135,24 @@ function init_context() # Find Python executable exe_path = get(ENV, "JULIA_PYTHONCALL_EXE", "") if exe_path == "" || exe_path == "@CondaPkg" - if CondaPkg.backend() == :Null - exe_path = Sys.which("python") - if exe_path === nothing - error("CondaPkg is using the Null backend but Python is not installed") + load_CondaPkg() do CondaPkg + if CondaPkg.backend() == :Null + exe_path = Sys.which("python") + if exe_path === nothing + error("CondaPkg is using the Null backend but Python is not installed") + end + exe_path::String + else + # By default, we use Python installed by CondaPkg. + exe_path = + Sys.iswindows() ? joinpath(CondaPkg.envdir(), "python.exe") : + joinpath(CondaPkg.envdir(), "bin", "python") + # It's not sufficient to only activate the env while Python is initialising, + # it must also be active when loading extension modules (e.g. numpy). So we + # activate the environment globally. + # TODO: is this really necessary? + CondaPkg.activate!(ENV) end - exe_path::String - else - # By default, we use Python installed by CondaPkg. - exe_path = - Sys.iswindows() ? joinpath(CondaPkg.envdir(), "python.exe") : - joinpath(CondaPkg.envdir(), "bin", "python") - # It's not sufficient to only activate the env while Python is initialising, - # it must also be active when loading extension modules (e.g. numpy). So we - # activate the environment globally. - # TODO: is this really necessary? - CondaPkg.activate!(ENV) end CTX.which = :CondaPkg elseif exe_path == "@PyCall" diff --git a/src/JlWrap/JlWrap.jl b/src/JlWrap/JlWrap.jl index 79b9c6b6..802ce465 100644 --- a/src/JlWrap/JlWrap.jl +++ b/src/JlWrap/JlWrap.jl @@ -30,7 +30,6 @@ import ..PythonCall: PyObjectMatrix, PyObjectArray -using Pkg: Pkg using Base: @propagate_inbounds, allocatedinline import ..Core: Py @@ -70,7 +69,6 @@ function __init__() jl.Core = Base.Core jl.Base = Base jl.Main = Main - jl.Pkg = Pkg jl.PythonCall = PythonCall end diff --git a/test/Aqua.jl b/test/Aqua.jl index f3f26542..ae680d0a 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -1,4 +1,4 @@ @testitem "Aqua" begin import Aqua - Aqua.test_all(PythonCall) + Aqua.test_all(PythonCall; stale_deps=(; ignore=[:CondaPkg])) end