Skip to content

Commit 6950747

Browse files
authored
Show Pkg logs in Process Status tab (#2498)
1 parent 18a6a0f commit 6950747

File tree

5 files changed

+71
-46
lines changed

5 files changed

+71
-46
lines changed

frontend/components/PkgTerminalView.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const TerminalViewAnsiUp = ({ value }) => {
1111
if (parent) parent.scrollTop = 1e5
1212
}, [node_ref.current, value])
1313

14-
return html`<pkg-terminal
15-
><div class="scroller"><pre ref=${node_ref} class="pkg-terminal"></pre></div
16-
></pkg-terminal>`
14+
return !!value
15+
? html`<pkg-terminal
16+
><div class="scroller"><pre ref=${node_ref} class="pkg-terminal"></pre></div
17+
></pkg-terminal>`
18+
: null
1719
}
1820

1921
export const PkgTerminalView = TerminalViewAnsiUp

frontend/components/ProcessTab.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { html, useEffect, useRef, useState } from "../imports/Preact.js"
33
import { cl } from "../common/ClassTable.js"
44
import { prettytime, useMillisSinceTruthy } from "./RunArea.js"
55
import { DiscreteProgressBar } from "./DiscreteProgressBar.js"
6+
import { PkgTerminalView } from "./PkgTerminalView.js"
67

