Skip to content

Commit

Permalink
use uv instead of pip if available (#139)
Browse files Browse the repository at this point in the history
* use uv instead of pip if available

* typo

---------

Co-authored-by: Christopher Doris <github.com/cjdoris>
  • Loading branch information
cjdoris committed Jul 7, 2024
1 parent 9b73ea5 commit e974445
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
22 changes: 19 additions & 3 deletions src/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ function _resolve_conda_remove(io, conda_env, pkgs)
nothing
end

function _which_pip()
uv = which("uv")
if uv !== nothing
return `$uv pip`, :uv
end
pip = which("pip")
if pip !== nothing
return `$pip`, :pip
end
error("expecting pip (or uv) to be installed")
end

function _resolve_pip_install(io, pip_specs, load_path)
args = String[]
for spec in pip_specs
Expand All @@ -327,7 +339,7 @@ function _resolve_pip_install(io, pip_specs, load_path)
STATE.resolved = true
STATE.load_path = load_path
withenv() do
pip = which("pip")
pip, _ = _which_pip()
cmd = `$pip install $vrb $args`
_run(io, cmd, "Installing Pip packages", flags=flags)
end
Expand All @@ -346,8 +358,12 @@ function _resolve_pip_remove(io, pkgs, load_path)
STATE.resolved = true
STATE.load_path = load_path
withenv() do
pip = which("pip")
cmd = `$pip uninstall $vrb -y $pkgs`
pip, kind = _which_pip()
if kind == :uv
cmd = `$pip uninstall $vrb $pkgs`
else
cmd = `$pip uninstall $vrb -y $pkgs`
end
_run(io, cmd, "Removing Pip packages", flags=flags)
end
finally
Expand Down
45 changes: 25 additions & 20 deletions test/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,33 @@ end
end

@testitem "pip install/remove python package" begin
include("setup.jl")
CondaPkg.add("python", version="==3.10.2")
# verify package isn't already installed
@test !occursin("six", status())
CondaPkg.withenv() do
isnull || @test_throws Exception run(`python -c "import six"`)
end
@testset "using $kind" for kind in ["pip", "uv"]
include("setup.jl")
CondaPkg.add("python", version="==3.10.2")
if kind == "uv"
CondaPkg.add("uv")
end
# verify package isn't already installed
@test !occursin("six", status())
CondaPkg.withenv() do
isnull || @test_throws Exception run(`python -c "import six"`)
end

# install package
CondaPkg.add_pip("six", version="==1.16.0")
@test occursin("six", status())
@test occursin("(==1.16.0)", status())
CondaPkg.withenv() do
isnull || run(`python -c "import six"`)
end
@test occursin("v1.16.0", status()) == !isnull
# install package
CondaPkg.add_pip("six", version="==1.16.0")
@test occursin("six", status())
@test occursin("(==1.16.0)", status())
CondaPkg.withenv() do
isnull || run(`python -c "import six"`)
end
@test occursin("v1.16.0", status()) == !isnull

# remove package
CondaPkg.rm_pip("six")
@test !occursin("six", status())
CondaPkg.withenv() do
isnull || @test_throws Exception run(`python -c "import six"`)
# remove package
CondaPkg.rm_pip("six")
@test !occursin("six", status())
CondaPkg.withenv() do
isnull || @test_throws Exception run(`python -c "import six"`)
end
end
end

Expand Down

0 comments on commit e974445

Please sign in to comment.