Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/RFC: Use CompilePreferences.jl to configure Python per project #835

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
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
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
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