Last active
April 27, 2016 11:40
-
-
Save jaywhy13/9641fe0206f1d794d7f2959bfa74fcb8 to your computer and use it in GitHub Desktop.
Python script to compile Sphinx documentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import logging | |
import os | |
from watchdog.observers import Observer | |
from watchdog.observers.polling import PollingObserver | |
from watchdog.events import PatternMatchingEventHandler | |
import subprocess | |
class DocsCompiler(PatternMatchingEventHandler): | |
""" Compile docs each a *.rst file is changed | |
""" | |
def dispatch(self, event): | |
if event.src_path.endswith(".rst"): | |
try: | |
print("======================================================") | |
print("Recompiling docs: \n\t%s changed" % event.src_path) | |
print("======================================================") | |
p = subprocess.Popen(["make", "html"], cwd="/code/docs/") | |
p.wait() | |
except Exception as e: | |
pass | |
if __name__ == "__main__": | |
logging.basicConfig(level=logging.INFO, | |
format='%(asctime)s - %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S') | |
path = sys.argv[1] if len(sys.argv) > 1 else '.' | |
event_handler = DocsCompiler(patterns="*.rst", ignore_patterns="_build/*") | |
observer = PollingObserver() | |
observer.schedule(event_handler, path, recursive=True) | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment