Skip to content

Commit 9204eb6

Browse files
Merge pull request #3809 from pawamoy/warnings-control
Allow controlling Python warnings with `python -W` and `PYTHONWARNINGS` again
2 parents a16d60f + e9d0c5c commit 9204eb6

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

mkdocs/__main__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
4646

4747

4848
def _enable_warnings():
49-
from mkdocs.commands import build
49+
# When `python -W...` or `PYTHONWARNINGS` are used, `sys.warnoptions` is set.
50+
# In that case, we skip warnings configuration since
51+
# we don't want to overwrite the user configuration.
52+
if not sys.warnoptions:
53+
from mkdocs.commands import build
5054

51-
build.log.addFilter(utils.DuplicateFilter())
55+
build.log.addFilter(utils.DuplicateFilter())
5256

53-
warnings.simplefilter('module', DeprecationWarning)
54-
warnings.showwarning = _showwarning
57+
warnings.simplefilter('module', DeprecationWarning)
58+
warnings.showwarning = _showwarning
5559

5660

5761
class ColorFormatter(logging.Formatter):

0 commit comments

Comments
 (0)