Changeset 904702d for waflib/Tools/tex.py
- Timestamp:
- Mar 14, 2015, 6:06:10 PM (10 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 6d7acc8
- Parents:
- 5525507
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waflib/Tools/tex.py
r5525507 r904702d 4 4 5 5 import os,re 6 from waflib import Utils,Task,Errors,Logs 6 from waflib import Utils,Task,Errors,Logs,Node 7 7 from waflib.TaskGen import feature,before_method 8 8 re_bibunit=re.compile(r'\\(?P<type>putbib)\[(?P<file>[^\[\]]*)\]',re.M) … … 15 15 path=match.group('file') 16 16 if path: 17 for k in ['','.bib']:17 for k in('','.bib'): 18 18 Logs.debug('tex: trying %s%s'%(path,k)) 19 19 fi=node.parent.find_resource(path+k) … … 24 24 Logs.debug("tex: found the following bibunit files: %s"%nodes) 25 25 return nodes 26 exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps' ]26 exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps','.sty'] 27 27 exts_tex=['.ltx','.tex'] 28 re_tex=re.compile(r'\\(?P<type> include|bibliography|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M)28 re_tex=re.compile(r'\\(?P<type>usepackage|RequirePackage|include|bibliography([^\[\]{}]*)|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M) 29 29 g_bibtex_re=re.compile('bibdata',re.M) 30 g_glossaries_re=re.compile('\\@newglossary',re.M) 30 31 class tex(Task.Task): 31 32 bibtex_fun,_=Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}',shell=False) … … 37 38 Execute the program **makeindex** 38 39 """ 40 makeglossaries_fun,_=Task.compile_fun('${MAKEGLOSSARIES} ${SRCFILE}',shell=False) 41 makeglossaries_fun.__doc__=""" 42 Execute the program **makeglossaries** 43 """ 39 44 def exec_command(self,cmd,**kw): 40 45 bld=self.generator.bld 46 Logs.info('runner: %r'%cmd) 41 47 try: 42 48 if not kw.get('cwd',None): … … 72 78 global re_tex 73 79 for match in re_tex.finditer(code): 80 multibib=match.group('type') 81 if multibib and multibib.startswith('bibliography'): 82 multibib=multibib[len('bibliography'):] 83 if multibib.startswith('style'): 84 continue 85 else: 86 multibib=None 74 87 for path in match.group('file').split(','): 75 88 if path: … … 77 90 found=None 78 91 for k in exts_deps_tex: 79 Logs.debug('tex: trying %s%s'%(path,k)) 80 found=node.parent.find_resource(path+k) 92 for up in self.texinputs_nodes: 93 Logs.debug('tex: trying %s%s'%(path,k)) 94 found=up.find_resource(path+k) 95 if found: 96 break 81 97 for tsk in self.generator.tasks: 82 98 if not found or found in tsk.outputs: … … 89 105 parse_node(found) 90 106 break 107 if found and multibib and found.name.endswith('.bib'): 108 try: 109 self.multibibs.append(found) 110 except AttributeError: 111 self.multibibs=[found] 91 112 if add_name: 92 113 names.append(path) … … 103 124 try: 104 125 ct=aux_node.read() 105 except (OSError,IOError):126 except EnvironmentError: 106 127 Logs.error('Error reading %s: %r'%aux_node.abspath()) 107 128 continue 108 129 if g_bibtex_re.findall(ct): 109 Logs. warn('calling bibtex')130 Logs.info('calling bibtex') 110 131 self.env.env={} 111 132 self.env.env.update(os.environ) 112 self.env.env.update({'BIBINPUTS':self. TEXINPUTS,'BSTINPUTS':self.TEXINPUTS})133 self.env.env.update({'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()}) 113 134 self.env.SRCFILE=aux_node.name[:-4] 114 135 self.check_status('error when calling bibtex',self.bibtex_fun()) 136 for node in getattr(self,'multibibs',[]): 137 self.env.env={} 138 self.env.env.update(os.environ) 139 self.env.env.update({'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()}) 140 self.env.SRCFILE=node.name[:-4] 141 self.check_status('error when calling bibtex',self.bibtex_fun()) 115 142 def bibunits(self): 116 143 try: … … 120 147 else: 121 148 if bibunits: 122 fn=['bu'+str(i)for i in xrange(1,len(bibunits)+1)]149 fn=['bu'+str(i)for i in range(1,len(bibunits)+1)] 123 150 if fn: 124 Logs. warn('calling bibtex on bibunits')151 Logs.info('calling bibtex on bibunits') 125 152 for f in fn: 126 self.env.env={'BIBINPUTS':self. TEXINPUTS,'BSTINPUTS':self.TEXINPUTS}153 self.env.env={'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()} 127 154 self.env.SRCFILE=f 128 155 self.check_status('error when calling bibtex',self.bibtex_fun()) 129 156 def makeindex(self): 157 self.idx_node=self.inputs[0].change_ext('.idx') 130 158 try: 131 159 idx_path=self.idx_node.abspath() 132 160 os.stat(idx_path) 133 161 except OSError: 134 Logs. warn('index file %s absent, not calling makeindex'%idx_path)162 Logs.info('index file %s absent, not calling makeindex'%idx_path) 135 163 else: 136 Logs. warn('calling makeindex')164 Logs.info('calling makeindex') 137 165 self.env.SRCFILE=self.idx_node.name 138 166 self.env.env={} … … 142 170 if os.path.exists(os.path.join(p.abspath(),'btaux.aux')): 143 171 self.aux_nodes+=p.ant_glob('*[0-9].aux') 172 def makeglossaries(self): 173 src_file=self.inputs[0].abspath() 174 base_file=os.path.basename(src_file) 175 base,_=os.path.splitext(base_file) 176 for aux_node in self.aux_nodes: 177 try: 178 ct=aux_node.read() 179 except EnvironmentError: 180 Logs.error('Error reading %s: %r'%aux_node.abspath()) 181 continue 182 if g_glossaries_re.findall(ct): 183 if not self.env.MAKEGLOSSARIES: 184 raise Errors.WafError("The program 'makeglossaries' is missing!") 185 Logs.warn('calling makeglossaries') 186 self.env.SRCFILE=base 187 self.check_status('error when calling makeglossaries %s'%base,self.makeglossaries_fun()) 188 return 189 def texinputs(self): 190 return os.pathsep.join([k.abspath()for k in self.texinputs_nodes])+os.pathsep 144 191 def run(self): 145 192 env=self.env … … 148 195 env.append_value('PDFLATEXFLAGS','-interaction=batchmode') 149 196 env.append_value('XELATEXFLAGS','-interaction=batchmode') 150 fun=self.texfun151 node=self.inputs[0]152 srcfile=node.abspath()153 texinputs=self.env.TEXINPUTS or''154 self.TEXINPUTS=node.parent.get_bld().abspath()+os.pathsep+node.parent.get_src().abspath()+os.pathsep+texinputs+os.pathsep155 197 self.cwd=self.inputs[0].parent.get_bld().abspath() 156 Logs.warn('first pass on %s'%self.__class__.__name__) 157 self.env.env={} 158 self.env.env.update(os.environ) 159 self.env.env.update({'TEXINPUTS':self.TEXINPUTS}) 160 self.env.SRCFILE=srcfile 161 self.check_status('error when calling latex',fun()) 162 self.aux_nodes=self.scan_aux(node.change_ext('.aux')) 163 self.idx_node=node.change_ext('.idx') 198 Logs.info('first pass on %s'%self.__class__.__name__) 199 cur_hash=self.hash_aux_nodes() 200 self.call_latex() 201 self.hash_aux_nodes() 164 202 self.bibtopic() 165 203 self.bibfile() 166 204 self.bibunits() 167 205 self.makeindex() 168 hash=''206 self.makeglossaries() 169 207 for i in range(10): 170 prev_hash=hash 208 prev_hash=cur_hash 209 cur_hash=self.hash_aux_nodes() 210 if not cur_hash: 211 Logs.error('No aux.h to process') 212 if cur_hash and cur_hash==prev_hash: 213 break 214 Logs.info('calling %s'%self.__class__.__name__) 215 self.call_latex() 216 def hash_aux_nodes(self): 217 try: 218 nodes=self.aux_nodes 219 except AttributeError: 171 220 try: 172 hashes=[Utils.h_file(x.abspath())for x in self.aux_nodes] 173 hash=Utils.h_list(hashes) 174 except(OSError,IOError): 175 Logs.error('could not read aux.h') 176 pass 177 if hash and hash==prev_hash: 178 break 179 Logs.warn('calling %s'%self.__class__.__name__) 180 self.env.env={} 181 self.env.env.update(os.environ) 182 self.env.env.update({'TEXINPUTS':self.TEXINPUTS}) 183 self.env.SRCFILE=srcfile 184 self.check_status('error when calling %s'%self.__class__.__name__,fun()) 221 self.aux_nodes=self.scan_aux(self.inputs[0].change_ext('.aux')) 222 except IOError: 223 return None 224 return Utils.h_list([Utils.h_file(x.abspath())for x in self.aux_nodes]) 225 def call_latex(self): 226 self.env.env={} 227 self.env.env.update(os.environ) 228 self.env.env.update({'TEXINPUTS':self.texinputs()}) 229 self.env.SRCFILE=self.inputs[0].abspath() 230 self.check_status('error when calling latex',self.texfun()) 185 231 class latex(tex): 186 232 texfun,vars=Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}',shell=False) … … 204 250 @before_method('process_source') 205 251 def apply_tex(self): 206 if not getattr(self,'type',None)in ['latex','pdflatex','xelatex']:252 if not getattr(self,'type',None)in('latex','pdflatex','xelatex'): 207 253 self.type='pdflatex' 208 254 tree=self.bld … … 212 258 if getattr(self,'deps',None): 213 259 deps=self.to_list(self.deps) 214 for filename in deps: 215 n=self.path.find_resource(filename) 216 if not n: 217 self.bld.fatal('Could not find %r for %r'%(filename,self)) 218 if not n in deps_lst: 219 deps_lst.append(n) 260 for dep in deps: 261 if isinstance(dep,str): 262 n=self.path.find_resource(dep) 263 if not n: 264 self.bld.fatal('Could not find %r for %r'%(dep,self)) 265 if not n in deps_lst: 266 deps_lst.append(n) 267 elif isinstance(dep,Node.Node): 268 deps_lst.append(dep) 220 269 for node in self.to_nodes(self.source): 221 270 if self.type=='latex': … … 227 276 task.env=self.env 228 277 if deps_lst: 229 try: 230 lst=tree.node_deps[task.uid()] 231 for n in deps_lst: 232 if not n in lst: 233 lst.append(n) 234 except KeyError: 235 tree.node_deps[task.uid()]=deps_lst 236 v=dict(os.environ) 237 p=node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()+os.pathsep+v.get('TEXINPUTS','')+os.pathsep 238 v['TEXINPUTS']=p 278 for n in deps_lst: 279 if not n in task.dep_nodes: 280 task.dep_nodes.append(n) 281 if hasattr(self,'texinputs_nodes'): 282 task.texinputs_nodes=self.texinputs_nodes 283 else: 284 task.texinputs_nodes=[node.parent,node.parent.get_bld(),self.path,self.path.get_bld()] 285 lst=os.environ.get('TEXINPUTS','') 286 if self.env.TEXINPUTS: 287 lst+=os.pathsep+self.env.TEXINPUTS 288 if lst: 289 lst=lst.split(os.pathsep) 290 for x in lst: 291 if x: 292 if os.path.isabs(x): 293 p=self.bld.root.find_node(x) 294 if p: 295 task.texinputs_nodes.append(p) 296 else: 297 Logs.error('Invalid TEXINPUTS folder %s'%x) 298 else: 299 Logs.error('Cannot resolve relative paths in TEXINPUTS %s'%x) 239 300 if self.type=='latex': 240 301 if'ps'in outs: 241 302 tsk=self.create_task('dvips',task.outputs,node.change_ext('.ps')) 242 tsk.env.env=dict( v)303 tsk.env.env=dict(os.environ) 243 304 if'pdf'in outs: 244 305 tsk=self.create_task('dvipdf',task.outputs,node.change_ext('.pdf')) 245 tsk.env.env=dict( v)306 tsk.env.env=dict(os.environ) 246 307 elif self.type=='pdflatex': 247 308 if'ps'in outs: … … 250 311 def configure(self): 251 312 v=self.env 252 for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps '.split():313 for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps makeglossaries'.split(): 253 314 try: 254 315 self.find_program(p,var=p.upper())
Note: See TracChangeset
for help on using the changeset viewer.