MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / process

Function process

python/doc/source/jupytext_process.py:16–60  ·  view source on GitHub ↗

Convert Python demos in Jupytext 'light' into MyST markdown/ipynb. Uses Jupytext. These files can then be included in Sphinx documentation.

()

Source from the content-addressed store, hash-verified

14
15
16def process():
17 """Convert Python demos in Jupytext 'light' into MyST markdown/ipynb.
18
19 Uses Jupytext. These files can then be included in Sphinx
20 documentation.
21 """
22 # Directories to scan
23 subdirs = [pathlib.Path("../../demo")]
24
25 # Iterate over subdirectories containing demos
26 for subdir in subdirs:
27 # Make demo doc directory
28 demo_dir = pathlib.Path("./demos")
29 demo_dir.mkdir(parents=True, exist_ok=True)
30
31 # Process each demo using jupytext/myst
32 for demo in subdir.glob("**/demo*.py"):
33 python_demo = jupytext.read(demo)
34 myst_text = jupytext.writes(python_demo, fmt="myst")
35
36 # myst-parser does not process blocks with {code-cell}
37 myst_text = myst_text.replace("{code-cell}", "python")
38 myst_file = (demo_dir / demo.name).with_suffix(".md")
39 with open(myst_file, "w") as fw:
40 fw.write(myst_text)
41
42 ipynb_file = (demo_dir / demo.name).with_suffix(".ipynb")
43 jupytext.write(python_demo, ipynb_file, fmt="ipynb")
44
45 # Copy python demo files into documentation demo directory
46 shutil.copy(demo, demo_dir)
47
48 # If demo saves matplotlib images, run the demo to create
49 # images
50 code = demo.read_text()
51 if "savefig" in code:
52 demo = demo.resolve()
53 here = os.getcwd()
54 os.chdir(demo_dir)
55 runpy.run_path(str(demo))
56 os.chdir(here)
57
58 # Copy images used in demos
59 for file in subdir.glob("**/*.png"):
60 shutil.copy(file, demo_dir)
61
62
63if __name__ == "__main__":

Callers 1

Calls 2

writeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected