Skip to content

Commit

Permalink
conda install withenv
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Aug 23, 2016
1 parent 8b0256b commit ee6fa26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Conda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ const conda = joinpath(SCRIPTDIR, "conda")
const CONDARC = joinpath(PREFIX, "condarc-julia")

"""
Use a cleaned up environment for the command `cmd`.
Get a cleaned up environment for the command `cmd`.
Any environment variable starting by CONDA will interact with the run.
"""
function _set_conda_env(cmd)
function _get_conda_env()
env = copy(ENV)
to_remove = AbstractString[]
for var in keys(env)
Expand All @@ -70,7 +70,16 @@ function _set_conda_env(cmd)
pop!(env, var)
end
env["CONDARC"] = CONDARC
setenv(cmd, env)
env
end

"""
Use a cleaned up environment for the command `cmd`.
Any environment variable starting by CONDA will interact with the run.
"""
function _set_conda_env(cmd)
setenv(cmd, _get_conda_env())
end

"Get the miniconda installer URL."
Expand Down Expand Up @@ -143,7 +152,9 @@ end
"Install a new package."
function add(pkg::AbstractString)
_install_conda()
run(_set_conda_env(`$conda install -y $pkg`))
withenv(_get_conda_env()...) do
run(`$conda install -y $pkg`)
end
end

"Uninstall a package."
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ Conda.add_channel("foo")
Conda.rm_channel("foo")
channels = Conda.channels()
@test (isempty(channels) || channels == ["defaults"])

# install qt
if is_windows()
Conda.add("qt")
Conda.rm("qt")
end

0 comments on commit ee6fa26

Please sign in to comment.