Skip to content

Commit ec27c7f

Browse files
committed
#57 add revision to tutorial markdown generator
1 parent 05b1686 commit ec27c7f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

infra/CreateMarkdownTutorial.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def CodeBlockOpener(file_name):
192192
return '```' + highlight_code
193193

194194
def AddCodeOutput(file_name, code, output):
195-
output.append('\n\n## File name `%s` \n\n' % file_name)
195+
output.append('\n\n### File name %s \n\n' % file_name)
196196
output.append(CodeBlockOpener(file_name))
197197
output.append('\n'.join(code))
198198
output.append('\n```\n\n')
@@ -207,13 +207,17 @@ def ConvertTutorialToMarkdownText(test_file_path, test_file, other_files, revisi
207207
the contents as for test_file.
208208
"""
209209
if revision:
210-
revision = ' at revision r' + str(revision)
210+
revision_text = f' at revision [{revision[:8]}](https://github.com/Chaste/PyChaste/commit/{revision})'
211+
else:
212+
revision_text = ''
213+
211214
output = []
212215
# Header
213216
regex = re.compile(r'(?!^)(?=[A-Z])', re.MULTILINE)
214217
ugly_file_name = os.path.splitext(os.path.basename(test_file_path))[0]
215218
nice_file_name = re.sub(regex, " ", ugly_file_name)
216219

220+
link_path = f"https://github.com/Chaste/PyChaste/blob/develop/test/tutorials/{ugly_file_name}.py"
217221
page_header = f"""
218222
---
219223
title : "{nice_file_name}"
@@ -224,10 +228,9 @@ def ConvertTutorialToMarkdownText(test_file_path, test_file, other_files, revisi
224228
layout: "single"
225229
---
226230
227-
This tutorial is automatically generated from the file {test_file_path} {revision}.
231+
This tutorial is automatically generated from [{ugly_file_name}]({link_path}){revision_text}.
228232
Note that the code is given in full at the bottom of the page.
229233
230-
231234
"""
232235

233236
output.append(page_header)
@@ -244,7 +247,7 @@ def ConvertTutorialToMarkdownText(test_file_path, test_file, other_files, revisi
244247
if file_code:
245248
other_code[other_file[0]] = file_code
246249
# Now output the C++ code for all files
247-
output.append('\n\n# Code \nThe full code is given below\n')
250+
output.append('\n\n## Code \nThe full code is given below\n')
248251
AddCodeOutput(os.path.basename(test_file_path), test_code, output)
249252
for filename, code in other_code.items():
250253
AddCodeOutput(filename, code, output)

infra/GenerateWikiPages.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
if not fnmatch.fnmatch(file, "*.pyc"):
6767
tutorial_files.append([root, file])
6868

69+
# Get git revision
70+
revision = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
71+
6972
if args.format == "markdown":
7073
# Generate the markdown for each
7174
for eachFile in tutorial_files:
@@ -75,7 +78,7 @@
7578
+ ".md"
7679
)
7780
inputfile = eachFile[0] + "/" + eachFile[1]
78-
launch_string = f"../infra/CreateMarkdownTutorial.py {inputfile} {outfile}"
81+
launch_string = f"../infra/CreateMarkdownTutorial.py {inputfile} {outfile} --revision {revision}"
7982
os.system(launch_string)
8083

8184
elif args.format == "jupyter":

0 commit comments

Comments
 (0)