Skip to content

Commit 9d7b650

Browse files
authored
Sg scraper (#2419)
* improve sphinx-gallery case to handle the cases of multiple galleries, and separate source directory * simplified sphinx-gallery scraper * blacken * fixed test * removed unused import
1 parent e882f85 commit 9d7b650

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/python/plotly/plotly/io/_sg_scraper.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs):
4242
4343
Notes
4444
-----
45-
Add this function to the image scrapers
45+
Add this function to the image scrapers
4646
"""
47-
examples_dirs = gallery_conf["examples_dirs"]
48-
if isinstance(examples_dirs, (list, tuple)):
49-
examples_dirs = examples_dirs[0]
50-
pngs = sorted(glob(os.path.join(examples_dirs, "*.png")))
51-
htmls = sorted(glob(os.path.join(examples_dirs, "*.html")))
47+
examples_dir = os.path.dirname(block_vars["src_file"])
48+
pngs = sorted(glob(os.path.join(examples_dir, "*.png")))
49+
htmls = sorted(glob(os.path.join(examples_dir, "*.html")))
5250
image_path_iterator = block_vars["image_path_iterator"]
5351
image_names = list()
5452
seen = set()

packages/python/plotly/plotly/tests/test_orca/test_sg_scraper.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def test_scraper():
5252
tempdir = tempfile.mkdtemp()
5353
gallery_conf = {"src_dir": tempdir, "examples_dirs": here}
5454
names = iter(["0", "1", "2"])
55-
block_vars = {"image_path_iterator": names}
55+
block_vars = {
56+
"image_path_iterator": names,
57+
"src_file": os.path.join(here, "plot_example.py"),
58+
}
5659
execute_plotly_example()
5760
res = plotly_sg_scraper(block, block_vars, gallery_conf)
5861
shutil.rmtree(tempdir)

0 commit comments

Comments
 (0)