From baa3bc28078e6580d60443621040fe7a1ed8e491 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 7 Nov 2018 19:35:09 -0800 Subject: [PATCH] Add an API to safely add conda packages If a package installed via `Conda.add` is not available for installed Python version, `conda` may downgrade Python: https://discourse.julialang.org/t/help-understanding-pycall-related-travis-failure/15957 This brakes PyCall because it stores the path to libpython etc. This patch provides a workaround to the issue by adding an API that wraps `Conda.add` and re-build PyCall if Python version is changed during installation of conda packages. fix https://github.com/JuliaPy/Conda.jl/issues/127 --- src/PyCall.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PyCall.jl b/src/PyCall.jl index 46ee4643..6768ab24 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -3,6 +3,7 @@ VERSION < v"0.7.0-beta2.199" && __precompile__() module PyCall using Compat, VersionParsing +using Compat: Pkg, @info, @debug export pycall, pycall!, pyimport, pyimport_e, pybuiltin, PyObject, PyReverseDims, PyPtr, pyincref, pydecref, pyversion, PyArray, PyArray_Info, @@ -686,6 +687,32 @@ function pyimport_conda(modulename::AbstractString, condapkg::AbstractString, end end +""" + conda_add(packages::AbstractVector{<: AbstractString}) + +Install conda `pakcages` _if_ PyCall is configured to use Conda.jl; +otherwise this function does nothing. It is intended to be used from +`deps/build.jl` of the packages depending on PyCall, for safely +installing Python packages via conda. More precisely, this function +detects if Python executable is re-installed during installing +`packages` and then re-build PyCall if it happens. +""" +function conda_add(packages::AbstractVector{<: AbstractString}) + if conda + before = Conda.version("python") + for pkg in packages + Conda.add(pkg) + end + after = Conda.version("python") + if before != after + @info "Python version is changed from $before to $after. Re-building PyCall.jl" + Pkg.build("PyCall") + end + else + @debug "PyCall is not configured to use Conda.jl. Skip installing $packages." + end +end + ######################################################################### # look up a global builtin