Skip to content

Commit

Permalink
STYLE: Format Python code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Leengit authored and hjmjohnson committed Mar 2, 2022
1 parent ac3ccdb commit b041051
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 96 deletions.
53 changes: 28 additions & 25 deletions SoftwareGuide/Examples/ParseCxxExamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
beginCodeBlockTag = "BeginCodeSnippet"
endCodeBlockTag = "EndCodeSnippet"

validCodeBlockTypes = ['Latex', 'CodeSnippet']
validCodeBlockTypes = ["Latex", "CodeSnippet"]

## This class is initialized with a the starting line of
## the command processing, and the block of text for
## this command invocation


class OneDocBlock():
class OneDocBlock:
def __init__(self, sourceFile, id, codeblock):
self.sourceFile = sourceFile
self.id = id
self.codeblock = codeblock
self.blockType = 'Unknown' # Something other than items in validCodeBlockTypes
self.blockType = "Unknown" # Something other than items in validCodeBlockTypes

def Print(self):
blockline = self.id
Expand All @@ -40,16 +40,16 @@ def Print(self):

def GetCodeBlockString(self):
blockstring = ""
if self.blockType == 'Latex':
if self.blockType == "Latex":
for blocktext in self.codeblock:
blockstring += "{0}\n".format(blocktext)
pass
elif self.blockType == 'CodeSnippet':
elif self.blockType == "CodeSnippet":
# blockstring += "\\small\n"
# blockstring += "\\begin{verbatim}\n"
# blockstring += "\\begin{itklisting}[language=C++]\n"
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"
# blockstring += "\\begin{minted}[baselinestretch=1,fontsize=\small,linenos=false,bgcolor=ltgray]{c++}\n"
for blocktext in self.codeblock:
blockstring += "{0}".format(blocktext)
blockstring += "\\end{minted}\n"
Expand All @@ -70,7 +70,7 @@ def ParseOneFile(sourceFile):
# Read each line and Parse the input file
#
# Get the command line args from the source file
sf = open(sourceFile, 'r')
sf = open(sourceFile, "r")
INFILE = sf.readlines()
sf.close()
parseLine = 0
Expand All @@ -90,7 +90,7 @@ def ParseOneFile(sourceFile):
checkForBlankLine = True
elif thisline.count(endLatexTag) == 1: # end of LatexCodeBlock
ocb = OneDocBlock(sourceFile, starttagline, codeBlock)
ocb.blockType = 'Latex'
ocb.blockType = "Latex"
thisFileCommandBlocks.append(ocb)
starttagline = 0
elif thisline.count(beginCodeBlockTag) == 1: # start of CodeSnippet
Expand All @@ -99,28 +99,27 @@ def ParseOneFile(sourceFile):
codeBlock = []
elif thisline.count(endCodeBlockTag) == 1: # end of CodeSnippet
ocb = OneDocBlock(sourceFile, starttagline, codeBlock)
ocb.blockType = 'CodeSnippet'
ocb.blockType = "CodeSnippet"
thisFileCommandBlocks.append(ocb)
starttagline = 0
elif starttagline > 0: # Inside a codeBlock
if isLatexBlock == True:
thisline = commentPattern.sub("",thisline)
thisline = commentPattern.sub("", thisline)
thisline = thisline.lstrip().rstrip()
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
)
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
)
)
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
)
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
)
)
codeBlock.append(thisline)
else: # non-codeBlock line
Expand All @@ -142,11 +141,15 @@ def GetPreambleString(examplefilename):
The source code for this section can be found in the file\\\\
\\texttt{2}{1}{3}.
""".format(examplefilename, os.path.basename(examplefilename), '{', '}')
""".format(
examplefilename, os.path.basename(examplefilename), "{", "}"
)
return preamble


if __name__ == "__main__":
import sys

if len(sys.argv) < 2:
print("Usage: {0} <input file> <output file>".format(argv[0]))
sys.exit(-1)
Expand All @@ -166,7 +169,7 @@ def GetPreambleString(examplefilename):
else:
raise

outPtr = open(outputfilename, 'w')
outPtr = open(outputfilename, "w")
outPtr.write(GetPreambleString(inputfilename))
for cb in thisCodeBlocks:
outPtr.write(cb.GetCodeBlockString())
Expand Down
Loading

0 comments on commit b041051

Please sign in to comment.