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

Skip to content

Commit 804b94c

Browse files
committed
STY: Combine declarations of example directories
1 parent 0d4ca31 commit 804b94c

File tree

3 files changed

+30
-37
lines changed

3 files changed

+30
-37
lines changed

doc/conf.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,27 @@
104104

105105
plot_formats = [('png', 80), ('hires.png', 200), ('pdf', 50)]
106106

107-
# Subdirectories in 'examples/' directory of package
108-
mpl_example_sections = ('lines_bars_and_markers',
109-
'shapes_and_collections',
110-
'statistics',
111-
'images_contours_and_fields',
112-
'pie_and_polar_charts',
113-
'color',
114-
'text_labels_and_annotations',
115-
'ticks_and_spines',
116-
'subplots_axes_and_figures',
117-
'specialty_plots',
118-
'showcase',
119-
'api', 'pylab_examples',
120-
'mplot3d', 'axes_grid',
121-
'units', 'widgets')
107+
# Subdirectories in 'examples/' directory of package and titles for gallery
108+
# TODO: Change to OrderedDict when Matplotlib drops support for Python < 2.7
109+
mpl_example_sections = (
110+
('lines_bars_and_markers', 'Lines, bars, and markers'),
111+
('shapes_and_collections', 'Shapes and collections'),
112+
('statistics', 'Statistical plots'),
113+
('images_contours_and_fields', 'Images, contours, and fields'),
114+
('pie_and_polar_charts', 'Pie and polar charts'),
115+
('color', 'Color'),
116+
('text_labels_and_annotations', 'Text, labels, and annotations'),
117+
('ticks_and_spines', 'Ticks and spines'),
118+
('subplots_axes_and_figures', 'Subplots, axes, and figures'),
119+
('specialty_plots', 'Specialty plots'),
120+
('showcase', 'Showcase'),
121+
('api', 'API'),
122+
('pylab_examples', 'pylab examples'),
123+
('mplot3d', 'mplot3d toolkit'),
124+
('axes_grid', 'axes_grid toolkit'),
125+
('units', 'units'),
126+
('widgets', 'widgets'),
127+
)
122128

123129

124130
# Github extension

doc/sphinxext/gen_gallery.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111

1212
exclude_example_sections = ['units']
1313
multiimage = re.compile('(.*?)(_\d\d){1,2}')
14-
custom_titles = {'pylab_examples' : 'pylab examples',
15-
'lines_bars_and_markers': 'Lines, bars, and markers',
16-
'shapes_and_collections': 'Shapes and collections',
17-
'statistics': 'Statistical plots',
18-
'images_contours_and_fields': 'Images, contours, and fields',
19-
'pie_and_polar_charts': 'Pie and polar charts',
20-
'text_labels_and_annotations': 'Text, labels, and annotations',
21-
'ticks_and_spines': 'Ticks and spines',
22-
'subplots_axes_and_figures': 'Subplots, axes, and figures',
23-
'specialty_plots': 'Specialty plots',
24-
'showcase': 'Showcase',
25-
'color': 'Color',
26-
'api': 'API',
27-
}
2814

2915
# generate a thumbnail gallery of examples
3016
gallery_template = """\
@@ -79,8 +65,9 @@ def gen_gallery(app, doctree):
7965
rootdir = 'plot_directive/mpl_examples'
8066

8167
example_sections = list(app.builder.config.mpl_example_sections)
82-
for section in exclude_example_sections:
83-
example_sections.remove(section)
68+
for i, (subdir, title) in enumerate(example_sections):
69+
if subdir in exclude_example_sections:
70+
example_sections.pop(i)
8471

8572
# images we want to skip for the gallery because they are an unusual
8673
# size that doesn't layout well in a table, or because they may be
@@ -96,8 +83,7 @@ def gen_gallery(app, doctree):
9683
rows = []
9784
toc_rows = []
9885

99-
for subdir in example_sections:
100-
title = custom_titles.get(subdir, subdir)
86+
for subdir, title in example_sections:
10187
rows.append(header_template.format(title=title, section=subdir))
10288
toc_rows.append(toc_template.format(title=title, section=subdir))
10389

doc/sphinxext/gen_rst.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ def generate_example_rst(app):
3333
os.makedirs(exampledir)
3434

3535
example_sections = list(app.builder.config.mpl_example_sections)
36-
for section in exclude_example_sections:
37-
example_sections.remove(section)
38-
36+
for i, (subdir, title) in enumerate(example_sections):
37+
if subdir in exclude_example_sections:
38+
example_sections.pop(i)
39+
example_subdirs, titles = zip(*example_sections)
3940

4041
datad = {}
4142
for root, subFolders, files in os.walk(rootdir):
@@ -122,7 +123,7 @@ def generate_example_rst(app):
122123

123124
fhsubdirIndex.write(' %s <%s>\n'%(os.path.basename(basename),rstfile))
124125

125-
do_plot = (subdir in example_sections
126+
do_plot = (subdir in example_subdirs
126127
and not noplot_regex.search(contents))
127128
if not do_plot:
128129
fhstatic = io.open(outputfile, 'w', encoding='utf-8')

0 commit comments

Comments
 (0)