Created
October 30, 2024 09:57
-
-
Save j-fu/4fedb3ae3bfa0cce4ce6bf8e060857c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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