From d8c1b0c699d9c7054b6f5a151cbbdce8682c500a Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Fri, 27 Jan 2023 09:29:31 +0000 Subject: [PATCH] resolve if conda_env has changed (#73) Co-authored-by: Christopher Doris --- CHANGELOG.md | 2 +- src/resolve.jl | 58 ++++++++++++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7198fbd..497d640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased * Adds named shared environments: `JULIA_CONDAPKG_ENV=@`. -* Add `update` function and REPL command. +* Add `update` function and PkgREPL command. * Bug fixes. diff --git a/src/resolve.jl b/src/resolve.jl index b60dbba..9a2cccf 100644 --- a/src/resolve.jl +++ b/src/resolve.jl @@ -17,30 +17,37 @@ function _resolve_top_env(load_path) top_env end -function _resolve_can_skip_1(load_path, meta_file) +function _resolve_env_is_clean(conda_env, meta) + conda_env == meta.conda_env || return false + stat(conda_env).mtime ≤ meta.timestamp || return false + isdir(conda_env) && return true + (isempty(meta.packages) && isempty(meta.pip_packages)) && return true + false +end + +function _resolve_can_skip_1(conda_env, load_path, meta_file) + isdir(conda_env) || return false + isfile(meta_file) || return false meta = open(read_meta, meta_file) - if meta !== nothing && meta.version == VERSION && meta.load_path == load_path - timestamp = max(meta.timestamp, stat(meta_file).mtime) - skip = true - for env in [meta.load_path; meta.extra_path] - dir = isfile(env) ? dirname(env) : isdir(env) ? env : continue - if isdir(dir) - if stat(dir).mtime > timestamp - skip = false - break - else - fn = joinpath(dir, "CondaPkg.toml") - if isfile(fn) && stat(fn).mtime > timestamp - skip = false - break - end + meta !== nothing || return false + meta.version == VERSION || return false + meta.load_path == load_path || return false + meta.conda_env == conda_env || return false + timestamp = max(meta.timestamp, stat(meta_file).mtime) + for env in [meta.load_path; meta.extra_path] + dir = isfile(env) ? dirname(env) : isdir(env) ? env : continue + if isdir(dir) + if stat(dir).mtime > timestamp + return false + else + fn = joinpath(dir, "CondaPkg.toml") + if isfile(fn) && stat(fn).mtime > timestamp + return false end end end - return skip - else - return false end + return true end _convert(::Type{T}, @nospecialize(x)) where {T} = convert(T, x)::T @@ -374,15 +381,6 @@ function offline() end end -function is_clean(conda_env, meta) - meta === nothing && return false - conda_env == meta.conda_env || return false - stat(conda_env).mtime ≤ meta.timestamp || return false - isdir(conda_env) && return true - (isempty(meta.packages) && isempty(meta.pip_packages)) && return true - false -end - function resolve(; force::Bool=false, io::IO=stderr, interactive::Bool=false, dry_run::Bool=false) # if frozen, do nothing STATE.frozen && return @@ -446,7 +444,7 @@ function resolve(; force::Bool=false, io::IO=stderr, interactive::Bool=false, dr end try # skip resolving if nothing has changed since the metadata was updated - if !force && isdir(conda_env) && isfile(meta_file) && _resolve_can_skip_1(load_path, meta_file) + if !force && _resolve_can_skip_1(conda_env, load_path, meta_file) STATE.resolved = true interactive && _log(io, "Dependencies already up to date") return @@ -495,7 +493,7 @@ function resolve(; force::Bool=false, io::IO=stderr, interactive::Bool=false, dr end end # install/uninstall packages - if (back === :Current) || (!force && is_clean(conda_env, meta)) + if (back === :Current) || (!force && meta !== nothing && _resolve_env_is_clean(conda_env, meta)) # the state is sufficiently clean that we can modify the existing conda environment changed = false if !isempty(removed_pip_pkgs) && !shared