Skip to content

Commit 94e751f

Browse files
author
Christopher Doris
committed
improve dependency resolution
1 parent beb32da commit 94e751f

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

PythonCallDeps.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[script]
22

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

src/deps.jl

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ function can_skip_resolve()
159159
# resolve whenever any of the environments in the load_path changes
160160
timestamp = get(deps, "timestamp", nothing)
161161
timestamp === nothing && return false
162+
load_path = get(deps, "load_path", nothing)
163+
load_path === nothing && return false
164+
load_path != Base.load_path() && return false
162165
for env in Base.load_path()
163166
proj = Base.env_project_file(env)
164167
dir = nothing
@@ -271,41 +274,69 @@ function resolve(; create=true, force=false)
271274
end
272275
end
273276

274-
# create and activate the conda environment with the desired packages
275-
# if update=true, just install the packages
277+
# canonicalise dependencies
278+
sort!(unique!(conda_channels))
279+
sort!(unique!(conda_packages))
280+
sort!(unique!(pip_packages))
281+
sort!(unique!(pip_indexes))
282+
sort!(unique!(scripts))
283+
284+
# determine if any dependencies have changed
276285
env = conda_env()
277-
conda_args = String[]
278-
for channel in conda_channels
279-
push!(conda_args, "--channel", channel)
286+
skip = !force && isdir(env)
287+
if skip
288+
depinfo = get_meta("jldeps")
289+
skip &= (
290+
conda_channels == get(depinfo, "conda_channels", nothing) &&
291+
conda_packages == get(depinfo, "conda_packages", nothing) &&
292+
pip_indexes == get(depinfo, "pip_indexes", nothing) &&
293+
pip_packages == get(depinfo, "pip_packages", nothing) &&
294+
scripts == get(depinfo, "scripts", nothing)
295+
)
280296
end
281-
append!(conda_args, conda_packages)
282-
if create
283-
conda_run_root(`create --yes --no-default-packages --prefix $env $conda_args`)
284-
conda_activate()
297+
298+
# create and activate the conda environment with the desired packages
299+
# if update=true, just install the packages
300+
if skip
301+
# nothing has changed
302+
create && conda_activate()
303+
285304
else
286-
conda_run(`install --yes $conda_args`)
287-
end
305+
conda_args = String[]
306+
for channel in conda_channels
307+
push!(conda_args, "--channel", channel)
308+
end
309+
append!(conda_args, conda_packages)
310+
if create || !isdir(env)
311+
ispath(env) && conda_run_root(`env remove --yes --prefix $env`)
312+
conda_run_root(`create --yes --no-default-packages --no-channel-priority --prefix $env $conda_args`)
313+
conda_activate()
314+
else
315+
conda_run(`install --yes $conda_args`)
316+
end
288317

289-
# install pip packages
290-
if !isempty(pip_packages)
291-
pip_enable()
292-
pip_args = String[]
293-
for index in pip_indexes
294-
push!(pip_args, "--extra-index-url", index)
318+
# install pip packages
319+
if !isempty(pip_packages)
320+
pip_enable()
321+
pip_args = String[]
322+
for index in pip_indexes
323+
push!(pip_args, "--extra-index-url", index)
324+
end
325+
append!(pip_args, pip_packages)
326+
pip_run(`install $pip_args`)
295327
end
296-
append!(pip_args, pip_packages)
297-
pip_run(`install $pip_args`)
298-
end
299328

300-
# run scripts
301-
for script in scripts
302-
@info "Executing `$script`"
303-
eval(Meta.parse(script))
329+
# run scripts
330+
for script in scripts
331+
@info "Executing `$script`"
332+
eval(Meta.parse(script))
333+
end
304334
end
305335

306336
# record what we did
307337
depinfo = Dict(
308338
"timestamp" => time(),
339+
"load_path" => Base.load_path(),
309340
"version" => string(PythonCall.VERSION),
310341
"files" => all_deps_files,
311342
"conda_packages" => conda_packages,
@@ -420,16 +451,16 @@ function add(; conda_channels=nothing, conda_packages=nothing, pip_indexes=nothi
420451
file = user_deps_file()
421452
deps = isfile(file) ? TOML.parsefile(file) : Dict{String,Any}()
422453
if conda_channels !== nothing
423-
union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "channels"), conda_channels)
454+
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "channels"), conda_channels))
424455
end
425456
if conda_packages !== nothing
426-
union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "packages"), conda_packages)
457+
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "conda"), "packages"), conda_packages))
427458
end
428459
if pip_indexes !== nothing
429-
union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "indexes"), pip_indexes)
460+
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "indexes"), pip_indexes))
430461
end
431462
if pip_packages !== nothing
432-
union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "packages"), pip_packages)
463+
sort!(union!(get!(Vector{String}, get!(Dict{String,Any}, deps, "pip"), "packages"), pip_packages))
433464
end
434465
if script_expr !== nothing
435466
get!(Dict{String,Any}, deps, "script")["expr"] = script_expr

0 commit comments

Comments
 (0)