Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve changed env #73

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased
* Adds named shared environments: `JULIA_CONDAPKG_ENV=@<name>`.
* Add `update` function and REPL command.
* Add `update` function and PkgREPL command.
* Bug fixes.


Expand Down
58 changes: 28 additions & 30 deletions src/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down