From 208f131feaaa8fb88e3e27ff4eff6a41fc5fec93 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Thu, 6 Feb 2020 08:59:32 -0700 Subject: Kill a couple of "for foo in range(len(bar))" Usually these aren't needed; the ones in tex.py defintely weren't. Also one bit of code reformat. Signed-off-by: Mats Wichmann --- SCons/Tool/tex.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/SCons/Tool/tex.py b/SCons/Tool/tex.py index 1d61e2d..a5e65c9 100644 --- a/SCons/Tool/tex.py +++ b/SCons/Tool/tex.py @@ -429,18 +429,23 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None return result # Now decide if latex will need to be run again due to newglossary command. - for ig in range(len(newglossary_suffix)): - if check_MD5(suffix_nodes[newglossary_suffix[ig][2]],newglossary_suffix[ig][2]) or (count == 1): + for ng in newglossary_suffix: + if check_MD5(suffix_nodes[ng[2]], ng[2]) or (count == 1): # We must run makeindex if Verbose: print("Need to run makeindex for newglossary") - newglfile = suffix_nodes[newglossary_suffix[ig][2]] - MakeNewGlossaryAction = SCons.Action.Action("$MAKENEWGLOSSARYCOM ${SOURCE.filebase}%s -s ${SOURCE.filebase}.ist -t ${SOURCE.filebase}%s -o ${SOURCE.filebase}%s" % (newglossary_suffix[ig][2],newglossary_suffix[ig][0],newglossary_suffix[ig][1]), "$MAKENEWGLOSSARYCOMSTR") + newglfile = suffix_nodes[ng[2]] + MakeNewGlossaryAction = SCons.Action.Action( + "$MAKENEWGLOSSARYCOM ${SOURCE.filebase}%s -s ${SOURCE.filebase}.ist -t ${SOURCE.filebase}%s -o ${SOURCE.filebase}%s" + % (ng[2], ng[0], ng[1]), + "$MAKENEWGLOSSARYCOMSTR", + ) result = MakeNewGlossaryAction(newglfile, newglfile, env) if result != 0: - check_file_error_message('%s (newglossary)' % env['MAKENEWGLOSSARY'], - newglossary_suffix[ig][0]) + check_file_error_message( + '%s (newglossary)' % env['MAKENEWGLOSSARY'], ng[0] + ) return result # Now decide if latex needs to be run yet again to resolve warnings. @@ -786,8 +791,8 @@ def tex_emitter_core(target, source, env, graphics_extensions): file_basename = os.path.join(targetdir, 'bu*.aux') file_list = glob.glob(file_basename) # remove the suffix '.aux' - for i in range(len(file_list)): - file_list.append(SCons.Util.splitext(file_list[i])[0]) + for fl in file_list: + file_list.append(SCons.Util.splitext(fl)[0]) # for multibib we need a list of files if suffix_list[-1] == 'multibib': for multibibmatch in multibib_re.finditer(content): @@ -797,8 +802,8 @@ def tex_emitter_core(target, source, env, graphics_extensions): baselist = multibibmatch.group(1).split(',') if Verbose: print("multibib list ", baselist) - for i in range(len(baselist)): - file_list.append(os.path.join(targetdir, baselist[i])) + for bl in baselist: + file_list.append(os.path.join(targetdir, bl)) # now define the side effects for file_name in file_list: for suffix in suffix_list[:-1]: -- cgit v0.12 From b896b7b9649003016537a005678c576511bf3338 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 18 Nov 2020 07:09:33 -0700 Subject: [PR #3827] fix: don't iterate over object being modified Signed-off-by: Mats Wichmann --- CHANGES.txt | 1 + SCons/Tool/tex.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 77fb110..1037f69 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -77,6 +77,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER and to rerun such tests. Useful when an error cascades through several tests, can quickly try if a change improves all the fails. Dropped runtest test for fallback from qmtest, not needed; added new tests. + - Eliminate tex tool usage of "for foo in range(len(iterable))" From Simon Tegelid - Fix using TEMPFILE in multiple actions in an action list. Previously a builder, or command diff --git a/SCons/Tool/tex.py b/SCons/Tool/tex.py index a5e65c9..0ca7e2d 100644 --- a/SCons/Tool/tex.py +++ b/SCons/Tool/tex.py @@ -791,7 +791,7 @@ def tex_emitter_core(target, source, env, graphics_extensions): file_basename = os.path.join(targetdir, 'bu*.aux') file_list = glob.glob(file_basename) # remove the suffix '.aux' - for fl in file_list: + for fl in file_list.copy(): file_list.append(SCons.Util.splitext(fl)[0]) # for multibib we need a list of files if suffix_list[-1] == 'multibib': -- cgit v0.12