question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide means to hide stdout and/or stderr

See original GitHub issue

Is your feature request related to a problem? Please describe. It would be desirable to sometimes hide stdout and/or stderr for a final polished report.

For example consider the following code:

import sys
import warnings
warnings.simplefilter(action='ignore', category=Warning)
from plotnine import ggplot, aes, geom_bar
from plotnine.data import mpg
import pandas as pd
# some pseudo-warning from pandas
pd.reset_option('all')

# stderr
sys.stderr.write("This should go away")

print("I guess this will go away as well")
#stuff printed from plots
p = ggplot(mpg) + \
            geom_bar(aes(x="class"))
display(p);

This will look like this in jupyterbook:

image

All elements with an arrow should not be present in the final report.

Using nbconvert it is easy to write a jinja2 template that gets rid of stdout and stderr so, the final result looks like this:

image

Describe the solution you’d like I would like to have a way to selectively hide stdout and/or stderr from the final report. For example set the cell metata to remove_stdout and/or remove_stderr in a similar way as remove_input.

Describe alternatives you’ve considered I have no idea how to handle this right now, but I would love to hear suggestions.

Additional context The example is minimal for reproducibility, but it illustrates what I would like to remove, the reasons why to remove these from the final report:

stdout:

  1. as shown in the example some plotting systems (plotnine in this case) produce a printing of the repr of the class as side effect when showing the plot. In this particular case there is the option to use p.draw(); that would hide it, but this doesn’t work together with ipywidgets tabs, so there is the need to hide these things.
  2. Maybe I would like to have some printings in the notebook as sanity check etc, but leave those out from the final report.
  3. Some libraries write warnings to stdout and there is no way to get rid of them, look at the pandas example in this case. Again this should not be included in the report.

stderr:

  1. I don’t have an easy to reproduce example of this, but some libraries do emit warnings in stderr that you cannot remove by filtering warnings out (sqlalchemy-redshift seems to be one of those in my hands right now, spits lots of strange warnings and I cannot get rid of them). So there is the need to hide stderr sometimes as well.

attached: jupyter notebook, html folder produced by jupyterbook, nbconvert template that removes stdout and stderr, html produced by nbconvert.

Archive.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ofajardocommented, Jun 15, 2020

I may be a bit naive, but looking at what you can do with nbconvert, I think there is not much more (useful) to remove or hide besides what jupyter-book already offers + stdout and stderr

1reaction
ofajardocommented, Jun 15, 2020

Right, sometimes it is not possible: for example with the plotnine example, if you get sys.stdout and direct to something else, and you want to combine with Ipywidgets to produce tabs, then you also loose the plot itself. Stderr maybe is easier, but ideally one would like to show it in the notebook, so that another developer would see the warnings, but hide it from the final report, as non coders consuming reports are not interested in warnings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hiding stderr or stdout | mindspill.net
To hide the standard error (stderr) or standard output (stdout) messages produced by a program, redirect them to /dev/null, a special file ...
Read more >
Hide stderr and pipe stdout in tcsh - linux - Stack Overflow
How can I hide stderr but use stdout in csh script? The problem is that if the file does not exist an error...
Read more >
suppress stderr messages in a bash script
This redirects the stderr for the script to /dev/null from this statement until it is changed back. Clumsy ways of changing it back...
Read more >
Hide the output of a shell command only on success?
Is there any builtin facility or command which by default hides the output but on error dumps all the accumulated output?
Read more >
rubocop/cli_spec.rb at master - GitHub
A Ruby static code analyzer and formatter, based on the community Ruby style guide. - rubocop/cli_spec.rb at master · rubocop/rubocop.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found