1 | # |
---|
2 | # Support for Latex used to build the PDF output format. |
---|
3 | # |
---|
4 | |
---|
5 | import os |
---|
6 | import platform |
---|
7 | import re |
---|
8 | |
---|
9 | package_test_preamble = ['\\newif\\ifsphinxKeepOldNames \\sphinxKeepOldNamestrue', |
---|
10 | '\documentclass[a4paper,11pt,english]{report}'] |
---|
11 | package_test_postamble = ['\\begin{document} test \\end{document}'] |
---|
12 | package_tests = { |
---|
13 | 'Bjarne' : ['\\usepackage[Bjarne]{fncychap}'], |
---|
14 | 'alltt' : ['\\usepackage{alltt}'], |
---|
15 | 'amsmath' : ['\\usepackage{amsmath}'], |
---|
16 | 'amssymb' : ['\\usepackage{amssymb}'], |
---|
17 | 'amstext' : ['\\usepackage{amstext}'], |
---|
18 | 'array' : ['\\usepackage{array}'], |
---|
19 | 'atbegshi' : ['\\usepackage{atbegshi}'], |
---|
20 | 'babel' : ['\\usepackage{babel}'], |
---|
21 | 'babel' : ['\\usepackage{babel}'], |
---|
22 | 'calc' : ['\\usepackage{calc}'], |
---|
23 | 'capt-of' : ['\\usepackage{capt-of}'], |
---|
24 | 'charter' : ['\\usepackage{charter}'], |
---|
25 | 'cmap' : ['\\usepackage{cmap}'], |
---|
26 | 'color' : ['\\usepackage{color}'], |
---|
27 | 'eqparbox' : ['\\usepackage{eqparbox}'], |
---|
28 | 'enumitem' : ['\\usepackage{enumitem}'], |
---|
29 | 'etoolbox' : ['\\usepackage{etoolbox}'], |
---|
30 | 'fancybox' : ['\\usepackage{fancybox}'], |
---|
31 | 'fancyhdr' : ['\\usepackage{fancyhdr}'], |
---|
32 | 'fancyvrb' : ['\\usepackage{fancyvrb}'], |
---|
33 | 'float' : ['\\usepackage{float}'], |
---|
34 | 'fncychap' : ['\\usepackage{fncychap}'], |
---|
35 | 'fontenc' : ['\\usepackage[T1]{fontenc}'], |
---|
36 | 'footnote' : ['\\usepackage{footnote}'], |
---|
37 | 'framed' : ['\\usepackage{framed}'], |
---|
38 | 'graphicx' : ['\\usepackage{graphicx}'], |
---|
39 | 'hypcap' : ['\\usepackage{hyperref}', |
---|
40 | '\\usepackage{hypcap}'], |
---|
41 | 'hyperref' : ['\\usepackage{hyperref}'], |
---|
42 | 'inconsolata' : ['\\usepackage{inconsolata}'], |
---|
43 | 'ifplatform' : ['\\usepackage{ifplatform}'], |
---|
44 | 'ifthen' : ['\\usepackage{ifthen}'], |
---|
45 | 'inputenc' : ['\\usepackage{inputenc}'], |
---|
46 | 'keyval' : ['\\usepackage{keyval}'], |
---|
47 | 'kvoptions' : ['\\usepackage{kvoptions}'], |
---|
48 | 'lato' : ['\\usepackage{lato}'], |
---|
49 | 'lineno' : ['\\usepackage{lineno}'], |
---|
50 | 'longtable' : ['\\usepackage{longtable}'], |
---|
51 | 'makeidx' : ['\\usepackage{makeidx}'], |
---|
52 | 'multirow' : ['\\usepackage{multirow}'], |
---|
53 | 'parskip' : ['\\usepackage{parskip}'], |
---|
54 | 'pdftexcmds' : ['\\usepackage{pdftexcmds}'], |
---|
55 | 'textcomp' : ['\\usepackage{textcomp}'], |
---|
56 | 'threeparttable' : ['\\usepackage{threeparttable}'], |
---|
57 | 'times' : ['\\usepackage{times}'], |
---|
58 | 'titlesec' : ['\\usepackage{titlesec}'], |
---|
59 | 'upquote' : ['\\usepackage{upquote}'], |
---|
60 | 'utf8' : ['\\usepackage[utf8]{inputenc}'], |
---|
61 | 'wrapfig' : ['\\usepackage{wrapfig}'], |
---|
62 | 'xcolor' : ['\\usepackage{xcolor}'], |
---|
63 | 'xstring' : ['\\usepackage{xstring}'], |
---|
64 | } |
---|
65 | package_optional = ['inconsolata', |
---|
66 | 'lato'] |
---|
67 | |
---|
68 | # |
---|
69 | # Add per host support. If there is a version clash for the same texlive |
---|
70 | # package create a directory, add to that directory and use the path in this |
---|
71 | # name here. |
---|
72 | # |
---|
73 | hosts = { |
---|
74 | # All versions of CentOS until told otherwise |
---|
75 | 'Linux/centos' : { '.*' : ['capt-of.sty', |
---|
76 | 'eqparbox.sty', |
---|
77 | 'environ.sty', |
---|
78 | 'ifplatform.sty', |
---|
79 | 'trimspaces.sty', |
---|
80 | 'slantsc.sty', |
---|
81 | 'upquote.sty'] } |
---|
82 | } |
---|
83 | |
---|
84 | def tex_test(test): |
---|
85 | return os.linesep.join(package_test_preamble + |
---|
86 | package_tests[test] + |
---|
87 | package_test_postamble) |
---|
88 | |
---|
89 | def host_name(): |
---|
90 | uname = os.uname() |
---|
91 | if uname[0] == 'Linux': |
---|
92 | distro = platform.dist() |
---|
93 | name = '%s/%s' % (uname[0], distro[0]) |
---|
94 | version = distro[1] |
---|
95 | else: |
---|
96 | name = uname[0] |
---|
97 | version = uname[2] |
---|
98 | return name, version |
---|
99 | |
---|
100 | def local_packages(): |
---|
101 | host, version = host_name() |
---|
102 | packages = None |
---|
103 | if host in hosts: |
---|
104 | for hv in list(hosts[host].keys()): |
---|
105 | if re.compile(hv).match(version) is not None: |
---|
106 | packages = hosts[host][hv] |
---|
107 | return packages |
---|
108 | |
---|
109 | def configure_tests(conf): |
---|
110 | |
---|
111 | # |
---|
112 | # Using a hint from ita (thank you) : |
---|
113 | # https://github.com/waf-project/waf/blob/master/demos/tex/wscript |
---|
114 | # |
---|
115 | def build_latex_test(bld): |
---|
116 | def write_tex_test(tsk): |
---|
117 | tsk.outputs[0].write(tex_test(tsk.env.TEST)) |
---|
118 | |
---|
119 | test = bld.kw['tex_test'] |
---|
120 | bld.env.TEST = test |
---|
121 | |
---|
122 | bld.to_log('%s.tex %s' % (test, '=' * (40 - len(test) + 5))) |
---|
123 | bld.to_log(tex_test(test)) |
---|
124 | bld.to_log('=' * 40) |
---|
125 | |
---|
126 | bld(rule = write_tex_test, target = 'main.tex') |
---|
127 | bld(features = 'tex', type = 'pdflatex', source = 'main.tex', prompt = 0) |
---|
128 | |
---|
129 | tests = sorted(package_tests.keys()) |
---|
130 | local_packs = local_packages() |
---|
131 | excludes = [p for p in package_optional] |
---|
132 | if local_packs is not None: |
---|
133 | excludes += [p[:p.rfind('.')] for p in local_packs] |
---|
134 | for e in excludes: |
---|
135 | if e in tests: |
---|
136 | tests.remove(e) |
---|
137 | |
---|
138 | fails = 0 |
---|
139 | r = conf.find_program("pygmentize", mandatory = False) |
---|
140 | if r is None: |
---|
141 | fails += 1 |
---|
142 | for t in tests: |
---|
143 | r = conf.test(build_fun = build_latex_test, |
---|
144 | msg = "Checking for Tex package '%s'" % (t), |
---|
145 | tex_test = t, |
---|
146 | okmsg = 'ok', |
---|
147 | errmsg = 'not found (please install)', |
---|
148 | mandatory = False) |
---|
149 | if r is None: |
---|
150 | fails += 1 |
---|
151 | if fails > 0: |
---|
152 | conf.fatal('There are %d Tex package failures. Please fix.' % (fails)) |
---|
153 | |
---|
154 | fails = 0 |
---|
155 | for t in package_optional: |
---|
156 | r = conf.test(build_fun = build_latex_test, |
---|
157 | msg = "Checking for Tex package '%s'" % (t), |
---|
158 | tex_test = t, |
---|
159 | okmsg = 'ok', |
---|
160 | errmsg = 'not found (degraded fonts)', |
---|
161 | mandatory = False) |
---|
162 | if r is None: |
---|
163 | fails += 1 |
---|
164 | if fails == 0: |
---|
165 | conf.env.RTEMSEXTRAFONTS = 'rtemsextrafonts.sty' |
---|
166 | else: |
---|
167 | conf.env.RTEMSEXTRAFONTS = 'rtemsextrafonts-null.sty' |
---|