From df9cf7f6b5b737e6d2044e9e8e01caccea461ba2 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Mon, 27 Apr 2020 17:53:32 +0200 Subject: [PATCH 1/5] improve sphinx-gallery case to handle the cases of multiple galleries, and separate source directory --- .../python/plotly/plotly/io/_sg_scraper.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py index 3f514a57ca8..14d92ad69f7 100644 --- a/packages/python/plotly/plotly/io/_sg_scraper.py +++ b/packages/python/plotly/plotly/io/_sg_scraper.py @@ -1,7 +1,7 @@ # This module defines an image scraper for sphinx-gallery # https://sphinx-gallery.github.io/ # which can be used by projects using plotly in their documentation. -import inspect, os +import inspect, os, pathlib import plotly from glob import glob @@ -45,10 +45,20 @@ def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs): Add this function to the image scrapers """ examples_dirs = gallery_conf["examples_dirs"] - if isinstance(examples_dirs, (list, tuple)): - examples_dirs = examples_dirs[0] - pngs = sorted(glob(os.path.join(examples_dirs, "*.png"))) - htmls = sorted(glob(os.path.join(examples_dirs, "*.html"))) + if not isinstance(examples_dirs, (list, tuple)): + examples_dirs = [examples_dirs] + pngs = [] + htmls = [] + for examples_dir in examples_dirs: + # sphinx hack, since the conf file can be either in the same dir as Makefile + # or in a subdirectory + if not os.path.isabs(examples_dir) and not os.path.exists(examples_dir): + examples_dir = pathlib.Path(*pathlib.Path(examples_dir).parts[1:]) + # Look for pngs and htmls in examples_dirs and subdirectories + pngs += sorted(glob(os.path.join(examples_dir, "*.png")) + + glob(os.path.join(examples_dir, "*", "*.png"))) + htmls += sorted(glob(os.path.join(examples_dir, "*.html")) + + glob(os.path.join(examples_dir, "*", "*.html"))) image_path_iterator = block_vars["image_path_iterator"] image_names = list() seen = set() From 3a44a64d5f85432fc7f125321a1db34a66a82ffa Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 28 Apr 2020 17:55:44 +0200 Subject: [PATCH 2/5] simplified sphinx-gallery scraper --- .../python/plotly/plotly/io/_sg_scraper.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py index 14d92ad69f7..8118b9210d2 100644 --- a/packages/python/plotly/plotly/io/_sg_scraper.py +++ b/packages/python/plotly/plotly/io/_sg_scraper.py @@ -44,21 +44,10 @@ def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs): ----- Add this function to the image scrapers """ - examples_dirs = gallery_conf["examples_dirs"] - if not isinstance(examples_dirs, (list, tuple)): - examples_dirs = [examples_dirs] - pngs = [] - htmls = [] - for examples_dir in examples_dirs: - # sphinx hack, since the conf file can be either in the same dir as Makefile - # or in a subdirectory - if not os.path.isabs(examples_dir) and not os.path.exists(examples_dir): - examples_dir = pathlib.Path(*pathlib.Path(examples_dir).parts[1:]) - # Look for pngs and htmls in examples_dirs and subdirectories - pngs += sorted(glob(os.path.join(examples_dir, "*.png")) + - glob(os.path.join(examples_dir, "*", "*.png"))) - htmls += sorted(glob(os.path.join(examples_dir, "*.html")) + - glob(os.path.join(examples_dir, "*", "*.html"))) + examples_dir = os.path.dirname(block_vars['src_file']) + print('----------------------') + pngs = sorted(glob(os.path.join(examples_dir, "*.png"))) + htmls = sorted(glob(os.path.join(examples_dir, "*.html"))) image_path_iterator = block_vars["image_path_iterator"] image_names = list() seen = set() From 70d096f30ec6109b58b69f7a087823add382c509 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 28 Apr 2020 17:56:06 +0200 Subject: [PATCH 3/5] blacken --- packages/python/plotly/plotly/io/_sg_scraper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py index 8118b9210d2..24d2f1c2205 100644 --- a/packages/python/plotly/plotly/io/_sg_scraper.py +++ b/packages/python/plotly/plotly/io/_sg_scraper.py @@ -44,8 +44,8 @@ def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs): ----- Add this function to the image scrapers """ - examples_dir = os.path.dirname(block_vars['src_file']) - print('----------------------') + examples_dir = os.path.dirname(block_vars["src_file"]) + print("----------------------") pngs = sorted(glob(os.path.join(examples_dir, "*.png"))) htmls = sorted(glob(os.path.join(examples_dir, "*.html"))) image_path_iterator = block_vars["image_path_iterator"] From a39f9f05fa7061222f66b48a1a82dc9cb431e7f0 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 28 Apr 2020 18:46:16 +0200 Subject: [PATCH 4/5] fixed test --- packages/python/plotly/plotly/io/_sg_scraper.py | 3 +-- .../python/plotly/plotly/tests/test_orca/test_sg_scraper.py | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py index 24d2f1c2205..72149f0192b 100644 --- a/packages/python/plotly/plotly/io/_sg_scraper.py +++ b/packages/python/plotly/plotly/io/_sg_scraper.py @@ -42,10 +42,9 @@ def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs): Notes ----- - Add this function to the image scrapers + Add this function to the image scrapers """ examples_dir = os.path.dirname(block_vars["src_file"]) - print("----------------------") pngs = sorted(glob(os.path.join(examples_dir, "*.png"))) htmls = sorted(glob(os.path.join(examples_dir, "*.html"))) image_path_iterator = block_vars["image_path_iterator"] diff --git a/packages/python/plotly/plotly/tests/test_orca/test_sg_scraper.py b/packages/python/plotly/plotly/tests/test_orca/test_sg_scraper.py index 837943ab45b..63eb1e2fc65 100644 --- a/packages/python/plotly/plotly/tests/test_orca/test_sg_scraper.py +++ b/packages/python/plotly/plotly/tests/test_orca/test_sg_scraper.py @@ -52,7 +52,10 @@ def test_scraper(): tempdir = tempfile.mkdtemp() gallery_conf = {"src_dir": tempdir, "examples_dirs": here} names = iter(["0", "1", "2"]) - block_vars = {"image_path_iterator": names} + block_vars = { + "image_path_iterator": names, + "src_file": os.path.join(here, "plot_example.py"), + } execute_plotly_example() res = plotly_sg_scraper(block, block_vars, gallery_conf) shutil.rmtree(tempdir) From 0c7510f3873166bea83b501b97833f11bc490b7c Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 28 Apr 2020 22:19:33 +0200 Subject: [PATCH 5/5] removed unused import --- packages/python/plotly/plotly/io/_sg_scraper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py index 72149f0192b..bec587d0ff6 100644 --- a/packages/python/plotly/plotly/io/_sg_scraper.py +++ b/packages/python/plotly/plotly/io/_sg_scraper.py @@ -1,7 +1,7 @@ # This module defines an image scraper for sphinx-gallery # https://sphinx-gallery.github.io/ # which can be used by projects using plotly in their documentation. -import inspect, os, pathlib +import inspect, os import plotly from glob import glob