Skip to content

Commit bffbcf5

Browse files
committed
Add a nagging message when "properdocs" is imported but the executable is "mkdocs"
Plugin authors can join in on this message by simply importing our special module.
1 parent 2298918 commit bffbcf5

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

properdocs/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33

44
# For acceptable version formats, see https://www.python.org/dev/peps/pep-0440/
55
__version__ = '1.6.1'
6+
7+
8+
from . import replacement_warning
9+
10+
replacement_warning.setup()

properdocs/replacement_warning.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import os.path
3+
import sys
4+
5+
6+
def _is_running_from_mkdocs():
7+
if 'mkdocs' not in sys.modules:
8+
return False
9+
10+
dir, name = os.path.split(sys.argv[0])
11+
if name == 'mkdocs':
12+
return True
13+
elif name == '__main__.py':
14+
dir, name = os.path.split(dir)
15+
if name == 'mkdocs':
16+
return True
17+
return False
18+
19+
20+
_WARNING_MESSAGE = '''
21+
WARNING: TODO (Some concerning message)
22+
23+
We have published a forked project that is an instant drop-in replacement of "mkdocs", supports all its plugins and currently works exactly the same other than bug fixes that we're actively working on.
24+
Please visit https://github.com/properdocs for more details.
25+
26+
Please replace the "mkdocs" dependency with "properdocs" (within `pip install`). Note that the plugins should stay under their previous name, they will simply keep working).
27+
And most importantly, replace all command line invocations of `mkdocs` with `properdocs`.
28+
29+
Doing this will also get rid of this warning.
30+
(This warning was initiated by one of the plugins that you depend on.)
31+
'''
32+
33+
34+
def setup():
35+
if _is_running_from_mkdocs():
36+
# Silence this warning with NO_MKDOCS_2_WARNING=true
37+
if os.environ.get("NO_MKDOCS_2_WARNING", "").lower() != "true":
38+
message = _WARNING_MESSAGE
39+
try:
40+
import click
41+
42+
message = click.style(message, fg='red')
43+
except ImportError:
44+
pass
45+
print(message, file=sys.stderr) # noqa: T201
46+
47+
# Prevent warnings from the theme that already uses this environment variable.
48+
os.environ["NO_MKDOCS_2_WARNING"] = "true"

0 commit comments

Comments
 (0)