Skip to content

Commit

Permalink
Use PyPreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Sep 25, 2020
1 parent fbd0bba commit a955681
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
PyPreferences = "cc9521c6-0242-4dda-8d66-c47a9d9eec02"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289"

Expand Down
1 change: 1 addition & 0 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optle
@eval Base.Experimental.@optlevel 1
end

using PyPreferences
using VersionParsing

export pycall, pycall!, pyimport, pyimport_e, pybuiltin, PyObject, PyReverseDims,
Expand Down
12 changes: 7 additions & 5 deletions src/startup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ else
global symbols_present = hassym(proc_handle, :Py_GetVersion)
end

if PyPreferences.inprocess
@assert symbols_present # TODO: better error
end

if !symbols_present
# Python not present. Use deps.jl
const depfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
isfile(depfile) || error("PyCall not properly installed. Please run Pkg.build(\"PyCall\")")
include(depfile) # generated by Pkg.build("PyCall")
PyPreferences.assert_configured()
using PyPreferences: PYTHONHOME, conda, libpython, pyprogramname, python, pyversion_build
# Only to be used at top-level - pointer will be invalid after reload
libpy_handle = try
Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_DEEPBIND|Libdl.RTLD_GLOBAL)
catch err
if err isa ErrorException
error(err.msg, ". Please run `Pkg.build(\"PyCall\")` if your Python build has changed")
error(err.msg, "\n", PyPreferences.instruction_message())
else
rethrow(err)
end
Expand Down

0 comments on commit a955681

Please sign in to comment.