Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support for removing python funcitons
  • Loading branch information
pmiquelm committed Aug 23, 2016
commit 772329b71ebfc44866e961f4fbcd3bbc50e00afc
34 changes: 30 additions & 4 deletions documentation/doxygen/converttonotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# -------- Fuction definitions---------
# -------------------------------------

def unindenter(string):
def unindenter(string, spaces = 3):
"""
Returns string with each line unindented by 3 spaces. If line isn't indented, it stays the same.
>>> unindenter(" foobar")
Expand All @@ -85,8 +85,8 @@ def unindenter(string):
newstring = ''
lines = string.splitlines()
for line in lines:
if line.startswith(" "):
newstring += (line[3:] + "\n")
if line.startswith(spaces*' '):
newstring += (line[spaces:] + "\n")
else:
newstring += (line + "\n")

Expand Down Expand Up @@ -194,6 +194,31 @@ def pythonComments(text):
return newtext


def pythonMainFunction(text):
lines = text.splitlines()
functionContentRe = re.compile('def %s\\(.*\\):' % tutName , flags = re.DOTALL | re.MULTILINE)
newtext = ''
inMainFunction = False
hasMainFunction = False
for line in lines:

if hasMainFunction:
if line.startswith("""if __name__ == "__main__":""") or line.startswith("""if __name__ == '__main__':"""):
break
match = functionContentRe.search(line)
if inMainFunction and not line.startswith(" ") and line != "":
inMainFunction = False
if match:
inMainFunction = True
hasMainFunction = True
else:
if inMainFunction:
newtext += (line[4:] + '\n')
else:
newtext += (line + '\n')
return newtext


def readHeaderCpp(text):
"""
Extract author and description from header, eliminate header from text. Also returns
Expand Down Expand Up @@ -393,7 +418,7 @@ def split(text):
helpers = []
main = ""
for matchString in [match.group() for match in functionMatches]:
if tutName == findFunctionName(matchString): # if the name of the funcitn is that of the macro
if tutName == findFunctionName(matchString): # if the name of the function is that of the macro
main = matchString
else:
helpers.append(matchString)
Expand Down Expand Up @@ -642,6 +667,7 @@ def mainfunction(text):
text += ("\n# <codecell>\n" + main)

if extension == "py":
text = pythonMainFunction(text)
text = pythonComments(text) # Convert comments into Markdown cells


Expand Down