Skip to content

Instantly share code, notes, and snippets.

@moqada
Created August 21, 2013 07:03
Show Gist options
  • Select an option

  • Save moqada/6291156 to your computer and use it in GitHub Desktop.

Select an option

Save moqada/6291156 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
*.rstなファイルを監視してSphinxをbuildするタスク
@see http://kshigeru.blogspot.jp/2013/02/sphinx-livereload.html
"""
import logging
from os import path
from subprocess import Popen, PIPE
from livereload.task import Task
def sphinx():
build_dir = '_build'
argv = [
'sphinx-build', '-q', '-b', 'html', '-d',
path.join(build_dir, 'doctrees'), '.',
path.join(build_dir, 'html')
]
logging.debug('Start to build into %s', build_dir)
p = Popen(argv, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
if stderr:
logging.error(stderr)
logging.debug('Finish to build: %s', stdout)
# 階層が違うとマッチしてくれないっぽい
Task.add('*.rst', sphinx)
Task.add('**/*.rst', sphinx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment