From: Vladimír Vondruš Date: Tue, 10 Sep 2019 17:44:53 +0000 (+0200) Subject: m.sphinx: dirty hack to make this file directly runnable. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2975998e41cc3ce22d91f9f3d695e99912624121;p=blog.git m.sphinx: dirty hack to make this file directly runnable. Because having to do python -m m.sphinx somefile.inv is too unintuitive to remember. --- diff --git a/plugins/m/sphinx.py b/plugins/m/sphinx.py index f094ac2e..61d83064 100755 --- a/plugins/m/sphinx.py +++ b/plugins/m/sphinx.py @@ -24,11 +24,19 @@ # 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