I have a silly problem:
We’re using a few packages that insist on printing their banners upon importing (consider this as something beyond me:). This results in a “barrage of banners” situation.
I tried to redirect output as follows:
The reason why is that this code is not run when the module is loaded from a precompiled file. The way precompilation of packages work is to deserialize the state of the module to a file during precompilation and when loading, the state is simply deserialized and then the __init__ function of the module is run. No top-level code is run when the module is loaded.
I’m not really sure how to “hook” into the __init__ function of dependent packages though.
Unconditional printing of banners and such on package load is really user-hostile behavior…
If you could spare a moment, I came up with the following solution hack to to detect if package has been imported from other module (and then suppress banner) or from Main/module inside Main (and display it then).
I think Nemo banner is conditional https://github.com/Nemocas/Nemo.jl/issues/817 Nemo banner
But I have no idea how to implement this in the __init__ function.
I would also like to remove exactly those two banners, did you, @abulak, succed with __is_root_module()?
How do you use it?
The same trick as in __is_root_module is precisely what is used in Nemo to not print the banner when it’s loaded from a hardcoded list of packages, I don’t think it’s possible to extend this list. As mentioned in the issue you linked to, you could set the environment variable ENV["NEMO_PRINT_BANNER"] = false (but it’s not documented and might not be supported in the future).
(The environment is then only set during precompilation—this is when top-level code in the module is executed—and will no longer be set when the user imports the module at a later time.)