From 94720bdcfc7696922da392e999b79f9eaf7852a5 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Tue, 17 Mar 2026 01:20:56 +0100 Subject: [PATCH] Suppress external warnings about mkdocs also when running as properdocs The warning from mkdocs-material is already being suppressed for the mkdocs executable when at least 1 plugin participates. But it is also supposed to be suppressed when running `properdocs`! This was missed. Also rework the setup to not rely on an unused import but instead be explicit. --- properdocs/__main__.py | 10 ++++------ properdocs/replacement.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/properdocs/__main__.py b/properdocs/__main__.py index 8d395af3..310fd119 100644 --- a/properdocs/__main__.py +++ b/properdocs/__main__.py @@ -12,12 +12,7 @@ import click -from properdocs import ( - __version__, - config, - replacement, # noqa: F401 - utils, -) +from properdocs import __version__, config, replacement, utils if sys.platform.startswith("win"): try: @@ -27,6 +22,9 @@ else: colorama.init() +replacement.setup() + + log = logging.getLogger(__name__) diff --git a/properdocs/replacement.py b/properdocs/replacement.py index ef68c6b3..e0edff05 100644 --- a/properdocs/replacement.py +++ b/properdocs/replacement.py @@ -1,7 +1,8 @@ -"""After this file is imported, all mkdocs.* imports get redirected to properdocs.* imports.""" +"""After calling setup(), all mkdocs.* imports get redirected to properdocs.* imports.""" import importlib.abc import importlib.util +import os import sys @@ -37,6 +38,11 @@ def find_spec(self, fullname, path, target=None): return None -sys.meta_path.insert(0, _AliasFinder()) -# Plus, handle the topmost module directly and without waiting for it to be requested. -sys.modules['mkdocs'] = sys.modules['properdocs'] +def setup(): + sys.meta_path.insert(0, _AliasFinder()) + # Plus, handle the topmost module directly and without waiting for it to be requested. + sys.modules['mkdocs'] = sys.modules['properdocs'] + + # Prevent warnings from the theme that already uses this environment variable. + # That warning does not apply to ProperDocs. + os.environ['NO_MKDOCS_2_WARNING'] = 'true'