From f1c50c3f9af8535545f0e398dda9f03e38a41ce5 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 1 May 2023 09:49:26 +0100 Subject: [PATCH] not a fan of nested functions --- openpower/mdwn_inline.py | 78 +++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/openpower/mdwn_inline.py b/openpower/mdwn_inline.py index 6ff024924..e072ecb1b 100755 --- a/openpower/mdwn_inline.py +++ b/openpower/mdwn_inline.py @@ -28,44 +28,47 @@ temp_output_file = output_file + '.tmp' file_path = os.path.abspath(__file__) openpower_path = os.path.split(file_path)[0] wiki_path = os.path.split(openpower_path)[0] -def body(o, print=print): - def recursive_inline(f, input_name, depth): - assert depth < 10, "probably found an [[!inline]]-loop" - for line in f.readlines(): - if input_name.endswith("comparison_table.tex") and \ - line.startswith("\begin{itemize}"): - o.write(line) - o.write("\\itemsep -0.3em\n") - continue - if not line.startswith("[[!inline"): - o.write(line) - continue - print(line.strip()) - # assume first thing is pagename - line = line.split('"') - fname = line[1] - print(f"\tdepth={depth}: {fname}") - if fname.endswith(".py"): - if fname.startswith("gf_reference"): - with open_tracked( - wiki_path + "/../nmigen-gf/" + fname) as inc: - recursive_inline(inc, fname, depth + 1) - else: - with open_tracked(wiki_path + "/" + fname) as inc: - recursive_inline(inc, fname, depth + 1) + + +def recursive_inline(f, input_name, depth): + assert depth < 10, "probably found an [[!inline]]-loop" + for line in f.readlines(): + if input_name.endswith("comparison_table.tex") and \ + line.startswith("\begin{itemize}"): + o.write(line) + o.write("\\itemsep -0.3em\n") + continue + if not line.startswith("[[!inline"): + o.write(line) + continue + print(line.strip()) + # assume first thing is pagename + line = line.split('"') + fname = line[1] + print(f"\tdepth={depth}: {fname}") + if fname.endswith(".py"): + if fname.startswith("gf_reference"): + with open_tracked( + wiki_path + "/../nmigen-gf/" + fname) as inc: + recursive_inline(inc, fname, depth + 1) + else: + with open_tracked(wiki_path + "/" + fname) as inc: + recursive_inline(inc, fname, depth + 1) + else: + if fname.endswith(".mdwn"): + with open_tracked(wiki_path + "/" + fname) as inc: + recursive_inline(inc, fname, depth + 1) + elif fname == 'openpower/isatables/fields.text': + with open_tracked( + wiki_path + "/../openpower-isa/" + fname) as inc: + recursive_inline(inc, fname, depth + 1) else: - if fname.endswith(".mdwn"): - with open_tracked(wiki_path + "/" + fname) as inc: - recursive_inline(inc, fname, depth + 1) - elif fname == 'openpower/isatables/fields.text': - with open_tracked( - wiki_path + "/../openpower-isa/" + fname) as inc: - recursive_inline(inc, fname, depth + 1) - else: - with open_tracked( - wiki_path + "/" + fname + ".mdwn") as inc: - recursive_inline(inc, fname, depth + 1) + with open_tracked( + wiki_path + "/" + fname + ".mdwn") as inc: + recursive_inline(inc, fname, depth + 1) + +def body(o, print=print): with open_tracked(sys.argv[1], "r") as f: recursive_inline(f, sys.argv[1], 0) @@ -79,4 +82,5 @@ if deps_only: else: with open(temp_output_file, "w") as o: body(o) - os.rename(temp_output_file, output_file) \ No newline at end of file + os.rename(temp_output_file, output_file) + -- 2.30.2