From 33df3bf4acab69326901b9922354849371b50e6b Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Wed, 5 Feb 2020 15:30:54 -0800 Subject: [PATCH 1/3] this just fixes Conda.exists --- src/Conda.jl | 2 +- test/runtests.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Conda.jl b/src/Conda.jl index e637f0c..7ff432e 100644 --- a/src/Conda.jl +++ b/src/Conda.jl @@ -291,7 +291,7 @@ function exists(package::AbstractString, env::Environment=ROOTENV) pkg,ver=split(package,"==") # Remove version if provided return pkg in search(pkg,ver,env) else - if package in search(package,env) + if package in search(package,Symbol(env)) # Found exactly this package return true else diff --git a/test/runtests.jl b/test/runtests.jl index f2d8789..211cedc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ env = :test_conda_jl rm(Conda.prefix(env); force=true, recursive=true) @test Conda.exists("curl", env) +@test Conda.exists("curl", "test_conda_jl") Conda.add("curl", env) @testset "Install Python package" begin From 446485ddb59d1b3e8f0bdabc230e370d24964814 Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Wed, 5 Feb 2020 18:43:42 -0800 Subject: [PATCH 2/3] key values for search, exists, optionally for add --- README.md | 14 +++++++------- src/Conda.jl | 16 ++++++++++------ test/runtests.jl | 14 +++++++------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fde4972..4236512 100644 --- a/README.md +++ b/README.md @@ -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="")` or `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. diff --git a/src/Conda.jl b/src/Conda.jl index 7ff432e..8dcf54f 100644 --- a/src/Conda.jl +++ b/src/Conda.jl @@ -192,7 +192,11 @@ 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="") + add(pkg,env,channel) +end + +function add(pkg::PkgOrPkgs, env::Environment, channel::AbstractString="") c = isempty(channel) ? `` : `-c $channel` runconda(`install $(_quiet()) -y $c $pkg`, env) end @@ -266,12 +270,12 @@ function version(name::AbstractString, env::Environment=ROOTENV) end "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) @@ -286,12 +290,12 @@ function search(package::AbstractString, _ver::Union{AbstractString,VersionNumbe end "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,Symbol(env)) + if package in search(package,env=Symbol(env)) # Found exactly this package return true else diff --git a/test/runtests.jl b/test/runtests.jl index 211cedc..f4ae139 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,12 +7,12 @@ Conda.update() env = :test_conda_jl rm(Conda.prefix(env); force=true, recursive=true) -@test Conda.exists("curl", env) -@test Conda.exists("curl", "test_conda_jl") +@test Conda.exists("curl", env=env) +@test Conda.exists("curl", env="test_conda_jl") Conda.add("curl", 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) @@ -24,12 +24,12 @@ 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) @@ -58,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 From ee58649679200f385400267dfb6d841d163d63ca Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Sun, 9 Feb 2020 16:41:22 -0800 Subject: [PATCH 3/3] @deprecate old versions --- README.md | 2 +- src/Conda.jl | 10 ++++++---- test/runtests.jl | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4236512..db14fc1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ 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=ROOTENV, channel="")` or `Conda.add(package, env=ROOTENV; channel="")`: install a package from a specified channel (optional); +- `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. diff --git a/src/Conda.jl b/src/Conda.jl index 8dcf54f..8c4df54 100644 --- a/src/Conda.jl +++ b/src/Conda.jl @@ -193,14 +193,11 @@ const PkgOrPkgs = Union{AbstractString, AbstractVector{<: AbstractString}} "Install a new package or packages." function add(pkg::PkgOrPkgs; env::Environment=ROOTENV, channel::AbstractString="") - add(pkg,env,channel) -end - -function add(pkg::PkgOrPkgs, env::Environment, channel::AbstractString="") 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) @@ -269,6 +266,9 @@ 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) return collect(keys(parseconda(`search $package`, env))) @@ -289,6 +289,8 @@ 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) if occursin("==", package) diff --git a/test/runtests.jl b/test/runtests.jl index f4ae139..5289503 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,7 +9,7 @@ rm(Conda.prefix(env); force=true, recursive=true) @test Conda.exists("curl", env=env) @test Conda.exists("curl", env="test_conda_jl") -Conda.add("curl", env) +Conda.add("curl"; env=env) @testset "Install Python package" begin Conda.add("python=3.6", env=env) # 3.7 doesn't work on Windows at the moment @@ -18,7 +18,7 @@ Conda.add("curl", env) 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 @@ -77,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