Skip to content
Open
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
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,7 +20,6 @@ Dates = "1"
Libdl = "1"
MacroTools = "0.5"
Markdown = "1"
Pkg = "1"
PyCall = "1"
Serialization = "1"
Tables = "1"
Expand Down
2 changes: 0 additions & 2 deletions src/C/C.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 27 additions & 15 deletions src/C/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions src/JlWrap/JlWrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import ..PythonCall:
PyObjectMatrix,
PyObjectArray

using Pkg: Pkg
using Base: @propagate_inbounds, allocatedinline

import ..Core: Py
Expand Down Expand Up @@ -70,7 +69,6 @@ function __init__()
jl.Core = Base.Core
jl.Base = Base
jl.Main = Main
jl.Pkg = Pkg
jl.PythonCall = PythonCall
end

Expand Down
2 changes: 1 addition & 1 deletion test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "Aqua" begin
import Aqua
Aqua.test_all(PythonCall)
Aqua.test_all(PythonCall; stale_deps=(; ignore=[:CondaPkg]))
end
Loading