Skip to content

Commit

Permalink
Capture IO from Pkg.rm (#2924)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored May 23, 2024
1 parent 2e272c5 commit b223265
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/packages/Packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function sync_nbpkg_core(
can_skip = isempty(removed) && isempty(added) && notebook.nbpkg_ctx_instantiated

iolistener = let
busy_packages = notebook.nbpkg_ctx_instantiated ? added : new_packages
busy_packages = notebook.nbpkg_ctx_instantiated ? union(added, removed) : new_packages
report_to = ["nbpkg_sync", busy_packages...]
IOListener(callback=(s -> on_terminal_output(report_to, freeze_loading_spinners(s))))
end
Expand Down Expand Up @@ -204,10 +204,12 @@ function sync_nbpkg_core(
mkeys() = Set(filter(!is_stdlib, [m.name for m in values(PkgCompat.dependencies(notebook.nbpkg_ctx))]))
old_manifest_keys = mkeys()

Pkg.rm(notebook.nbpkg_ctx, [
Pkg.PackageSpec(name=p)
for p in to_remove
])
with_io_setup(notebook, iolistener) do
Pkg.rm(notebook.nbpkg_ctx, [
Pkg.PackageSpec(name=p)
for p in to_remove
])
end

notebook.nbpkg_install_time_ns = nothing # we lose our estimate of install time
# We record the manifest before and after, to prevent recommending a reboot when nothing got removed from the manifest (e.g. when removing GR, but leaving Plots), or when only stdlibs got removed.
Expand Down
14 changes: 14 additions & 0 deletions test/packages/Basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ import Malt
@test notebook.nbpkg_restart_required_msg === nothing
@test notebook.nbpkg_ctx_instantiated
@test notebook.nbpkg_install_time_ns > last_install_time
@test notebook.nbpkg_terminal_outputs["nbpkg_sync"] != ""
@test notebook.nbpkg_terminal_outputs["PlutoPkgTestB"] != ""
@test occursin("+ PlutoPkgTestB", notebook.nbpkg_terminal_outputs["PlutoPkgTestB"])

@test notebook.nbpkg_busy_packages == []
last_install_time = notebook.nbpkg_install_time_ns

Expand Down Expand Up @@ -189,6 +193,11 @@ import Malt
@test notebook.nbpkg_ctx !== nothing
@test notebook.nbpkg_restart_recommended_msg === nothing
@test notebook.nbpkg_restart_required_msg === nothing
@test notebook.nbpkg_busy_packages == []
@test notebook.nbpkg_terminal_outputs["nbpkg_sync"] != ""
@test notebook.nbpkg_terminal_outputs["Dates"] != ""
@test occursin("- Dates", notebook.nbpkg_terminal_outputs["Dates"])
@test occursin("- Dates", notebook.nbpkg_terminal_outputs["nbpkg_sync"])

@test count("Dates", ptoml_contents()) == 0

Expand All @@ -202,6 +211,11 @@ import Malt
@test notebook.nbpkg_restart_recommended_msg !== nothing # recommend restart
@test notebook.nbpkg_restart_required_msg === nothing
@test notebook.nbpkg_install_time_ns === nothing # removing a package means that we lose our estimate
@test notebook.nbpkg_busy_packages == []
@test notebook.nbpkg_terminal_outputs["nbpkg_sync"] != ""
@test notebook.nbpkg_terminal_outputs["PlutoPkgTestD"] != ""
@test occursin("- PlutoPkgTestD", notebook.nbpkg_terminal_outputs["PlutoPkgTestD"])
@test occursin("- PlutoPkgTestD", notebook.nbpkg_terminal_outputs["nbpkg_sync"])

@test count("PlutoPkgTestD", ptoml_contents()) == 0

Expand Down

0 comments on commit b223265

Please sign in to comment.