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

Fixing exists by adding keywords #167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ where you can type `add Conda` to install this package.

Once Conda is installed, you can run `import Conda` to load the package and run a variety of package-management functions:

- `Conda.add(package, env; channel="")`: install a package from a specified channel (optional);
- `Conda.rm(package, env)`: remove (uninstall) a package;
- `Conda.update(env)`: update all installed packages to the latest version;
- `Conda.list(env)`: list all installed packages.
- `Conda.add_channel(channel, env)`: add a channel to the list of channels;
- `Conda.channels(env)`: get the current list of channels;
- `Conda.rm_channel(channel, env)`: remove a channel from the list of channels;
- `Conda.add(package; env=ROOTENV, channel="")`: install a package from a specified channel (optional);
- `Conda.rm(package, env=ROOTENV)`: remove (uninstall) a package;
- `Conda.update(env=ROOTENV)`: update all installed packages to the latest version;
- `Conda.list(env=ROOTENV)`: list all installed packages.
- `Conda.add_channel(channel, env=ROOTENV)`: add a channel to the list of channels;
- `Conda.channels(env=ROOTENV)`: get the current list of channels;
- `Conda.rm_channel(channel, env=ROOTENV)`: remove a channel from the list of channels;

The parameter `env` is optional and defaults to `ROOTENV`. See below for more info.

Expand Down
18 changes: 12 additions & 6 deletions src/Conda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ end
const PkgOrPkgs = Union{AbstractString, AbstractVector{<: AbstractString}}

"Install a new package or packages."
function add(pkg::PkgOrPkgs, env::Environment=ROOTENV; channel::AbstractString="")
function add(pkg::PkgOrPkgs; env::Environment=ROOTENV, channel::AbstractString="")
Copy link
Member

@stevengj stevengj Feb 8, 2020

Choose a reason for hiding this comment

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

This is a breaking change. You should add:

@deprecate add(pkg::PkgOrPkgs, env::Environment; channel::AbstractString="") add(pkg, env=env, channel=channel)

and similar so that callers using the old API still function, albeit with a warning message.

c = isempty(channel) ? `` : `-c $channel`
runconda(`install $(_quiet()) -y $c $pkg`, env)
end

@deprecate add(pkg::PkgOrPkgs, env::Environment; channel::AbstractString="") add(pkg, env=env, channel=channel)
"Uninstall a package or packages."
function rm(pkg::PkgOrPkgs, env::Environment=ROOTENV)
runconda(`remove $(_quiet()) -y $pkg`, env)
Expand Down Expand Up @@ -265,13 +266,16 @@ function version(name::AbstractString, env::Environment=ROOTENV)
error("Could not find the $name package")
end

@deprecate search(package::AbstractString, env::Environment) search(package,env=env)
@deprecate search(package::AbstractString, _ver::Union{AbstractString,VersionNumber}, env::Environment) search(package, _ver; env=env)

"Search packages for a string"
function search(package::AbstractString, env::Environment=ROOTENV)
function search(package::AbstractString; env::Environment=ROOTENV)
return collect(keys(parseconda(`search $package`, env)))
end

"Search a specific version of a package"
function search(package::AbstractString, _ver::Union{AbstractString,VersionNumber}, env::Environment=ROOTENV)
function search(package::AbstractString, _ver::Union{AbstractString,VersionNumber}; env::Environment=ROOTENV)
ret=parseconda(`search $package`, env)
out = String[]
ver = string(_ver)
Expand All @@ -285,13 +289,15 @@ function search(package::AbstractString, _ver::Union{AbstractString,VersionNumbe
out
end

@deprecate exists(package::AbstractString, env::Environment) exists(package, env=env)

"Check if a given package exists."
function exists(package::AbstractString, env::Environment=ROOTENV)
function exists(package::AbstractString; env::Environment=ROOTENV)
if occursin("==", package)
pkg,ver=split(package,"==") # Remove version if provided
return pkg in search(pkg,ver,env)
return pkg in search(pkg,ver,env=env)
else
if package in search(package,env)
if package in search(package,env=Symbol(env))
# Found exactly this package
return true
else
Expand Down
19 changes: 10 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ Conda.update()
env = :test_conda_jl
rm(Conda.prefix(env); force=true, recursive=true)

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

@testset "Install Python package" begin
Conda.add("python=3.6", env) # 3.7 doesn't work on Windows at the moment
Conda.add("python=3.6", env=env) # 3.7 doesn't work on Windows at the moment
pythonpath = joinpath(Conda.python_dir(env), "python" * exe)
@test isfile(pythonpath)

cmd = Conda._set_conda_env(`$pythonpath -c "import zmq"`, env)
@test_throws Exception run(cmd)
Conda.add("pyzmq", env)
Conda.add("pyzmq", env=env)
run(cmd)
end

curlvers = Conda.version("curl",env)
@test curlvers >= v"5.0"
@test Conda.exists("curl==$curlvers", env)
@test Conda.exists("curl==$curlvers", env=env)

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

@test "curl" in Conda.search("cu*", env)
@test "curl" in Conda.search("cu*", env=env)

Conda.rm("curl", env)
@test !isfile(curl_path)
Expand Down Expand Up @@ -57,10 +58,10 @@ Conda.rm_channel("foo", env)
@test Conda.channels(env) == ["defaults"]

# Add a package from a specific channel
Conda.add("requests", env; channel="conda-forge")
Conda.add("requests"; env=env, channel="conda-forge")

@testset "Batch install and uninstall" begin
Conda.add(["affine", "ansi2html"], env)
Conda.add(["affine", "ansi2html"], env=env)
installed = Conda._installed_packages(env)
@test "affine" ∈ installed
@test "ansi2html" ∈ installed
Expand All @@ -76,7 +77,7 @@ Conda.clean(; debug=true)

@testset "Exporting and creating environments" begin
new_env = :test_conda_jl_2
Conda.add("curl", env)
Conda.add("curl", env=env)
Conda.export_list("conda-pkg.txt", env)

# Create a new environment
Expand Down