78
/**
89
* @param {{
@@ -13,7 +14,7 @@ import { DiscreteProgressBar } from "./DiscreteProgressBar.js"
1314
export let ProcessTab = ({ notebook, my_clock_is_ahead_by }) => {
1415
return html`
1516
<section>
16-
<${StatusItem} status_tree=${notebook.status_tree} my_clock_is_ahead_by=${my_clock_is_ahead_by} path=${[]} />
17+
<${StatusItem} status_tree=${notebook.status_tree} path=${[]} my_clock_is_ahead_by=${my_clock_is_ahead_by} nbpkg=${notebook.nbpkg} />
1718
</section>
1819
`
1920
}
@@ -76,9 +77,10 @@ const to_ns = (x) => x * 1e9
7677
* status_tree: import("./Editor.js").StatusEntryData?,
7778
* path: string[],
7879
* my_clock_is_ahead_by: number,
80+
* nbpkg: import("./Editor.js").NotebookPkgData?,
7981
* }} props
8082
*/
81-
const StatusItem = ({ status_tree, path, my_clock_is_ahead_by }) => {
83+
const StatusItem = ({ status_tree, path, my_clock_is_ahead_by, nbpkg }) => {
8284
if (status_tree == null) return null
8385
const mystatus = path.reduce((entry, key) => entry.subtasks[key], status_tree)
8486
if (!mystatus) return null
@@ -129,7 +131,13 @@ const StatusItem = ({ status_tree, path, my_clock_is_ahead_by }) => {
129131
.map(([key, _subtask]) =>
130132
blocklist.includes(key)
131133
? null
132-
: html`<${StatusItem} key=${key} status_tree=${status_tree} my_clock_is_ahead_by=${my_clock_is_ahead_by} path=${[...path, key]} />`
134+
: html`<${StatusItem}
135+
key=${key}
136+
status_tree=${status_tree}
137+
my_clock_is_ahead_by=${my_clock_is_ahead_by}
138+
path=${[...path, key]}
139+
nbpkg=${nbpkg}
140+
/>`
133141
)
134142

135143
const render_child_progress = () => {
@@ -179,7 +187,7 @@ const StatusItem = ({ status_tree, path, my_clock_is_ahead_by }) => {
179187
<span class="status-name">${friendly_name(mystatus.name)}${inner_progress}</span>
180188
<span class="status-time">${finished ? prettytime(to_ns(end - start)) : busy ? prettytime(to_ns(busy_time)) : null}</span>
181189
</div>
182-
${inner}
190+
${inner}${is_open && mystatus.name === "pkg" ? html`<${PkgTerminalView} value=${nbpkg?.terminal_outputs?.nbpkg_sync} />` : undefined}
183191
</pl-status>`
184192
}
185193

frontend/editor.css

+32-25
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,12 @@ pluto-helpbox {
20402040
border-top-right-radius: 9px;
20412041
box-shadow: 0 0 11px 0px var(--helpbox-box-shadow-color);
20422042
}
2043+
pluto-helpbox > section {
2044+
height: 100%;
2045+
overflow: auto;
2046+
padding: 10px;
2047+
}
2048+
20432049
pluto-helpbox > header {
20442050
display: flex;
20452051
padding: 0.6em;
@@ -2273,54 +2279,49 @@ pluto-helpbox.hidden > section {
22732279
/* https://docs.julialang.org/en/v1/assets/themes/documenter-light.css */
22742280
/* see https://github.com/JuliaDocs/Documenter.jl for author information */
22752281

2276-
pluto-helpbox {
2282+
.helpbox-docs {
22772283
font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
22782284
line-height: 1.5;
22792285
font-size: 0.9rem;
22802286
}
2281-
pluto-helpbox pre,
2282-
pluto-helpbox code,
2283-
pluto-helpbox .cm-line {
2287+
.helpbox-docs pre,
2288+
.helpbox-docs code,
2289+
.helpbox-docs .cm-line {
22842290
/* from https://docs.julialang.org/en/v1/assets/themes/documenter-light.css */
2285-
font-family: "JuliaMono", "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono", "DejaVu Sans Mono", monospace;
2291+
font-family: "Roboto Mono", "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono", "DejaVu Sans Mono", monospace;
22862292
font-size: 0.95em;
22872293
line-height: initial;
22882294
}
2289-
pluto-helpbox pre code {
2295+
.helpbox-docs pre code {
22902296
font-size: 1em;
22912297
}
22922298

2293-
pluto-helpbox pre code.hljs {
2299+
.helpbox-docs pre code.hljs {
22942300
padding: 0;
22952301
}
22962302

2297-
pluto-helpbox code .cm-editor .cm-content {
2303+
.helpbox-docs code .cm-editor .cm-content {
22982304
padding: 0px;
22992305
}
23002306

2301-
pluto-helpbox img {
2307+
.helpbox-docs img {
23022308
max-width: 100%;
23032309
}
23042310

2305-
pluto-helpbox > section {
2306-
height: 100%;
2307-
overflow: auto;
2308-
padding: 10px;
2309-
}
2310-
pluto-helpbox > section h1,
2311-
pluto-helpbox > section h2,
2312-
pluto-helpbox > section h3,
2313-
pluto-helpbox > section h4,
2314-
pluto-helpbox > section h5,
2315-
pluto-helpbox > section h6 {
2311+
.helpbox-docs > section h1,
2312+
.helpbox-docs > section h2,
2313+
.helpbox-docs > section h3,
2314+
.helpbox-docs > section h4,
2315+
.helpbox-docs > section h5,
2316+
.helpbox-docs > section h6 {
23162317
font-family: inherit;
23172318
border-bottom: none;
23182319
font-size: 1rem;
23192320
}
2320-
pluto-helpbox > section h1 {
2321+
.helpbox-docs > section h1 {
23212322
font-size: 1.3rem;
23222323
}
2323-
pluto-helpbox > section pre {
2324+
.helpbox-docs > section pre {
23242325
padding: 0.7rem 0.5rem;
23252326
-webkit-overflow-scrolling: touch;
23262327
overflow-x: auto;
@@ -2330,11 +2331,11 @@ pluto-helpbox > section pre {
23302331
white-space: pre;
23312332
word-wrap: normal;
23322333
}
2333-
/* pluto-helpbox > section code {
2334+
/* .helpbox-docs > section code {
23342335
background-color: whitesmoke;
23352336
padding: 0.1em;
23362337
} */
2337-
pluto-helpbox > section hr {
2338+
.helpbox-docs > section hr {
23382339
border: none;
23392340
border-top: 3px solid var(--rule-color);
23402341
}
@@ -2379,11 +2380,13 @@ pluto-helpbox > section hr {
23792380
pl-status {
23802381
--status-color: var(--process-undefined);
23812382
font-family: var(--system-ui-font-stack);
2383+
font-size: 0.9rem;
23822384
display: flex;
23832385
flex-direction: column;
23842386
border-radius: 0.2em;
23852387
/* margin: 0.3em; */
2386-
margin-left: 0.7em;
2388+
--indent: 0.7rem;
2389+
margin-left: var(--indent);
23872390
border-left: 3px solid transparent;
23882391
margin-top: 0.4em;
23892392
overflow: hidden;
@@ -2522,6 +2525,10 @@ pl-status .status-time {
25222525
gap: 0.5px;
25232526
}
25242527

2528+
pl-status pkg-terminal {
2529+
margin-left: var(--indent);
2530+
}
2531+
25252532
/* FOOTER */
25262533

25272534
footer {

src/packages/Packages.jl

+21-14
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,34 @@ function sync_nbpkg_core(
101101

102102
removed = setdiff(old_packages, new_packages)
103103
added = setdiff(new_packages, old_packages)
104+
can_skip = isempty(removed) && isempty(added) && notebook.nbpkg_ctx_instantiated
104105

105106
iolistener = let
106107
busy_packages = notebook.nbpkg_ctx_instantiated ? added : new_packages
107-
IOListener(callback=(s -> on_terminal_output(busy_packages, s)))
108+
report_to = ["nbpkg_sync", busy_packages...]
109+
IOListener(callback=(s -> on_terminal_output(report_to, s)))
108110
end
109111
cleanup[] = () -> stoplistening(iolistener)
110-
111-
# We remember which Pkg.Types.PreserveLevel was used. If it's too low, we will recommend/require a notebook restart later.
112-
local used_tier = Pkg.PRESERVE_ALL
113-
114-
if !isready(pkg_token)
115-
println(iolistener.buffer, "Waiting for other notebooks to finish Pkg operations...")
116-
trigger(iolistener)
117-
end
118112

119-
can_skip = isempty(removed) && isempty(added) && notebook.nbpkg_ctx_instantiated
113+
120114

121115
Status.report_business_finished!(pkg_status, :analysis)
122116

117+
# We remember which Pkg.Types.PreserveLevel was used. If it's too low, we will recommend/require a notebook restart later.
118+
local used_tier = Pkg.PRESERVE_ALL
123119
if !can_skip
120+
# We have a global lock, `pkg_token`, on Pluto-managed Pkg operations, which is shared between all notebooks. If this lock is not ready right now then that means that we are going to wait at the `withtoken(pkg_token)` line below.
121+
# We want to report that we are waiting, with a best guess of why.
124122
wait_business = if !isready(pkg_token)
123+
reg = !PkgCompat._updated_registries_compat[]
124+
125+
# Print something in the terminal logs
126+
println(iolistener.buffer, "Waiting for $(reg ? "the package registry to update" : "other notebooks to finish Pkg operations")...")
127+
trigger(iolistener) # manual trigger because we did not start listening yet
128+
129+
# Create a business item
125130
Status.report_business_started!(pkg_status,
126-
!PkgCompat._updated_registries_compat[] ?
127-
:registry_update :
128-
:waiting_for_others
131+
reg ? :registry_update : :waiting_for_others
129132
)
130133
end
131134

@@ -206,6 +209,8 @@ function sync_nbpkg_core(
206209
Status.report_business_started!(pkg_status, :add)
207210
start_time = time_ns()
208211
with_io_setup(notebook, iolistener) do
212+
println(iolistener.buffer, "\nAdding packages...")
213+
209214
# We temporarily clear the "semver-compatible" [deps] entries, because Pkg already respects semver, unless it doesn't, in which case we don't want to force it.
210215
PkgCompat.clear_auto_compat_entries!(notebook.nbpkg_ctx)
211216

@@ -380,8 +385,8 @@ end
380385

381386
function instantiate(notebook::Notebook, iolistener::IOListener)
382387
start_time = time_ns()
383-
startlistening(iolistener)
384388
with_io_setup(notebook, iolistener) do
389+
println(iolistener.buffer, "\nInstantiating...")
385390
@debug "PlutoPkg: Instantiating" notebook.path
386391

387392
# update registries if this is the first time
@@ -411,6 +416,7 @@ end
411416
function resolve(notebook::Notebook, iolistener::IOListener)
412417
startlistening(iolistener)
413418
with_io_setup(notebook, iolistener) do
419+
println(iolistener.buffer, "\nResolving...")
414420
@debug "PlutoPkg: Instantiating" notebook.path
415421
Pkg.resolve(notebook.nbpkg_ctx)
416422
end
@@ -488,6 +494,7 @@ function update_nbpkg_core(
488494

489495
iolistener = let
490496
# we don't know which packages will be updated, so we send terminal output to all installed packages
497+
report_to = ["nbpkg_update", old_packages...]
491498
IOListener(callback=(s -> on_terminal_output(old_packages, s)))
492499
end
493500
cleanup[] = () -> stoplistening(iolistener)

src/webserver/Status.jl

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Base.@kwdef mutable struct Business
66
started_at::Union{Nothing,Float64}=nothing
77
finished_at::Union{Nothing,Float64}=nothing
88
subtasks::Dict{Symbol,Business}=Dict{Symbol,Business}()
9+
910
update_listener_ref::Ref{Union{Nothing,Function}}=Ref{Union{Nothing,Function}}(nothing)
1011
lock::Threads.SpinLock=Threads.SpinLock()
1112
end

0 commit comments

Comments
 (0)