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

RFC: Add an API to safely add conda packages #613

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: switch to Conda.add(packages) once the Conda.jl version containing JuliaPy/Conda.jl#130 is released.

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