Skip to content

Commit

Permalink
fix: Hook properly to MkDocs logging
Browse files Browse the repository at this point in the history
With strict mode (`-s` option for build and serve
commands of MkDocs), the build should fail if any
warning has been issued.

This was not the case. This commit adds the
`warning_filter` counter declared and used by
MkDocs to loggers in all modules.

Reference: #86.
  • Loading branch information
pawamoy committed Apr 14, 2020
1 parent 5f8cc71 commit b23daed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
option_x: etc
```
"""

import logging
import re
from typing import Tuple
from xml.etree.ElementTree import XML, Element, ParseError # nosec: we choose to trust the XML input
Expand All @@ -34,10 +34,13 @@
from markdown.blockprocessors import BlockProcessor
from markdown.extensions import Extension
from markdown.util import AtomicString
from mkdocs.utils import log
from mkdocs.utils import warning_filter

from .handlers import CollectionError, get_handler

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


def atomic_brute_cast(tree: Element) -> Element:
"""
Expand Down
6 changes: 5 additions & 1 deletion src/mkdocstrings/handlers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
"""

import json
import logging
import os
from subprocess import PIPE, Popen # nosec: what other option, more secure that PIPE do we have? sockets?
from typing import Optional

from markdown import Markdown
from mkdocs.utils import log
from mkdocs.utils import warning_filter

from . import BaseCollector, BaseHandler, BaseRenderer, CollectionError, DataType

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


class PythonRenderer(BaseRenderer):
"""
Expand Down
5 changes: 4 additions & 1 deletion src/mkdocstrings/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@
from mkdocs.structure.files import Files
from mkdocs.structure.pages import Page
from mkdocs.structure.toc import AnchorLink
from mkdocs.utils import log
from mkdocs.utils import warning_filter

from .extension import MkdocstringsExtension
from .handlers import teardown

log = logging.getLogger(__name__)
log.addFilter(warning_filter)

SELECTION_OPTS_KEY: str = "selection"
"""The name of the selection parameter in YAML configuration blocks."""
RENDERING_OPTS_KEY: str = "rendering"
Expand Down

0 comments on commit b23daed

Please sign in to comment.