Skip to content

Commit be59762

Browse files
committed
#57 fix tutorial gen script paths
1 parent ec27c7f commit be59762

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

infra/CreateMarkdownTutorial.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import os
6161
import sys
6262
import re
63+
import subprocess
6364

6465
# This had better match GenerateHowTo.py!
6566
HOWTO_TAG = "HOW_TO_TAG"
@@ -217,7 +218,12 @@ def ConvertTutorialToMarkdownText(test_file_path, test_file, other_files, revisi
217218
ugly_file_name = os.path.splitext(os.path.basename(test_file_path))[0]
218219
nice_file_name = re.sub(regex, " ", ugly_file_name)
219220

220-
link_path = f"https://github.com/Chaste/PyChaste/blob/develop/test/tutorials/{ugly_file_name}.py"
221+
root_dir = (
222+
subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("ascii").strip()
223+
)
224+
link_path = os.path.relpath(os.path.abspath(test_file_path), root_dir)
225+
link_path = f"https://github.com/Chaste/PyChaste/blob/develop/{link_path}"
226+
221227
page_header = f"""
222228
---
223229
title : "{nice_file_name}"

infra/GenerateWikiPages.py

+40-25
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
This script converts Python tutorials to markdown and jupyter notebook formats for use on the
3838
PyChaste website.
3939
"""
40+
4041
import argparse
4142
import fnmatch
4243
import ntpath
@@ -56,43 +57,57 @@
5657
)
5758
args = parser.parse_args()
5859

60+
# Get the repository root directory
61+
root_dir = (
62+
subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
63+
.decode("ascii")
64+
.strip()
65+
)
66+
5967
# Find all the tutorial files.
6068
tutorial_files = []
61-
for root, dirs, files in os.walk("../test"):
69+
for root, dirs, files in os.walk(os.path.join(root_dir, "test")):
6270
for file in files:
63-
if fnmatch.fnmatch(file, "Test*LiteratePaper*") or fnmatch.fnmatch(
64-
file, "Test*Tutorial*"
71+
if fnmatch.fnmatch(file, "Test*LiteratePaper*.py") or fnmatch.fnmatch(
72+
file, "Test*Tutorial*.py"
6573
):
66-
if not fnmatch.fnmatch(file, "*.pyc"):
67-
tutorial_files.append([root, file])
74+
tutorial_files.append((root, file))
6875

69-
# Get git revision
70-
revision = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
76+
# Get the git revision
77+
revision = (
78+
subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
79+
)
7180

7281
if args.format == "markdown":
73-
# Generate the markdown for each
74-
for eachFile in tutorial_files:
75-
outfile = (
76-
"../doc/tutorials/"
77-
+ os.path.splitext(ntpath.basename(eachFile[1]))[0]
78-
+ ".md"
82+
# Generate a markdown file for each tutorial
83+
for tutorial_file in tutorial_files:
84+
input_filepath = os.path.join(tutorial_file[0], tutorial_file[1])
85+
86+
output_filename = (
87+
os.path.splitext(os.path.basename(tutorial_file[1]))[0] + ".md"
7988
)
80-
inputfile = eachFile[0] + "/" + eachFile[1]
81-
launch_string = f"../infra/CreateMarkdownTutorial.py {inputfile} {outfile} --revision {revision}"
89+
output_filepath = os.path.join(
90+
root_dir, "doc", "tutorials", output_filename
91+
)
92+
93+
launch_string = f"{root_dir}/infra/CreateMarkdownTutorial.py {input_filepath} {output_filepath} --revision {revision}"
8294
os.system(launch_string)
8395

8496
elif args.format == "jupyter":
85-
# Generate the jupyter notebooks for each
86-
for eachFile in tutorial_files:
87-
outfile = (
88-
"../doc/tutorials/"
89-
+ os.path.splitext(ntpath.basename(eachFile[1]))[0]
90-
+ ".ipynb"
97+
# Generate a jupyter notebook for each tutorial
98+
for tutorial_file in tutorial_files:
99+
input_filepath = os.path.join(tutorial_file[0], tutorial_file[1])
100+
101+
output_filename = (
102+
os.path.splitext(os.path.basename(tutorial_file[1]))[0] + ".ipynb"
91103
)
92-
inputfile = eachFile[0] + "/" + eachFile[1]
93-
launch_string = (
94-
f"../infra/CreateJupyterNotebookTutorial.py {inputfile} {outfile}"
104+
output_filepath = os.path.join(
105+
root_dir, "doc", "tutorials", output_filename
95106
)
107+
108+
launch_string = f"{root_dir}/infra/CreateJupyterNotebookTutorial.py {input_filepath} {output_filepath}"
96109
os.system(launch_string)
97110

98-
subprocess.call(f"jupyter nbconvert --to notebook {outfile}", shell=True)
111+
subprocess.call(
112+
f"jupyter nbconvert --to notebook {output_filepath}", shell=True
113+
)

0 commit comments

Comments
 (0)