Skip to content

Commit

Permalink
Split Examples toctree by subpackage in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
j4321 committed Oct 23, 2018
1 parent 317e8fd commit 63be42b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions docs/source/generate_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@
EXAMPLES_FILE = \
"Examples\n" \
"========\n" \
"\n" \
"{}"

TOCTREE_TEMPLATE = \
".. toctree::\n" \
" :maxdepth: 2\n\n" \
" :glob:\n" \
" :Caption: {}\n" \
"\n" \
" {}"

if not os.path.exists("examples"):
os.makedirs("examples")

example_files = list()

pkgs = {}

for example in EXAMPLES:
path = os.path.join(FOLDER, example)
with open(path) as fi:
Expand All @@ -40,6 +48,11 @@
if widget is None:
print("[WARNING] Could not determine imported widget in {}".format(example))
continue

pkg = package
if not pkg in pkgs:
pkgs[pkg] = []

package = package.split(".")
package = "" if len(package) != 2 else package[1]

Expand All @@ -54,9 +67,12 @@
with open(out_file, "w") as fo:
fo.write(text)

example_files.append(out_file.replace(".rst", "") + "\n")

with open("examples.rst", "w") as fo:
fo.write(EXAMPLES_FILE.format(" ".join(sorted(example_files))))
pkgs[pkg].append(out_file.replace(".rst", "") + "\n")

toctrees = []

for pkg in sorted(pkgs.keys()):
toctrees.append(TOCTREE_TEMPLATE.format(pkg, " ".join(sorted(pkgs[pkg]))))

with open("examples.rst", "w") as fo:
fo.write(EXAMPLES_FILE.format("\n\n".join(sorted(toctrees))))

0 comments on commit 63be42b

Please sign in to comment.