Skip to content

Commit

Permalink
Pass --file to conda config to avoid writing to ~/.condarc (#141)
Browse files Browse the repository at this point in the history
* Pass --file to `conda config` to avoid writing to `~/.condarc`.

* Test last modified time for user condarc file.
  • Loading branch information
rofinn authored and omus committed Jan 29, 2019
1 parent 4725842 commit 3f681ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Conda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ end

"Get the list of channels used to search packages"
function channels(env::Environment=ROOTENV)
ret=parseconda(`config --get channels`, env)
ret=parseconda(`config --get channels --file $(conda_rc(env))`, env)
if haskey(ret["get"], "channels")
return collect(String, ret["get"]["channels"])
else
Expand All @@ -298,12 +298,12 @@ end

"Add a channel to the list of channels"
function add_channel(channel::AbstractString, env::Environment=ROOTENV)
runconda(`config --add channels $channel --force`, env)
runconda(`config --add channels $channel --file $(conda_rc(env)) --force`, env)
end

"Remove a channel from the list of channels"
function rm_channel(channel::AbstractString, env::Environment=ROOTENV)
runconda(`config --remove channels $channel --force`, env)
runconda(`config --remove channels $channel --file $(conda_rc(env)) --force`, env)
end

"""
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ pythonpath = joinpath(Conda.PYTHONDIR, "python" * exe)
pyversion = read(`$pythonpath -c "import sys; print(sys.version)"`, String)
@test pyversion[1:1] == Conda.MINICONDA_VERSION

condarc_path = joinpath(homedir(), ".condarc")
last_modified = mtime(condarc_path)

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)

# Validate that only the Conda.jl RC file was modified
@test occursin("foo", read(Conda.conda_rc(env), String))
@test !isfile(condarc_path) || !occursin("foo", read(condarc_path, String))

Conda.rm_channel("foo", env)
@test mtime(condarc_path) == last_modified

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

@testset "Batch install and uninstall" begin
Expand Down

0 comments on commit 3f681ee

Please sign in to comment.