diff --git a/SoftwareGuide/Examples/ParseCxxExamples.py b/SoftwareGuide/Examples/ParseCxxExamples.py
index 247a01a6..3410bbdd 100755
--- a/SoftwareGuide/Examples/ParseCxxExamples.py
+++ b/SoftwareGuide/Examples/ParseCxxExamples.py
@@ -32,17 +32,17 @@ def __init__(self, sourceFile, id, codeblock):
def Print(self):
blockline = self.id
print("=" * 80)
- print("{0} : {1}".format(self.blockType, self.sourceFile))
+ print(f"{self.blockType} : {self.sourceFile}")
for blocktext in self.codeblock:
blockline += 1
- print("{0} : {1}".format(blockline, blocktext))
+ print(f"{blockline} : {blocktext}")
print("^" * 80)
def GetCodeBlockString(self):
blockstring = ""
if self.blockType == "Latex":
for blocktext in self.codeblock:
- blockstring += "{0}\n".format(blocktext)
+ blockstring += f"{blocktext}\n"
pass
elif self.blockType == "CodeSnippet":
# blockstring += "\\small\n"
@@ -51,7 +51,7 @@ def GetCodeBlockString(self):
blockstring += "\\begin{minted}[baselinestretch=1,fontsize=\\footnotesize,linenos=false,bgcolor=ltgray]{c++}\n"
# blockstring += "\\begin{minted}[baselinestretch=1,fontsize=\small,linenos=false,bgcolor=ltgray]{c++}\n"
for blocktext in self.codeblock:
- blockstring += "{0}".format(blocktext)
+ blockstring += f"{blocktext}"
blockstring += "\\end{minted}\n"
# blockstring += "\\end{itklisting}\n"
# blockstring += "\\end{verbatim}\n";
@@ -109,17 +109,13 @@ def ParseOneFile(sourceFile):
if checkForBlankLine:
if thisline != "":
print(
- "{filename}:{line}: warning: Line after start of LaTeX block should be a newline -- instead got {value}".format(
- filename=sourceFile, line=parseLine, value=thisline
- )
+ f"{sourceFile}:{parseLine}: warning: Line after start of LaTeX block should be a newline -- instead got {thisline}"
)
checkForBlankLine = False
if not isLatexBlock and (len(thisline) > 80):
print(
- "{filename}:{line}:80: warning: Line length too long for LaTeX printing".format(
- filename=sourceFile, line=parseLine
- )
+ f"{sourceFile}:{parseLine}:80: warning: Line length too long for LaTeX printing"
)
codeBlock.append(thisline)
else: # non-codeBlock line
@@ -130,20 +126,18 @@ def ParseOneFile(sourceFile):
def GetPreambleString(examplefilename):
# The following message is a warning writen on the generated .tex
# files for preventing them from being manualy edited.
- preamble = """
+ preamble = f"""
% Please do NOT edit this file.
% It has been automatically generated
% by a perl script from the original cxx sources
% in the Insight/Examples directory
% Any changes should be made in the file
-% {0}
+% {examplefilename}
The source code for this section can be found in the file\\\\
-\\texttt{2}{1}{3}.
-""".format(
- examplefilename, os.path.basename(examplefilename), "{", "}"
- )
+\\texttt{{{os.path.basename(examplefilename)}}}.
+"""
return preamble
@@ -151,12 +145,12 @@ def GetPreambleString(examplefilename):
import sys
if len(sys.argv) < 2:
- print("Usage: {0} ".format(argv[0]))
+ print(f"Usage: {argv[0]} ")
sys.exit(-1)
inputfilename = sys.argv[1]
outputfilename = sys.argv[2]
- print("Processing {0} into {1} ... \n".format(inputfilename, outputfilename))
+ print(f"Processing {inputfilename} into {outputfilename} ... \n")
thisCodeBlocks = ParseOneFile(inputfilename)
diff --git a/SoftwareGuide/Examples/RunExamples.py b/SoftwareGuide/Examples/RunExamples.py
index aca8d818..7db6535e 100644
--- a/SoftwareGuide/Examples/RunExamples.py
+++ b/SoftwareGuide/Examples/RunExamples.py
@@ -65,9 +65,7 @@ def __init__(self, sourceFile, id, codeblock, pathFinder):
self.children = set()
if not os.path.exists(self.progFullPath):
print(
- "ERROR: Required program {0} does not exists. Please rebuild ITK".format(
- self.progBaseName
- )
+ f"ERROR: Required program {self.progBaseName} does not exists. Please rebuild ITK"
)
sys.exit(-1)
@@ -81,43 +79,43 @@ def DoInputsExists(self):
if ii == None:
continue
if not os.path.exists(ii):
- print("ERROR: XXXXXXXXXXXX MISSING {0}".format(ii))
+ print(f"ERROR: XXXXXXXXXXXX MISSING {ii}")
return False
return True
def AreOutputsNewer(self):
oldest_output = 100000000000000000000000
if self.verbose:
- print("Self Outputs {0}".format(self.outputs))
- print("Self Inputs {0}".format(self.inputs))
+ print(f"Self Outputs {self.outputs}")
+ print(f"Self Inputs {self.inputs}")
for o in self.outputs:
if self.verbose:
- print("CHECKING TIME FOR: {0}".format(o))
+ print(f"CHECKING TIME FOR: {o}")
if os.path.exists(o):
this_output_time = os.path.getmtime(o)
if self.verbose:
- print("This Ouptut Time: {0}".format(this_output_time))
+ print(f"This Ouptut Time: {this_output_time}")
if this_output_time < oldest_output:
oldest_output = this_output_time
else:
if self.verbose:
- print("Missing Output: {0}".format(o))
+ print(f"Missing Output: {o}")
return False
newest_input = os.path.getmtime(self.progFullPath)
for i in self.inputs:
if i == None:
continue
if self.verbose:
- print("CHECKING TIME FOR: {0}".format(i))
+ print(f"CHECKING TIME FOR: {i}")
if os.path.exists(i):
this_input_time = os.path.getmtime(i)
if self.verbose:
- print("This Input Time: {0}".format(this_input_time))
+ print(f"This Input Time: {this_input_time}")
if this_input_time > newest_input:
newest_input = this_input_time
else:
- print("Missing input {0}".format(i))
- print("Searched {0}".format(self.inputs))
+ print(f"Missing input {i}")
+ print(f"Searched {self.inputs}")
print("ERROR:" * 20)
print(
"Failing to process all data, This should never happen because you should only run this function once all inputs exists."
@@ -126,11 +124,7 @@ def AreOutputsNewer(self):
-1
) # This should never happen because you should only run this function once all inputs exists.
if self.verbose:
- print(
- "Newest Input: {0}, Oldest Output: {1}".format(
- newest_input, oldest_output
- )
- )
+ print(f"Newest Input: {newest_input}, Oldest Output: {oldest_output}")
if newest_input < oldest_output:
return True
else:
@@ -145,9 +139,7 @@ def GetCommandLine(self):
parseGroups = lineparse.search(currLine)
if parseGroups == None:
print(
- "ERROR: Invalid parsing of {0} at line {1}".format(
- self.sourceFile, currLineNumber
- )
+ f"ERROR: Invalid parsing of {self.sourceFile} at line {currLineNumber}"
)
sys.exit(-1)
if parseGroups.group(1) == "INPUTS":
@@ -155,9 +147,7 @@ def GetCommandLine(self):
inputFileName = pathFinder.GetInputPath(inputBaseFileName)
if inputFileName == None:
print(
- "ERROR: Invalid input {0} at {1} at line {2}".format(
- parseGroups.group(2), self.sourceFile, currLineNumber
- )
+ f"ERROR: Invalid input {parseGroups.group(2)} at {self.sourceFile} at line {currLineNumber}"
)
exit(-1)
else:
@@ -166,9 +156,7 @@ def GetCommandLine(self):
inputFileName = pathFinder.GetOutputPath(inputBaseFileName)
if not os.path.exists(inputFileName):
print(
- "WARNING: Can not find {0} path, assuming it is autogenerated".format(
- inputFileName
- )
+ f"WARNING: Can not find {inputFileName} path, assuming it is autogenerated"
)
self.inputs.append(inputFileName)
elif parseGroups.group(1) == "OUTPUTS":
@@ -212,9 +200,7 @@ def MakeAllFileLists(self):
pass
else:
print(
- "ERROR: INVALID LINE IDENTIFIER {0} at line {1} in {2}".format(
- parseGroups.group(1), lineNumber, self.sourceFile
- )
+ f"ERROR: INVALID LINE IDENTIFIER {parseGroups.group(1)} at line {lineNumber} in {self.sourceFile}"
)
sys.exit(-1)
@@ -224,7 +210,7 @@ def Print(self):
print(self.sourceFile)
for blocktext in self.codeblock:
blockline += 1
- print("{0} : {1}".format(blockline, blocktext))
+ print(f"{blockline} : {blocktext}")
print(self.GetCommandLine())
print("^" * 80)
@@ -300,9 +286,7 @@ def __init__(self, itkSourceDir, itkExecutablesDir, itkBuildDir, SWGuidBaseOutpu
mkdir_p(self.outPicDir)
# HACK: Need beter search criteria
- searchPaths = "{0}/ExternalData/Testing/Data/Input#{0}/ExternalData/Examples/Data/BrainWeb#{0}/Testing/Temporary#{0}/Modules/Nonunit/Review/test#{0}/ExternalData/Modules/Segmentation/LevelSetsv4/test/Baseline#{0}/ExternalData/Modules/IO/GE/test/Baseline#{0}/ExternalData/Examples/Filtering/test/Baseline#{0}/Examples/Segmentation/test#{1}/Art/Generated#{2}/Examples/Data".format(
- itkBuildDir, SWGuidBaseOutput, itkSourceDir
- )
+ searchPaths = f"{itkBuildDir}/ExternalData/Testing/Data/Input#{itkBuildDir}/ExternalData/Examples/Data/BrainWeb#{itkBuildDir}/Testing/Temporary#{itkBuildDir}/Modules/Nonunit/Review/test#{itkBuildDir}/ExternalData/Modules/Segmentation/LevelSetsv4/test/Baseline#{itkBuildDir}/ExternalData/Modules/IO/GE/test/Baseline#{itkBuildDir}/ExternalData/Examples/Filtering/test/Baseline#{itkBuildDir}/Examples/Segmentation/test#{SWGuidBaseOutput}/Art/Generated#{itkSourceDir}/Examples/Data"
dirtyDirPaths = searchPaths.split("#")
self.searchDirList = []
@@ -310,7 +294,7 @@ def __init__(self, itkSourceDir, itkExecutablesDir, itkBuildDir, SWGuidBaseOutpu
if os.path.isdir(eachpath):
self.searchDirList.append(os.path.realpath(eachpath))
else:
- print("WARNING: MISSING search path {0} ".format(eachpath))
+ print(f"WARNING: MISSING search path {eachpath} ")
sys.exit(-1)
def GetProgramPath(self, execfilenamebase):
@@ -320,7 +304,7 @@ def GetProgramPath(self, execfilenamebase):
if os.path.exists(testPath):
return testPath
else:
- print("ERROR: {0} does not exists".format(testPath))
+ print(f"ERROR: {testPath} does not exists")
sys.exit(-1)
def GetInputPath(self, inputBaseName):
@@ -329,7 +313,7 @@ def GetInputPath(self, inputBaseName):
if os.path.exists(testPath):
return testPath
else:
- # print('##STATUS: Not yet found input {0}'.format(testPath))
+ # print(f"##STATUS: Not yet found input {testPath}")
pass
return self.GetOutputPath(inputBaseName)
@@ -337,7 +321,7 @@ def GetOutputPath(self, outputBaseName):
outPath = os.path.join(self.outPicDir, outputBaseName)
# outPath = outPath.replace(self.outPicDir+'/'+self.outPicDir, self.outPicDir ) #Avoid multiple path concatenations
# if not os.path.exists(outPath):
- # print("@@Warning: Output missing {0}".format(outPath))
+ # print(f"@@Warning: Output missing {outPath}")
return outPath
@@ -424,12 +408,12 @@ def GetSortedCodeBlockList(self):
allCommandBlocks = []
for rootDir, dirList, fileList in os.walk(args.itkSourceDir):
if rootDir.count("ThirdParty") >= 1:
- # print("Passing on: {0}".format(rootDir))
+ # print(f"Passing on: {rootDir}")
continue
for currFile in fileList:
if currFile[-4:] != ".cxx": # Only parse cxx files
- # print("NOT PARSING: {0} because it has wrong extension {1}".format(currFile,currFile[-r:]))
+ # print(f"NOT PARSING: {currFile} because it has wrong extension {currFile[-r:]}")
continue
sourceFile = os.path.realpath(rootDir + "/" + currFile)
@@ -442,8 +426,8 @@ def GetSortedCodeBlockList(self):
runCommand = blockStart.GetCommandLine()
for inputFile in blockStart.inputs:
if not os.path.exists(inputFile):
- print("WARNING: {0} input does not exist".format(blockStart.sourceFile))
- print("Running: {0}".format(runCommand))
+ print(f"WARNING: {blockStart.sourceFile} input does not exist")
+ print(f"Running: {runCommand}")
try:
retcode = subprocess.call(runCommand, shell=True)
if retcode < 0:
@@ -462,16 +446,12 @@ def GetSortedCodeBlockList(self):
for outputFile in block.outputs:
if not os.path.exists(outputFile):
print(
- "WARNING: output {0} of {1} does not exist!".format(
- outputFile, baseProgramName
- )
+ f"WARNING: output {outputFile} of {baseProgramName} does not exist!"
)
for inputFile in block.inputs:
if not os.path.exists(inputFile):
print(
- "WARNING: input {0} of {1} does not exist!".format(
- inputFile, baseProgramName
- )
+ f"WARNING: input {inputFile} of {baseProgramName} does not exist!"
)
dependencyDictionary[baseProgramName].extend(block.outputs)
for inputFile in block.inputs:
@@ -489,17 +469,16 @@ def GetSortedCodeBlockList(self):
outputCDFile = open(outputCMakeDependancies, "w")
allDependencies = "set(allEPS-DEPS "
for baseName in dependencyDictionary.keys():
- outstring = 'set("{name}-DEPS" '.format(name=baseName)
- allDependencies += ' "${' + "{name}-DEPS".format(name=baseName) + '}" '
+ outstring = f'set("{baseName}-DEPS" '
+ allDependencies += ' "${' + f"{baseName}-DEPS" + '}" '
for output in dependencyDictionary[baseName]:
epsOutput = os.path.join(
outputEPSDirectory, os.path.basename(output.replace(".png", ".eps"))
)
- outstring += ' "{epsOutput}"'.format(epsOutput=epsOutput.replace("\\", "/"))
+ # chr(92) is backslash
+ outstring += f' "{epsOutput.replace(chr(92), "/")}"'
outputCDFile.write(
- 'CONVERT_INPUT_IMG("{0}" "{1}" "{2}")\n'.format(
- output.replace("\\", "/"), epsOutput.replace("\\", "/"), ""
- )
+ f'CONVERT_INPUT_IMG("{output.replace(chr(92), "/")}" "{epsOutput.replace(chr(92), "/")}" "")\n'
)
outstring += ")\n"
outputCDFile.write(outstring)