Skip to content

Commit

Permalink
Display banner from Pluto.__init__, not during precompile
Browse files Browse the repository at this point in the history
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 fonsp#548
  • Loading branch information
mgkuhn committed Aug 12, 2023
1 parent 1d2c303 commit 1daf35b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/Pluto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/notebook/path helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ function cutename()
titlecase(rand(adjectives)) * " " * rand(nouns)
end

function new_notebooks_directory()
function new_notebooks_directory(;mkdir_callback = nothing)
try
path = get(
ENV,
"JULIA_PLUTO_NEW_NOTEBOOKS_DIR",
joinpath(first(DEPOT_PATH), "pluto_notebooks")
)
if !isdir(path)
mkdir_callback === nothing || mkdir_callback()
mkdir(path)
end
path
Expand Down Expand Up @@ -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
end

0 comments on commit 1daf35b

Please sign in to comment.