chiark / gitweb /
m.sphinx: dirty hack to make this file directly runnable.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 17:44:53 +0000 (19:44 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 20:10:14 +0000 (22:10 +0200)
Because having to do

    python -m m.sphinx somefile.inv

is too unintuitive to remember.

plugins/m/sphinx.py

index f094ac2e6422544640fcca1a80ba5ff57ea5c2b8..61d830649488e3add8f61caef04f40846504e778 100755 (executable)
 #   DEALINGS IN THE SOFTWARE.
 #
 
+import os
+import sys
+
+# So it's possible to do `./plugins/m/sphinx.py somefile.inv` without it all
+# blowing up on the earliest `import math` as there's a math.py file in this
+# directory. Alternatively, doing `python -m m.sphinx` would work too, but who
+# would remember to do that.
+if __name__ == '__main__': # pragma: no cover
+    sys.path.remove(os.path.realpath(os.path.dirname(__file__)))
+
 import argparse
 import logging
-import os
 import re
-import sys
 from types import SimpleNamespace as Empty
 from typing import Dict, List, Optional
 from urllib.parse import urljoin