Skip to content
Snippets Groups Projects
Commit 82f1e25c authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[docgen] use .json format for .doc_config

parent 75d994ab
No related branches found
No related tags found
1 merge request!1914[examples] Implement Python-only doc generator using pyparsing
doc/intro.md {
spatialparams_1p.hh "README.md" : [
problem_1p.hh "doc/intro.md",
spatialparams_tracer.hh "spatialparams_1p.hh",
problem_tracer.hh "problem_1p.hh",
main.cc "spatialparams_tracer.hh",
doc/results.md "problem_tracer.hh",
"main.cc",
"doc/results.md"
]
}
doc/intro.md {
spatialparams.hh "README.md" : [
problem.hh "doc/intro.md",
main.cc "spatialparams.hh",
doc/results.md "problem.hh",
"main.cc",
"doc/results.md"
]
}
doc/intro.md {
problem.hh "README.md" : [
main.cc "doc/intro.md",
doc/results.md "problem.hh",
"main.cc",
"doc/results.md"
]
}
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import json
import argparse import argparse
from convert_code_to_doc import * from convert_code_to_doc import *
def convertToMarkdownAndMerge(dir, includeList): def convertToMarkdownAndMerge(dir, config):
with open(os.path.join(dir, "README.md"), "w") as readme:
for include, description in includeList: for target, sources in config.items():
fileExtension = os.path.splitext(include)[1]
if fileExtension == ".md": targetExtension = os.path.splitext(target)[1]
with open(os.path.join(dir, include), "r") as markdown: if not targetExtension == ".md":
readme.write(markdown.read()) raise IOError("Markdown files expected as targets! Given target: {}".format(target))
elif fileExtension == ".hh" or fileExtension == ".cc":
title = description + " (`{}`)\n\n\n" if description else "The file `{}`\n\n\n" targetPath = os.path.join(dir, target)
title = title.format(os.path.split(include)[1]) os.makedirs(os.path.dirname(targetPath), exist_ok=True)
readme.write("\n\n## " + title)
with open(os.path.join(dir, include), "r") as cppCode: with open(targetPath, "w") as targetFile:
readme.write(transformCode(cppCode.read(), cppRules()) + "\n") for source in sources:
else: fileExtension = os.path.splitext(source)[1]
raise IOError("Unsupported or unknown file extension *{}".format(fileExtension)) if fileExtension == ".md":
with open(os.path.join(dir, source), "r") as markdown:
targetFile.write(markdown.read())
elif fileExtension == ".hh" or fileExtension == ".cc":
with open(os.path.join(dir, source), "r") as cppCode:
targetFile.write("\n\n" + transformCode(cppCode.read(), cppRules()) + "\n")
else:
raise IOError("Unsupported or unknown file extension *{}".format(fileExtension))
def generateReadme(dir): def generateReadme(dir):
includeList = None config = None
# look for .doc_config, if not found we pass # look for .doc_config, if not found we pass
try: try:
configname = os.path.join(dir, ".doc_config") configname = os.path.join(dir, ".doc_config")
with open(configname, 'r') as config: with open(configname, 'r') as configFile:
def readline(line): config = json.load(configFile)
line = line.split(' ', 1)
if len(line) == 1:
return [line[0], ""]
else:
return [line[0], line[1]]
includeList = [readline(line) for line in config.read().splitlines()]
except FileNotFoundError: except FileNotFoundError:
pass pass
if includeList is not None: if config is not None:
convertToMarkdownAndMerge(dir, includeList) convertToMarkdownAndMerge(dir, config)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
doc/intro.md {
spatialparams.hh "README.md" : [
problem.hh "doc/intro.md",
main.cc "spatialparams.hh",
doc/results.md "problem.hh",
"main.cc",
"doc/results.md"
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment