blob: 09f67f88140807d5fcb731787851d6e7a0e6e7ef [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001#!/usr/bin/env python
2# encoding: utf-8
3# Hans-Martin von Gaudecker, 2012
4
5import os
6from waflib import Node, Task, TaskGen, Errors, Logs, Build, Utils
7
8class sphinx_build(Task.Task):
9 color = 'BLUE'
10 run_str = '${SPHINX_BUILD} -q -b ${BUILDERNAME} -d ${DOCTREEDIR} ${SRCDIR} ${OUTDIR}'
11
12 def __str__(self):
13 env = self.env
14 src_str = ' '.join([a.nice_path()for a in self.inputs])
15 tgt_str = ' '.join([a.nice_path()for a in self.outputs])
16 if self.outputs: sep = ' -> '
17 else: sep = ''
18 return'%s [%s]: %s%s%s\n'%(self.__class__.__name__.replace('_task',''),
19 self.env['BUILDERNAME'], src_str, sep, tgt_str)
20
21@TaskGen.extension('.py', '.rst')
22def sig_hook(self, node):
23 node.sig=Utils.h_file(node.abspath())
24
25@TaskGen.feature("sphinx")
26@TaskGen.before_method("process_source")
27def apply_sphinx(self):
28 """Set up the task generator with a Sphinx instance and create a task."""
29
30 inputs = []
31 for i in Utils.to_list(self.source):
32 if not isinstance(i, Node.Node):
33 node = self.path.find_node(node)
34 else:
35 node = i
36 if not node:
37 raise ValueError('[%s] file not found' % i)
38 inputs.append(node)
39
40 task = self.create_task('sphinx_build', inputs)
41
42 conf = self.path.find_node(self.config)
43 task.inputs.append(conf)
44
45 confdir = conf.parent.abspath()
46 buildername = getattr(self, "builder", "html")
47 srcdir = getattr(self, "srcdir", confdir)
48 outdir = self.path.find_or_declare(getattr(self, "outdir", buildername)).get_bld()
49 doctreedir = getattr(self, "doctreedir", os.path.join(outdir.abspath(), ".doctrees"))
50
51 task.env['BUILDERNAME'] = buildername
52 task.env['SRCDIR'] = srcdir
53 task.env['DOCTREEDIR'] = doctreedir
54 task.env['OUTDIR'] = outdir.abspath()
55
56 import imp
57 confData = imp.load_source('sphinx_conf', conf.abspath())
58
59 if buildername == "man":
60 for i in confData.man_pages:
61 target = outdir.find_or_declare('%s.%d' % (i[1], i[4]))
62 task.outputs.append(target)
63
64 if self.install_path:
65 self.bld.install_files("%s/man%d/" % (self.install_path, i[4]), target)
66 else:
67 task.outputs.append(outdir)
68
69def configure(conf):
70 conf.find_program('sphinx-build', var='SPHINX_BUILD', mandatory=False)
71
72# sphinx docs
73from waflib.Build import BuildContext
74class sphinx(BuildContext):
75 cmd = "sphinx"
76 fun = "sphinx"