jupyter/papyri

Extract / Make log filtering configurable.

Carreau opened this issue · 0 comments

Currently matplotlib generate logs while building the docs that pollute the output.

We need to find a way to silence and/or capture those.

Here is the current code:

papyri/papyri/gen.py

Lines 985 to 1007 in 1740a4a

class MF(logging.Filter):
"""
This is a matplotlib filter to temporarily silence a bunch of warning
messages that are emitted if font are not found
"""
def filter(self, record):
if "Generic family" in record.msg:
return 0
if "found for the serif fontfamily" in record.msg:
return 0
if "not found. Falling back to" in record.msg:
return 0
if "Substituting symbol" in record.msg:
return 0
return 1
mlog = logging.getLogger("matplotlib.font_manager")
mlog.addFilter(MF("serif"))
mplog = logging.getLogger("matplotlib.mathtext")
mplog.addFilter(MF("serif"))

I'm thinking it would be great to find a way to filter from the configuration that looks like pytest filterwarnings, with some customization as of course we dont' have a warning class but a log level...

[tool.pytest.ini_options]
filterwarnings = [
    "ignore::INFO",
    # note the use of single quote below to denote "raw" strings in TOML
    'error:function ham\(\) is deprecated:DEBUG',
]

If running example could also capture the logs, and insert them as output that would be a great addition.