Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68f00b7

Browse files
committed
doc generation: handle example scripts with __name__ == "__main__"
1 parent 2b6ac8a commit 68f00b7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def run_code(code, code_path, ns=None, function_name=None):
467467
exec "import numpy as np\nfrom matplotlib import pyplot as plt\n" in ns
468468
else:
469469
exec setup.config.plot_pre_code in ns
470+
if "__main__" in code:
471+
exec "__name__ = '__main__'" in ns
470472
exec code in ns
471473
if function_name is not None:
472474
exec function_name + "()" in ns
@@ -746,7 +748,7 @@ def run(arguments, content, options, state_machine, state, lineno):
746748
# copy image files to builder's output directory, if necessary
747749
if not os.path.exists(dest_dir):
748750
cbook.mkdirs(dest_dir)
749-
751+
750752
for code_piece, images in results:
751753
for img in images:
752754
for fn in img.filenames():

0 commit comments

Comments
 (0)