Skip to content

Commit 94720bd

Browse files
committed
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.
1 parent 65ed6c3 commit 94720bd

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

properdocs/__main__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212

1313
import click
1414

15-
from properdocs import (
16-
__version__,
17-
config,
18-
replacement, # noqa: F401
19-
utils,
20-
)
15+
from properdocs import __version__, config, replacement, utils
2116

2217
if sys.platform.startswith("win"):
2318
try:
@@ -27,6 +22,9 @@
2722
else:
2823
colorama.init()
2924

25+
replacement.setup()
26+
27+
3028
log = logging.getLogger(__name__)
3129

3230

properdocs/replacement.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
"""After this file is imported, all mkdocs.* imports get redirected to properdocs.* imports."""
1+
"""After calling setup(), all mkdocs.* imports get redirected to properdocs.* imports."""
22

33
import importlib.abc
44
import importlib.util
5+
import os
56
import sys
67

78

@@ -37,6 +38,11 @@ def find_spec(self, fullname, path, target=None):
3738
return None
3839

3940

40-
sys.meta_path.insert(0, _AliasFinder())
41-
# Plus, handle the topmost module directly and without waiting for it to be requested.
42-
sys.modules['mkdocs'] = sys.modules['properdocs']
41+
def setup():
42+
sys.meta_path.insert(0, _AliasFinder())
43+
# Plus, handle the topmost module directly and without waiting for it to be requested.
44+
sys.modules['mkdocs'] = sys.modules['properdocs']
45+
46+
# Prevent warnings from the theme that already uses this environment variable.
47+
# That warning does not apply to ProperDocs.
48+
os.environ['NO_MKDOCS_2_WARNING'] = 'true'

0 commit comments

Comments
 (0)