Skip to content

Commit

Permalink
Add an API to safely add conda packages
Browse files Browse the repository at this point in the history
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 breaks 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 JuliaPy/Conda.jl#127
  • Loading branch information
tkf committed Nov 8, 2018
1 parent fe67ef2 commit 8a313ae
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -686,6 +687,33 @@ 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
@debug "PyCall is not configured to use Conda.jl. Skip installing $packages."
return
end

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
end

#########################################################################

# look up a global builtin
Expand Down

0 comments on commit 8a313ae

Please sign in to comment.