Skip to content

Instantly share code, notes, and snippets.

@j-fu
Created October 30, 2024 09:57
Show Gist options
  • Save j-fu/4fedb3ae3bfa0cce4ce6bf8e060857c5 to your computer and use it in GitHub Desktop.
Save j-fu/4fedb3ae3bfa0cce4ce6bf8e060857c5 to your computer and use it in GitHub Desktop.
"""
force_update_notebook_environment(notebook)
Forced update of notebook environment to all newest versions of the packages.
`Pluto.update_notebook_environment(notebook)` heeds
the compat entries in the Project.toml and thus seems to do nothing.
"""
function force_update_notebook_environment(notebook)
# cache the current environment
thisproject=Pkg.project().path
@info "Force updating packages in $(notebook):"
tmp=mktempdir()
tmpjl=joinpath(tmp,"tmp.jl")
cp(notebook,"$(notebook).bak",force=true)
@info "Created backup in $(notebook).bak"
cp(notebook,tmpjl,force=true)
# After this, notebook env + curent env are in sync
Pluto.activate_notebook_environment(tmpjl)
# Get list of current dependencies and their UUIDs:
pkgs=[PackageSpec(uuid=v) for (k,v) in Pkg.project().dependencies]
# Remove and re-add packages, thus ignoring compat
if length(pkgs) >0
Pkg.rm(pkgs)
sleep(1)
Pkg.add(pkgs)
# let the environments sync
sleep(1)
end
# Sets compat to the current versions
Pluto.update_notebook_environment(tmpjl)
@info "Updating of $(notebook) done\n"
sleep(1)
cp(tmpjl,notebook,force=true)
# Re-activate the current environment
Pkg.activate(thisproject)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment