@@ -572,6 +572,10 @@ def jupyterlite_build(app: Sphinx, error):
572
572
573
573
jupyterlite_dir = str (app .env .config .jupyterlite_dir )
574
574
575
+ jupyterlite_build_command_options : Dict [str , Any ] = (
576
+ app .env .config .jupyterlite_build_command_options
577
+ )
578
+
575
579
config = []
576
580
if jupyterlite_config :
577
581
config = ["--config" , jupyterlite_config ]
@@ -614,6 +618,22 @@ def jupyterlite_build(app: Sphinx, error):
614
618
jupyterlite_dir ,
615
619
]
616
620
621
+ if jupyterlite_build_command_options is not None :
622
+ for key , value in jupyterlite_build_command_options .items ():
623
+ # Check for conflicting options from the default command we use
624
+ # while building. We don't want to allow these to be overridden
625
+ # unless they are explicitly set through Sphinx config.
626
+ if key in ["contents" , "output-dir" , "lite-dir" ]:
627
+ jupyterlite_command_error_message = f"""
628
+ Additional option, { key } , passed to `jupyter lite build` through
629
+ `jupyterlite_build_command_options` in conf.py is already an existing
630
+ option. "contents", "output_dir", and "lite_dir" can be configured in
631
+ conf.py as described in the jupyterlite-sphinx documentation:
632
+ https://jupyterlite-sphinx.readthedocs.io/en/stable/configuration.html
633
+ """
634
+ raise RuntimeError (jupyterlite_command_error_message )
635
+ command .extend ([f"--{ key } " , str (value )])
636
+
617
637
assert all (
618
638
[isinstance (s , str ) for s in command ]
619
639
), f"Expected all commands arguments to be a str, got { command } "
@@ -669,6 +689,9 @@ def setup(app):
669
689
app .add_config_value ("jupyterlite_bind_ipynb_suffix" , True , rebuild = "html" )
670
690
app .add_config_value ("jupyterlite_silence" , True , rebuild = True )
671
691
692
+ # Pass a dictionary of additional options to the JupyterLite build command
693
+ app .add_config_value ("jupyterlite_build_command_options" , None , rebuild = "html" )
694
+
672
695
app .add_config_value ("global_enable_try_examples" , default = False , rebuild = True )
673
696
app .add_config_value ("try_examples_global_theme" , default = None , rebuild = True )
674
697
app .add_config_value ("try_examples_global_warning_text" , default = None , rebuild = True )
0 commit comments