From b22326574d53f8b39bb7880a0ba69bdabac222b3 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Thu, 23 May 2024 14:23:24 +0200 Subject: [PATCH] Capture IO from Pkg.rm (#2924) --- src/packages/Packages.jl | 12 +++++++----- test/packages/Basic.jl | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/packages/Packages.jl b/src/packages/Packages.jl index 647def9ebd..4fb1192eda 100644 --- a/src/packages/Packages.jl +++ b/src/packages/Packages.jl @@ -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 @@ -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. diff --git a/test/packages/Basic.jl b/test/packages/Basic.jl index c0af5b6492..3675801d7e 100644 --- a/test/packages/Basic.jl +++ b/test/packages/Basic.jl @@ -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 @@ -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 @@ -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