From 1daf35b1a8999ff8e252a58f31a2a6f9f4aa5cf4 Mon Sep 17 00:00:00 2001 From: Markus Kuhn Date: Sat, 12 Aug 2023 18:46:17 +0100 Subject: [PATCH] Display banner from Pluto.__init__, not during precompile Display banner only when `$JULIA_DEPOT_PATH/pluto_notebooks/` is created, and create that folder when the module initializes. This preserves the fact that the banner is only displayed once, while it now no longer displays it when the package is compiled. Compile-time display became problematic as that is counted by `Pkg` as a warning, and users might therefore think something went wrong. Note that this now creates `$JULIA_DEPOT_PATH/pluto_notebooks/` much earlier, whereas previously that folder was only created when the user saved a notebook there. fixes #548 --- src/Pluto.jl | 26 ++++++++++++++++++-------- src/notebook/path helpers.jl | 5 +++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Pluto.jl b/src/Pluto.jl index 2cb0eee2ad..943bf18b3e 100644 --- a/src/Pluto.jl +++ b/src/Pluto.jl @@ -99,16 +99,26 @@ export activate_notebook_environment include("./precompile.jl") -if get(ENV, "JULIA_PLUTO_SHOW_BANNER", "1") != "0" && get(ENV, "CI", "🍄") != "true" -@info """\n - Welcome to Pluto $(PLUTO_VERSION_STR) 🎈 - Start a notebook server using: +function print_banner() + if (get(ENV, "JULIA_PLUTO_SHOW_BANNER", "1") != "0" && + get(ENV, "CI", "🍄") != "true" && isinteractive()) + @info """ - julia> Pluto.run() + Welcome to Pluto $(PLUTO_VERSION_STR) 🎈 + Start a notebook server using: - Have a look at the FAQ: - https://github.com/fonsp/Pluto.jl/wiki -\n""" + julia> Pluto.run() + + Have a look at the FAQ: + https://github.com/fonsp/Pluto.jl/wiki + + """ + end +end + +function __init__() + # print banner only once, if there isn't yet a notebooks directory + new_notebooks_directory(mkdir_callback = print_banner) end end diff --git a/src/notebook/path helpers.jl b/src/notebook/path helpers.jl index 9a3a387931..08fc98458e 100644 --- a/src/notebook/path helpers.jl +++ b/src/notebook/path helpers.jl @@ -90,7 +90,7 @@ function cutename() titlecase(rand(adjectives)) * " " * rand(nouns) end -function new_notebooks_directory() +function new_notebooks_directory(;mkdir_callback = nothing) try path = get( ENV, @@ -98,6 +98,7 @@ function new_notebooks_directory() joinpath(first(DEPOT_PATH), "pluto_notebooks") ) if !isdir(path) + mkdir_callback === nothing || mkdir_callback() mkdir(path) end path @@ -206,4 +207,4 @@ function wait_until_file_unchanged(filename::String, timeout::Real, last_content sleep(timeout) wait_until_file_unchanged(filename, timeout, new_contents) end -end \ No newline at end of file +end