Skip to content

Commit a2ee9c6

Browse files
committed
Load CondaPkg lazily, and drop Pkg as a dependency
1 parent 2381ce1 commit a2ee9c6

6 files changed

Lines changed: 15 additions & 12 deletions

File tree

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1010
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1111
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
12-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1312
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1413
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1514
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
@@ -22,7 +21,6 @@ Dates = "1"
2221
Libdl = "1"
2322
MacroTools = "0.5"
2423
Markdown = "1"
25-
Pkg = "1"
2624
Preferences = "1"
2725
PyCall = "1"
2826
Serialization = "1"

docs/src/pythoncall.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ to your current Julia project containing Python and any required Python packages
282282

283283
You can configure PythonCall with the preferences listed below. These can be set either as
284284
[Julia preferences](https://github.com/JuliaPackaging/Preferences.jl) or as environment
285-
variables.
285+
variables. If an environment variable and preference are both set, the
286+
preference will take priority.
286287

287288
| Preference | Environment Variable | Description |
288289
| ---------- | -------------------- | ----------- |

src/C/C.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ using ..Utils
99

1010
using Base: @kwdef
1111
using UnsafePointers: UnsafePtr
12-
using CondaPkg: CondaPkg
13-
using Pkg: Pkg
1412
using Libdl:
1513
dlpath, dlopen, dlopen_e, dlclose, dlsym, dlsym_e, RTLD_LAZY, RTLD_DEEPBIND, RTLD_GLOBAL
1614

15+
if Utils.getpref_exe(; prefonly=true) == "@CondaPkg"
16+
using CondaPkg: CondaPkg
17+
end
18+
1719
import ..PythonCall:
1820
python_executable_path, python_library_path, python_library_handle, python_version
1921

src/C/context.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function init_context()
124124
else
125125
# Find Python executable
126126
exe_path = Utils.getpref_exe()
127-
if exe_path == "" || exe_path == "@CondaPkg"
127+
if exe_path == "@CondaPkg"
128128
if CondaPkg.backend() == :Null
129129
exe_path = Sys.which("python")
130130
if exe_path === nothing

src/JlWrap/JlWrap.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import ..PythonCall:
3030
PyObjectMatrix,
3131
PyObjectArray
3232

33-
using Pkg: Pkg
3433
using Base: @propagate_inbounds, allocatedinline
3534

3635
import ..Core: Py
@@ -70,7 +69,6 @@ function __init__()
7069
jl.Core = Base.Core
7170
jl.Base = Base
7271
jl.Main = Main
73-
jl.Pkg = Pkg
7472
jl.PythonCall = PythonCall
7573
end
7674

src/Utils/Utils.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ module Utils
22

33
using Preferences: @load_preference
44

5-
function getpref(::Type{T}, prefname, envname, default = nothing) where {T}
5+
function getpref(::Type{T}, prefname, envname, default = nothing; prefonly=false) where {T}
66
ans = @load_preference(prefname, nothing)
77
ans === nothing || return checkpref(T, ans)::T
8-
ans = get(ENV, envname, "")
9-
isempty(ans) || return checkpref(T, ans)::T
8+
9+
if !prefonly
10+
ans = get(ENV, envname, "")
11+
isempty(ans) || return checkpref(T, ans)::T
12+
end
13+
1014
return default
1115
end
1216

1317
checkpref(::Type{String}, x) = error("invalid preference of type $(type(x)), expecting a string")
1418
checkpref(::Type{String}, x::AbstractString) = convert(String, x)
1519

1620
# Specific preference functions
17-
getpref_exe() = getpref(String, "exe", "JULIA_PYTHONCALL_EXE", "")
21+
getpref_exe(; kwargs...) = getpref(String, "exe", "JULIA_PYTHONCALL_EXE", "@CondaPkg"; kwargs...)
1822
getpref_lib() = getpref(String, "lib", "JULIA_PYTHONCALL_LIB", nothing)
1923
getpref_pickle() = getpref(String, "pickle", "JULIA_PYTHONCALL_PICKLE", "pickle")
2024

0 commit comments

Comments
 (0)