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

conda install withenv #41

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
conda install withenv
wookay committed Aug 23, 2016
commit ee6fa267d8ad80d51a583023d2ddc87b8192f339
19 changes: 15 additions & 4 deletions src/Conda.jl
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you remove this function and replace other uses of if with the same withenv construct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if so, it's need to refactor with the newer function like run_with_env.

run_with_env(`$conda install -y $pkg`)

run_with_env(`$conda remove -y $pkg`)

instead of

withenv(_get_conda_env()...) do
    run(`$conda install -y $pkg`)
end

run(_set_conda_env(`$conda remove -y $pkg`))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, go for it! I just do not like to have two very similar functions with close names 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed something,
but it still needs the _set_conda_env function for
that is used to get the information from the commands.

 return collect(keys(JSON.parse(readstring(_set_conda_env(`$conda search $package --json`)))))

setenv(cmd, _get_conda_env())
end

"Get the miniconda installer URL."
@@ -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."
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably clean up after itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added removing qt. thanks.

Conda.rm("qt")
end