@@ -122,24 +122,6 @@ def _bool_eval(x):
122
122
return bool (x )
123
123
124
124
125
- def parse_config (app , check_keys = True ):
126
- """Process the Sphinx Gallery configuration."""
127
- plot_gallery = _bool_eval (app .builder .config .plot_gallery )
128
- src_dir = app .builder .srcdir
129
- abort_on_example_error = _bool_eval (
130
- app .builder .config .abort_on_example_error )
131
- lang = app .builder .config .highlight_language
132
- gallery_conf = _complete_gallery_conf (
133
- app .config .sphinx_gallery_conf , src_dir , plot_gallery ,
134
- abort_on_example_error , lang , app .builder .name , app ,
135
- check_keys )
136
-
137
- # this assures I can call the config in other places
138
- app .config .sphinx_gallery_conf = gallery_conf
139
- app .config .html_static_path .append (glr_path_static ())
140
- return gallery_conf
141
-
142
-
143
125
def _update_gallery_conf (gallery_conf ):
144
126
"""Update gallery config.
145
127
@@ -151,19 +133,24 @@ def _update_gallery_conf(gallery_conf):
151
133
gallery_conf ['exclude_implicit_doc_regex' ] = exclude_regex
152
134
153
135
154
- def _complete_gallery_conf (sphinx_gallery_conf , src_dir , plot_gallery ,
155
- abort_on_example_error , lang = 'python' ,
156
- builder_name = 'html' , app = None , check_keys = True ):
136
+ def _complete_gallery_conf_builder_inited (
137
+ sphinx_gallery_conf , src_dir , plot_gallery = True ,
138
+ abort_on_example_error = False , lang = 'python' ,
139
+ builder_name = 'html' ):
140
+ sphinx_gallery_conf .update (plot_gallery = plot_gallery )
141
+ sphinx_gallery_conf .update (abort_on_example_error = abort_on_example_error )
142
+ sphinx_gallery_conf ['src_dir' ] = src_dir
143
+ lang = lang if lang in ('python' , 'python3' , 'default' ) else 'python'
144
+ sphinx_gallery_conf ['lang' ] = lang
145
+ # Make it easy to know which builder we're in
146
+ sphinx_gallery_conf ['builder_name' ] = builder_name
147
+
148
+
149
+ def _complete_gallery_conf_config_inited (sphinx_gallery_conf , app = None ,
150
+ check_keys = True ):
157
151
gallery_conf = copy .deepcopy (DEFAULT_GALLERY_CONF )
158
152
options = sorted (gallery_conf )
159
- # sphinx-autoapi can run before our config filling can occur, which
160
- # when used with show_api_usage=True can cause us to add this early.
161
- # In theory we could bump our priority above theirs, but this could have
162
- # unintented consequences.
163
- ignore_keys = ('_sg_api_entries' ,)
164
- extra_keys = sorted (
165
- (set (sphinx_gallery_conf ) - set (options )) - set (ignore_keys )
166
- )
153
+ extra_keys = sorted (set (sphinx_gallery_conf ) - set (options ))
167
154
if extra_keys and check_keys :
168
155
msg = 'Unknown key(s) in sphinx_gallery_conf:\n '
169
156
for key in extra_keys :
@@ -176,13 +163,10 @@ def _complete_gallery_conf(sphinx_gallery_conf, src_dir, plot_gallery,
176
163
msg += '\n '
177
164
raise ConfigError (msg .strip ())
178
165
gallery_conf .update (sphinx_gallery_conf )
179
- gallery_conf .update (plot_gallery = plot_gallery )
180
- gallery_conf .update (abort_on_example_error = abort_on_example_error )
181
166
# XXX anything that can only be a bool (rather than str) should probably be
182
167
# evaluated this way as it allows setting via -D on the command line
183
168
for key in ('promote_jupyter_magic' , 'run_stale_examples' ,):
184
169
gallery_conf [key ] = _bool_eval (gallery_conf [key ])
185
- gallery_conf ['src_dir' ] = src_dir
186
170
gallery_conf ['app' ] = app
187
171
188
172
# Check capture_repr
@@ -318,8 +302,6 @@ def call_memory(func):
318
302
"['before', 'after', 'both'], "
319
303
'got %r' % gallery_conf ['reset_modules_order' ])
320
304
321
- lang = lang if lang in ('python' , 'python3' , 'default' ) else 'python'
322
- gallery_conf ['lang' ] = lang
323
305
del resetters
324
306
325
307
# Ensure the first cell text is a string if we have it
@@ -357,8 +339,6 @@ def call_memory(func):
357
339
"values: %s, got: %s."
358
340
% (accepted_keys , key ))
359
341
360
- # Make it easy to know which builder we're in
361
- gallery_conf ['builder_name' ] = builder_name
362
342
gallery_conf ['titles' ] = {}
363
343
# Ensure 'backreferences_dir' is str, pathlib.Path or None
364
344
backref = gallery_conf ['backreferences_dir' ]
@@ -376,7 +356,6 @@ def call_memory(func):
376
356
gallery_conf ['binder' ] = check_binder_conf (gallery_conf ['binder' ])
377
357
378
358
# jupyterlite
379
- print ('_complete_gallery_conf' , gallery_conf .get ('jupyterlite' ))
380
359
gallery_conf ['jupyterlite' ] = check_jupyterlite_conf (
381
360
gallery_conf .get ('jupyterlite' , {}), app )
382
361
@@ -503,7 +482,7 @@ def generate_gallery_rst(app):
503
482
"""
504
483
505
484
logger .info ('generating gallery...' , color = 'white' )
506
- gallery_conf = parse_config ( app )
485
+ gallery_conf = app . config . sphinx_gallery_conf
507
486
508
487
seen_backrefs = set ()
509
488
@@ -737,9 +716,6 @@ def write_computation_times(gallery_conf, target_dir, costs):
737
716
738
717
739
718
def write_api_entries (app , what , name , obj , options , lines ):
740
- # sphinx-autoapi can do this before we manage to complete our config
741
- if 'show_api_usage' not in app .config .sphinx_gallery_conf :
742
- app .config .sphinx_gallery_conf ['show_api_usage' ] = False
743
719
if app .config .sphinx_gallery_conf ['show_api_usage' ] is False :
744
720
return
745
721
if '_sg_api_entries' not in app .config .sphinx_gallery_conf :
@@ -1065,7 +1041,7 @@ def _parse_failures(gallery_conf):
1065
1041
# filter from examples actually run
1066
1042
passing_unexpectedly = [
1067
1043
src_file for src_file in passing_unexpectedly
1068
- if re .search (gallery_conf . get ( 'filename_pattern' ) , src_file )]
1044
+ if re .search (gallery_conf [ 'filename_pattern' ] , src_file )]
1069
1045
return failing_as_expected , failing_unexpectedly , passing_unexpectedly
1070
1046
1071
1047
@@ -1187,12 +1163,38 @@ def default_getter(conf):
1187
1163
return default_getter
1188
1164
1189
1165
1166
+ def normalize_gallery_conf_config_inited (app , config , check_keys = True ):
1167
+ new_sphinx_gallery_conf = _complete_gallery_conf_config_inited (
1168
+ config .sphinx_gallery_conf , app = app , check_keys = check_keys )
1169
+ config .sphinx_gallery_conf = new_sphinx_gallery_conf
1170
+ config .html_static_path .append (glr_path_static ())
1171
+
1172
+
1173
+ def normalize_gallery_conf_builder_inited (app ):
1174
+ plot_gallery = _bool_eval (app .builder .config .plot_gallery )
1175
+ src_dir = app .builder .srcdir
1176
+ abort_on_example_error = _bool_eval (
1177
+ app .builder .config .abort_on_example_error )
1178
+ lang = app .builder .config .highlight_language
1179
+ _complete_gallery_conf_builder_inited (
1180
+ app .config .sphinx_gallery_conf ,
1181
+ src_dir ,
1182
+ plot_gallery = plot_gallery ,
1183
+ abort_on_example_error = abort_on_example_error ,
1184
+ lang = lang ,
1185
+ builder_name = app .builder .name
1186
+ )
1187
+
1188
+
1190
1189
def setup (app ):
1191
1190
"""Setup Sphinx-Gallery sphinx extension"""
1192
1191
app .add_config_value ('sphinx_gallery_conf' , DEFAULT_GALLERY_CONF , 'html' )
1193
1192
for key in ['plot_gallery' , 'abort_on_example_error' ]:
1194
1193
app .add_config_value (key , get_default_config_value (key ), 'html' )
1195
1194
1195
+ # Early normalization of sphinx_gallery_conf at config-inited
1196
+ app .connect ('config-inited' , normalize_gallery_conf_config_inited ,
1197
+ priority = 10 )
1196
1198
# set small priority value, so that pre_configure_jupyterlite_sphinx is
1197
1199
# called before jupyterlite_sphinx config-inited
1198
1200
app .connect (
@@ -1213,6 +1215,9 @@ def setup(app):
1213
1215
1214
1216
imagesg_addnode (app )
1215
1217
1218
+ # Early normalization of sphinx_gallery_conf at builder-inited
1219
+ app .connect ('builder-inited' , normalize_gallery_conf_builder_inited ,
1220
+ priority = 10 )
1216
1221
app .connect ('builder-inited' , generate_gallery_rst )
1217
1222
app .connect ('build-finished' , copy_binder_files )
1218
1223
app .connect ('build-finished' , create_jupyterlite_contents )
0 commit comments