tex.py (SCons-4.3.0) | : | tex.py (SCons-4.4.0) | ||
---|---|---|---|---|
skipping to change at line 473 | skipping to change at line 473 | |||
print("reached max number of retries on Latex ,",int(env.subst('$LAT EXRETRIES'))) | print("reached max number of retries on Latex ,",int(env.subst('$LAT EXRETRIES'))) | |||
# end of while loop | # end of while loop | |||
# rename Latex's output to what the target name is | # rename Latex's output to what the target name is | |||
if not (str(target[0]) == resultfilename and os.path.isfile(resultfilename )): | if not (str(target[0]) == resultfilename and os.path.isfile(resultfilename )): | |||
if os.path.isfile(resultfilename): | if os.path.isfile(resultfilename): | |||
print("move %s to %s" % (resultfilename, str(target[0]), )) | print("move %s to %s" % (resultfilename, str(target[0]), )) | |||
shutil.move(resultfilename,str(target[0])) | shutil.move(resultfilename,str(target[0])) | |||
# Original comment (when TEXPICTS was not restored): | # Original comment (when TEXPICTS was not restored): | |||
# The TEXPICTS enviroment variable is needed by a dvi -> pdf step | # The TEXPICTS environment variable is needed by a dvi -> pdf step | |||
# later on Mac OSX so leave it | # later on Mac OSX so leave it | |||
# | # | |||
# It is also used when searching for pictures (implicit dependencies). | # It is also used when searching for pictures (implicit dependencies). | |||
# Why not set the variable again in the respective builder instead | # Why not set the variable again in the respective builder instead | |||
# of leaving local modifications in the environment? What if multiple | # of leaving local modifications in the environment? What if multiple | |||
# latex builds in different directories need different TEXPICTS? | # latex builds in different directories need different TEXPICTS? | |||
for var in SCons.Scanner.LaTeX.LaTeX.env_variables: | for var in SCons.Scanner.LaTeX.LaTeX.env_variables: | |||
if var == 'TEXPICTS': | if var == 'TEXPICTS': | |||
continue | continue | |||
if saved_env[var] is _null: | if saved_env[var] is _null: | |||
try: | try: | |||
del env['ENV'][var] | del env['ENV'][var] | |||
except KeyError: | except KeyError: | |||
pass # was never set | pass # was never set | |||
else: | else: | |||
env['ENV'][var] = saved_env[var] | env['ENV'][var] = saved_env[var] | |||
return result | return result | |||
def LaTeXAuxAction(target = None, source= None, env=None): | def LaTeXAuxAction(target=None, source=None, env=None): | |||
result = InternalLaTeXAuxAction( LaTeXAction, target, source, env ) | result = InternalLaTeXAuxAction(LaTeXAction, target, source, env) | |||
return result | return result | |||
LaTeX_re = re.compile("\\\\document(style|class)") | LaTeX_re = re.compile("\\\\document(style|class)") | |||
def is_LaTeX(flist,env,abspath): | def is_LaTeX(flist, env, abspath) -> bool: | |||
"""Scan a file list to decide if it's TeX- or LaTeX-flavored.""" | """Scan a file list to decide if it's TeX- or LaTeX-flavored.""" | |||
# We need to scan files that are included in case the | # We need to scan files that are included in case the | |||
# \documentclass command is in them. | # \documentclass command is in them. | |||
# get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS'] | # get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS'] | |||
savedpath = modify_env_var(env, 'TEXINPUTS', abspath) | savedpath = modify_env_var(env, "TEXINPUTS", abspath) | |||
paths = env['ENV']['TEXINPUTS'] | paths = env["ENV"]["TEXINPUTS"] | |||
if SCons.Util.is_List(paths): | if SCons.Util.is_List(paths): | |||
pass | pass | |||
else: | else: | |||
# Split at os.pathsep to convert into absolute path | # Split at os.pathsep to convert into absolute path | |||
paths = paths.split(os.pathsep) | paths = paths.split(os.pathsep) | |||
# now that we have the path list restore the env | # now that we have the path list restore the env | |||
if savedpath is _null: | if savedpath is _null: | |||
try: | try: | |||
del env['ENV']['TEXINPUTS'] | del env["ENV"]["TEXINPUTS"] | |||
except KeyError: | except KeyError: | |||
pass # was never set | pass # was never set | |||
else: | else: | |||
env['ENV']['TEXINPUTS'] = savedpath | env["ENV"]["TEXINPUTS"] = savedpath | |||
if Verbose: | if Verbose: | |||
print("is_LaTeX search path ",paths) | print("is_LaTeX search path ", paths) | |||
print("files to search :",flist) | print("files to search: ", flist) | |||
# Now that we have the search path and file list, check each one | # Now that we have the search path and file list, check each one | |||
file_test = False | ||||
for f in flist: | for f in flist: | |||
if Verbose: | if Verbose: | |||
print(" checking for Latex source ",str(f)) | print(f" checking for Latex source {f}") | |||
content = f.get_text_contents() | content = f.get_text_contents() | |||
if LaTeX_re.search(content): | if LaTeX_re.search(content): | |||
if Verbose: | if Verbose: | |||
print("file %s is a LaTeX file" % str(f)) | print(f"file {f} is a LaTeX file") | |||
return 1 | return True | |||
if Verbose: | if Verbose: | |||
print("file %s is not a LaTeX file" % str(f)) | print(f"file {f} is not a LaTeX file") | |||
# now find included files | # now find included files | |||
inc_files = [ ] | inc_files = [] | |||
inc_files.extend( include_re.findall(content) ) | inc_files.extend(include_re.findall(content)) | |||
if Verbose: | if Verbose: | |||
print("files included by '%s': "%str(f),inc_files) | print(f"files included by '{f}': ", inc_files) | |||
# inc_files is list of file names as given. need to find them | # inc_files is list of file names as given. need to find them | |||
# using TEXINPUTS paths. | # using TEXINPUTS paths. | |||
# search the included files | # search the included files | |||
for src in inc_files: | for src in inc_files: | |||
srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt | srcNode = FindFile( | |||
=False) | src, [".tex", ".ltx", ".latex"], paths, env, requireExt=False | |||
) | ||||
# make this a list since is_LaTeX takes a list. | # make this a list since is_LaTeX takes a list. | |||
fileList = [srcNode,] | fileList = [srcNode] | |||
if Verbose: | if Verbose: | |||
print("FindFile found ",srcNode) | print("FindFile found ", srcNode) | |||
if srcNode is not None: | if srcNode is not None: | |||
file_test = is_LaTeX(fileList, env, abspath) | file_test = is_LaTeX(fileList, env, abspath) | |||
# return on first file that finds latex is needed. | # return on first file that finds latex is needed. | |||
if file_test: | if file_test: | |||
return file_test | return True | |||
if Verbose: | if Verbose: | |||
print(" done scanning ",str(f)) | print(f" done scanning {f}") | |||
return 0 | return False | |||
def TeXLaTeXFunction(target = None, source= None, env=None): | def TeXLaTeXFunction(target = None, source= None, env=None): | |||
"""A builder for TeX and LaTeX that scans the source file to | """A builder for TeX and LaTeX that scans the source file to | |||
decide the "flavor" of the source and then executes the appropriate | decide the "flavor" of the source and then executes the appropriate | |||
program.""" | program.""" | |||
# find these paths for use in is_LaTeX to search for included files | # find these paths for use in is_LaTeX to search for included files | |||
basedir = os.path.split(str(source[0]))[0] | basedir = os.path.split(str(source[0]))[0] | |||
abspath = os.path.abspath(basedir) | abspath = os.path.abspath(basedir) | |||
End of changes. 20 change blocks. | ||||
25 lines changed or deleted | 27 lines changed or added |