Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move welcome message to end of code loading #389

Merged
merged 1 commit into from
Sep 9, 2020

Conversation

IanButterworth
Copy link
Contributor

I noticed that for me, the welcome message appears well-before code loading has finished and the repl is ready. This might make for nicer UX?

@fonsp
Copy link
Owner

fonsp commented Sep 8, 2020

Right now it only prints it once, when Pluto is precompiling, but not when you launch it for the second time. It this is nice (accidental) feature.

Is it the same with __init__?

@IanButterworth
Copy link
Contributor Author

Ah, no. With this it would print each time (I assumed that was what was wanted)

Perhaps the @info could just be moved to the end of the include statements?

@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

Oh yeah that would be perfect! Good idea

@IanButterworth IanButterworth changed the title Move welcome message to __init__() Move welcome message to end of code loading Sep 9, 2020
@IanButterworth
Copy link
Contributor Author

@fonsp updated! 👍

@fonsp fonsp merged commit 2f060dc into fonsp:master Sep 9, 2020
@IanButterworth IanButterworth deleted the patch-2 branch September 9, 2020 12:05
@IanButterworth
Copy link
Contributor Author

I just realized that if the user precompiles via Pkg.precompile() or pkg> precompile, then this message will print during that process, which doesn't make sense, and then won't print again.
I think it needs to be moved into __init__(), but I'm not sure how to make it print only the first time after compilation.

@fonsp
Copy link
Owner

fonsp commented Sep 15, 2020

This is fine, it's only there to say hello and make the software seem less intimidating, if you are precompiling then you're probably comfortable enough to do without the message.

@kalmarek
Copy link

it makes sense to print banner in interactive mode (you may add isinteractive() to the boolean check).
tbh. I don't think it's great idea to display welcome messages. I couldn't find a way to circumvent these as well, despite efforts:
https://discourse.julialang.org/t/redirecting-stdout-to-avoid-banners-while-import-ing/37633/8

any new ideas are welcome though!

@fonsp
Copy link
Owner

fonsp commented Sep 16, 2020

I tried isinteractive() but it is always false inside package code, it can also give true when called from an interactive env

@kalmarek
Copy link

not sure what do you mean by "always false inside package code"?
it will certainly be true if you start REPL, or run a script with julia -i script.jl, no matter whether inside a module or not

@fonsp
Copy link
Owner

fonsp commented Sep 17, 2020

Try it out yourself: make a package that prints isinteractive(), and load it using import

@IanButterworth
Copy link
Contributor Author

From within __init__() or just directly in the module?

@kalmarek
Copy link

@fonsp this is what I get:

module MyPackage

__init__() = @show isinteractive()

end
$ julia --project # starting repl
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.1 (2020-08-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using MyPackage
[ Info: Precompiling MyPackage [c2604015-7b3d-4a30-8a26-9074551ec60a]
isinteractive() = true
$ julia --project -e "using MyPackage" # just executing a script
isinteractive() = false

$ julia --project -i -e "using KnuthBendix" # executing in interactive mode
isinteractive() = true
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.1 (2020-08-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> 

how did you do?

@kalmarek
Copy link

kalmarek commented Sep 17, 2020

I guess you tried to store the value in a variable ;) then indeed it's assigned during precompilation, where isinteractive()== false and never changed later. e.g.

module MyModule
    using Dates
    const date_loaded = now()
    get_date_loaded() = date_loaded
end

precompilation of this package will fix date_loaded to the time and date when the package was precompiled, not, when it's loaded ;)


EDIT: I guess it's all better explained here: https://docs.julialang.org/en/v1/manual/modules/#Module-initialization-and-precompilation than what I did ;)

@fonsp
Copy link
Owner

fonsp commented Sep 17, 2020

Oh that explains it, thanks!

But still, I am happy with the current accidental behaviour.

@fonsp fonsp mentioned this pull request Oct 8, 2020
@Moelf Moelf mentioned this pull request Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants