Skip to content

Commit b59000d

Browse files
author
Christopher Doris
committed
tweaks to dependencies
1 parent 9d887ff commit b59000d

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

PythonCallDeps.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[conda]
44
packages = ["pip>=18", "python>=3.5,<4"]
5-
channels = []
5+
channels = ["defaults"]

src/deps.jl

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function can_skip_resolve()
178178
stat(fn).mtime < timestamp || return false
179179
end
180180
end
181-
return deps
181+
return false
182182
end
183183

184184
"""
@@ -312,7 +312,7 @@ function resolve(; create=true, force=false)
312312
conda_run_root(`create --yes --no-default-packages --no-channel-priority --prefix $env $conda_args`)
313313
conda_activate()
314314
else
315-
conda_run(`install --yes $conda_args`)
315+
conda_run(`install --yes --no-channel-priority --satisfied-skip-solve $conda_args`)
316316
end
317317

318318
# install pip packages
@@ -429,6 +429,17 @@ function status()
429429
end
430430
end
431431

432+
function getconvert!(::Type{T}, x, k) where {T}
433+
v = get!(T, x, k)
434+
if v isa T
435+
return v::T
436+
else
437+
v = convert(T, v)
438+
x[k] = v
439+
return x[k]::T
440+
end
441+
end
442+
432443
"""
433444
add(...)
434445
@@ -444,33 +455,34 @@ Keyword arguments (all optional):
444455
- `resolve=true`: When true, immediately resolve the dependencies. Otherwise, the
445456
dependencies are not resolved until you call [`resolve`](@ref) or load PythonCall in a
446457
new Julia session.
458+
- `create=true`: When true, creates the environment from scratch when resolving.
447459
448460
The conda and pip packages can include version specifiers, such as `python>=3.6`.
449461
"""
450-
function add(; conda_channels=nothing, conda_packages=nothing, pip_indexes=nothing, pip_packages=nothing, script_expr=nothing, script_file=nothing, resolve=true)
462+
function add(; conda_channels=nothing, conda_packages=nothing, pip_indexes=nothing, pip_packages=nothing, script_expr=nothing, script_file=nothing, resolve=true, create=true)
451463
file = user_deps_file()
452464
deps = isfile(file) ? TOML.parsefile(file) : Dict{String,Any}()
453465
if conda_channels !== nothing
454-
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "channels"), conda_channels))
466+
sort!(union!(getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "conda"), "channels"), conda_channels))
455467
end
456468
if conda_packages !== nothing
457-
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "packages"), conda_packages))
469+
sort!(union!(getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "conda"), "packages"), conda_packages))
458470
end
459471
if pip_indexes !== nothing
460-
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "indexes"), pip_indexes))
472+
sort!(union!(getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "pip"), "indexes"), pip_indexes))
461473
end
462474
if pip_packages !== nothing
463-
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "packages"), pip_packages))
475+
sort!(union!(getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "pip"), "packages"), pip_packages))
464476
end
465477
if script_expr !== nothing
466-
get!(Dict{String,Any}, deps, "script")["expr"] = script_expr
478+
getconvert!(Dict{String,Any}, deps, "script")["expr"] = script_expr
467479
end
468480
if script_file !== nothing
469-
get!(Dict{String,Any}, deps, "script")["file"] = script_file
481+
getconvert!(Dict{String,Any}, deps, "script")["file"] = script_file
470482
end
471483
open(io->TOML.print(io, deps), file, "w")
472484
if resolve
473-
Deps.resolve(force=true)
485+
Deps.resolve(force=true, create=create)
474486
end
475487
return
476488
end
@@ -490,31 +502,32 @@ Keyword arguments (all optional):
490502
- `resolve=true`: When true, immediately resolve the dependencies. Otherwise, the
491503
dependencies are not resolved until you call [`resolve`](@ref) or load PythonCall in a
492504
new Julia session.
505+
- `create=true`: When true, creates the environment from scratch when resolving.
493506
"""
494-
function rm(; conda_channels=nothing, conda_packages=nothing, pip_indexes=nothing, pip_packages=nothing, script_expr=false, script_file=false, resolve=true)
507+
function rm(; conda_channels=nothing, conda_packages=nothing, pip_indexes=nothing, pip_packages=nothing, script_expr=false, script_file=false, resolve=true, create=true)
495508
file = user_deps_file()
496509
deps = isfile(file) ? TOML.parsefile(file) : Dict{String,Any}()
497510
if conda_channels !== nothing
498-
filter!(x -> x conda_channels, get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "channels"))
511+
filter!(x -> x conda_channels, getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "conda"), "channels"))
499512
end
500513
if conda_packages !== nothing
501-
filter!(x -> spec_split(x)[1] conda_packages, get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "packages"))
514+
filter!(x -> spec_split(x)[1] conda_packages, getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "conda"), "packages"))
502515
end
503516
if pip_indexes !== nothing
504-
filter!(x -> x pip_indexes, get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "indexes"))
517+
filter!(x -> x pip_indexes, getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "pip"), "indexes"))
505518
end
506519
if pip_packages !== nothing
507-
filter!(x -> spec_split(x)[1] pip_packages, get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "packages"))
520+
filter!(x -> spec_split(x)[1] pip_packages, getconvert!(Vector{String}, getconvert!(Dict{String,Any}, deps, "pip"), "packages"))
508521
end
509522
if script_expr
510-
delete!(get!(Dict{String,Any}, deps, "script"), "expr")
523+
delete!(getconvert!(Dict{String,Any}, deps, "script"), "expr")
511524
end
512525
if script_file !== nothing
513-
delete!(get!(Dict{String,Any}, deps, "script"), "file")
526+
delete!(getconvert!(Dict{String,Any}, deps, "script"), "file")
514527
end
515528
open(io->TOML.print(io, deps), file, "w")
516529
if resolve
517-
Deps.resolve(force=true)
530+
Deps.resolve(force=true, create=create)
518531
end
519532
return
520533
end

0 commit comments

Comments
 (0)