Skip to content

Commit

Permalink
updates for Julia 0.7, version parsing, and latest conda version (#103)
Browse files Browse the repository at this point in the history
* use VersionParsing to parse version numbers, drop 0.5 support

* updates for 0.7, fixes for latest Conda version where environments do not get their own conda.exe and other changes
  • Loading branch information
stevengj authored Jun 9, 2018
1 parent b94203a commit ea09df2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 68 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- osx
- linux
julia:
- 0.5
- 0.6
- nightly
env:
Expand Down
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.5
julia 0.6
BinDeps
Compat 0.27.0
Compat 0.62.0
JSON
VersionParsing
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
Expand All @@ -27,4 +25,3 @@ build_script:

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "ENV[\"HOME\"]=joinpath(homedir(),\"Conda test home\"); Pkg.test(\"Conda\")"

44 changes: 18 additions & 26 deletions src/Conda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ provides(Conda.Manager, "libnetcdf", netcdf)
```
"""
module Conda
using Compat
using JSON
using Compat, JSON, VersionParsing

const deps_file = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")

Expand Down Expand Up @@ -87,22 +86,19 @@ function python_dir(env::Environment)
end
const PYTHONDIR = python_dir(ROOTENV)

function conda_bin(env::Environment)
if Compat.Sys.iswindows()
p = script_dir(env)
conda_bat = joinpath(p, "conda.bat")
return isfile(conda_bat) ? conda_bat : joinpath(p, "conda.exe")
else
return joinpath(script_dir(env), "conda")
end
# note: the same conda program is used for all environments
const conda = if Compat.Sys.iswindows()
p = script_dir(ROOTENV)
conda_bat = joinpath(p, "conda.bat")
isfile(conda_bat) ? conda_bat : joinpath(p, "conda.exe")
else
joinpath(bin_dir(ROOTENV), "conda")
end
const conda = conda_bin(ROOTENV)

"Path to the condarc file"
conda_rc(env::Environment) = joinpath(prefix(env), "condarc-julia.yml")
const CONDARC = conda_rc(ROOTENV)


"""
Use a cleaned up environment for the command `cmd`.
Expand All @@ -120,20 +116,20 @@ function _set_conda_env(cmd, env::Environment=ROOTENV)
pop!(env_var, var)
end
env_var["CONDARC"] = conda_rc(env)
env_var["CONDA_PREFIX"] = env_var["CONDA_DEFAULT_ENV"] = prefix(env)
env_var["CONDA_PREFIX"] = prefix(env)
setenv(cmd, env_var)
end

"Run conda command with environment variables set."
function runconda(args::Cmd, env::Environment=ROOTENV)
_install_conda(env)
run(_set_conda_env(`$(conda_bin(env)) $args`, env))
run(_set_conda_env(`$conda $args`, env))
end

"Run conda command with environment variables set and return the json output as a julia object"
function parseconda(args::Cmd, env::Environment=ROOTENV)
_install_conda(env)
JSON.parse(readstring(_set_conda_env(`$(conda_bin(env)) $args --json`, env)))
JSON.parse(read(_set_conda_env(`$conda $args --json`, env), String))
end

"Get the miniconda installer URL."
Expand Down Expand Up @@ -171,7 +167,7 @@ function _install_conda(env::Environment, force::Bool=false)
https://github.com/conda/conda/issues/1084
""")
end
info("Downloading miniconda installer ...")
Compat.@info("Downloading miniconda installer ...")
if Compat.Sys.isunix()
installer = joinpath(PREFIX, "installer.sh")
end
Expand All @@ -180,7 +176,7 @@ function _install_conda(env::Environment, force::Bool=false)
end
download(_installer_url(), installer)

info("Installing miniconda ...")
Compat.@info("Installing miniconda ...")
if Compat.Sys.isunix()
chmod(installer, 33261) # 33261 corresponds to 755 mode of the 'chmod' program
run(`$installer -b -f -p $PREFIX`)
Expand All @@ -193,8 +189,7 @@ function _install_conda(env::Environment, force::Bool=false)
runconda(`update $(_quiet()) -y conda`)
end
if !isdir(prefix(env))
# conda doesn't allow totally empty environments. using zlib as the default package
runconda(`create $(_quiet()) -y -p $(prefix(env)) zlib`)
runconda(`create $(_quiet()) -y -p $(prefix(env))`)
end
end

Expand All @@ -217,18 +212,15 @@ end
function _installed_packages_dict(env::Environment=ROOTENV)
_install_conda(env)
package_dict = Dict{String, Tuple{VersionNumber, String}}()
for line in eachline(_set_conda_env(`$(conda_bin(env)) list`, env))
for line in eachline(_set_conda_env(`$conda list`, env))
line = chomp(line)
if !startswith(line, "#")
name, version, build_string = split(line)
# As julia do not accepts xx.yy.zz.rr version number the last part is removed.
# see issue https://github.com/JuliaLang/julia/issues/7282 a maximum of three levels is inserted
version_number = join(split(version,".")[1:min(3,end)],".")
try
package_dict[name] = (convert(VersionNumber, version_number), line)
package_dict[name] = (vparse(version), line)
catch
package_dict[name] = (v"9999.9999.9999", line)
warn("Failed parsing string: \"$(version_number)\" to a version number. Please open an issue!")
warn("Failed parsing string: \"$(version)\" to a version number. Please open an issue!")
end
end
end
Expand Down Expand Up @@ -273,7 +265,7 @@ end

"Check if a given package exists."
function exists(package::AbstractString, env::Environment=ROOTENV)
if contains(package,"==")
if occursin("==", package)
pkg,ver=split(package,"==") # Remove version if provided
return pkg in search(pkg,ver,env)
else
Expand Down
19 changes: 8 additions & 11 deletions src/bindeps_conda.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This file contains the necessary ingredients to create a PackageManager for BinDeps
using BinDeps

type EnvManager{T} <: BinDeps.PackageManager
struct EnvManager{T} <: BinDeps.PackageManager
packages::Vector{String}
end

"Manager for root environment"
const Manager = EnvManager{Symbol(PREFIX)}

function Base.show{T}(io::IO, manager::EnvManager{T})
function Base.show(io::IO, manager::EnvManager)
write(io, "Conda packages: ", join(manager.packages, ", "))
end

BinDeps.can_use(::Type{EnvManager}) = true

function BinDeps.package_available{T}(manager::EnvManager{T})
function BinDeps.package_available(manager::EnvManager{T}) where {T}
pkgs = manager.packages
# For each package, see if we can get info about it. If not, fail out
for pkg in pkgs
Expand All @@ -25,21 +25,18 @@ function BinDeps.package_available{T}(manager::EnvManager{T})
return true
end

BinDeps.libdir{T}(m::EnvManager{T}, ::Any) = lib_dir(T)
BinDeps.bindir{T}(m::EnvManager{T}, ::Any) = bin_dir(T)
BinDeps.libdir(m::EnvManager{T}, ::Any) where {T} = lib_dir(T)
BinDeps.bindir(m::EnvManager{T}, ::Any) where {T} = bin_dir(T)

BinDeps.provider{T, S<:String}(::Type{EnvManager{T}}, packages::Vector{S}; opts...) = EnvManager{T}(packages)
BinDeps.provider{T}(::Type{EnvManager{T}}, packages::String; opts...) = EnvManager{T}([packages])
BinDeps.provider(::Type{EnvManager{T}}, packages::AbstractVector{<:AbstractString}; opts...) where {T} = EnvManager{T}(packages)
BinDeps.provider(::Type{EnvManager{T}}, packages::AbstractString; opts...) where {T} = EnvManager{T}([packages])

function BinDeps.generate_steps(dep::BinDeps.LibraryDependency, manager::EnvManager, opts)
pkgs = manager.packages
if isa(pkgs, AbstractString)
pkgs = [pkgs]
end
()->install(pkgs, manager)
end

function install{T}(pkgs, manager::EnvManager{T})
function install(pkgs, manager::EnvManager{T}) where {T}
for pkg in pkgs
add(pkg, T)
end
Expand Down
34 changes: 9 additions & 25 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
using Conda
using BinDeps
using Base.Test
using Compat
using Conda, BinDeps, Compat, VersionParsing
using Compat.Test

env = Conda.Environment(:test_conda_jl)
env = :test_conda_jl
@test Conda.exists("curl", env)
Conda.add("curl", env)

if Compat.Sys.isunix()
curl_path = joinpath(Conda.prefix(env), "bin", "curl-config")
end
if Compat.Sys.iswindows()
curl_path = joinpath(Conda.lib_dir(env), "curl.exe")
end
exe = Compat.Sys.iswindows() ? ".exe" : ""

curl_path = joinpath(Conda.bin_dir(env), "curl" * exe)
@test isfile(curl_path)

@test isfile(joinpath(Conda.bin_dir(env), basename(curl_path)))

Conda.rm("curl", env)
if Compat.Sys.isunix()
@test !isfile(curl_path)
end
@test !isfile(curl_path)

@test isfile(Conda.conda_bin(env))
Conda.add("python", env)
pythonpath = joinpath(Conda.python_dir(env), "python" * (Compat.Sys.iswindows() ? ".exe" : ""))
pythonpath = joinpath(Conda.PYTHONDIR, "python" * exe)
@test isfile(pythonpath)
pyversion = readstring(`$pythonpath -c "import sys; print(sys.version)"`)
pyversion = read(`$pythonpath -c "import sys; print(sys.version)"`, String)
@test pyversion[1:1] == Conda.MINICONDA_VERSION

channels = Conda.channels()
@test channels == ["defaults"]

Conda.add_channel("foo", env)
@test Conda.channels(env) == ["foo", "defaults"]
# Testing that calling the function twice do not fail
Conda.add_channel("foo", env)

Conda.rm_channel("foo", env)
channels = Conda.channels(env)
@test channels == ["defaults"]
@test Conda.channels(env) == ["defaults"]

0 comments on commit ea09df2

Please sign in to comment.