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

auto pkg fixes: remove sources? #3101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
65 changes: 44 additions & 21 deletions src/packages/Packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,34 +475,57 @@ function _resolve(notebook::Notebook, iolistener::IOListener)
end


struct AutoFix
fix::Function
name::String
end



const auto_fixes = [
AutoFix("Updating registries") do notebook
PkgCompat.update_registries(; force=true)
end,
AutoFix("Removing Manifest") do notebook
reset_nbpkg!(notebook; keep_project=true, save=false, backup=false)
notebook.nbpkg_ctx_instantiated = false
end,
AutoFix("Removing sourcesssss") do notebook
# reset_nbpkg!(notebook; keep_project=true, save=false, backup=false)
# PkgCompat.clear_compat_entries!(notebook.nbpkg_ctx)
# notebook.nbpkg_ctx_instantiated = false
end,
AutoFix("Removing Project compat entries and Manifest") do notebook
reset_nbpkg!(notebook; keep_project=true, save=false, backup=false)
PkgCompat.clear_compat_entries!(notebook.nbpkg_ctx)
notebook.nbpkg_ctx_instantiated = false
end,
]







"""
Run `f` (e.g. `Pkg.instantiate`) on the notebook's package environment. Keep trying more and more invasive strategies to fix problems until the operation succeeds.
"""
function with_auto_fixes(f::Function, notebook::Notebook)
try
f()
catch e
@info "Operation failed. Updating registries and trying again..." exception=e

PkgCompat.update_registries(; force=true)
function with_auto_fixes(f::Function, notebook::Notebook, index::Int=1)

if index > length(auto_fixes)
return f()
else
try
f()
catch e
@warn "Operation failed. Removing Manifest and trying again..." exception=e
fix = auto_fixes[index]
exception = index < length(auto_fixes) ? e : (e, catch_backtrace())

reset_nbpkg!(notebook; keep_project=true, save=false, backup=false)
notebook.nbpkg_ctx_instantiated = false
try
f()
catch e
@warn "Operation failed. Removing Project compat entries and Manifest and trying again..." exception=(e, catch_backtrace())

reset_nbpkg!(notebook; keep_project=true, save=false, backup=false)
PkgCompat.clear_compat_entries!(notebook.nbpkg_ctx)
notebook.nbpkg_ctx_instantiated = false

f()
end
@info "Operation failed. $(fix.name) and trying again..." exception

fix.fix(notebook)
with_auto_fixes(f, notebook, index + 1)
end
end
end
Expand Down
Loading