# -*- coding: utf-8 -*-

import inspect
import os.path
import sys
from sphinx.application import Sphinx

# Build HTML documentation using sphinx
script = inspect.currentframe().f_code.co_filename
srcdir = os.path.dirname(script)
confdir = srcdir
outdir = os.path.join(srcdir, '_build')
doctreedir = os.path.join(outdir, '.doctrees')

sphinx = Sphinx(srcdir, confdir, outdir, doctreedir, 'html', {}, sys.stdout)

sources = [os.path.join(srcdir, doc + '.rst')
           for doc in sphinx.builder.get_outdated_docs()]
output = [os.path.join(outdir, doc + '.html')
          for doc in sphinx.builder.get_outdated_docs()]

def build_doc(target, source, env):
    sphinx.build(False, [])
    return sphinx.statuscode

env = Environment()
doc = env.Command(output, sources, build_doc)
env.Alias('doc', doc)

