@@ -572,6 +572,10 @@ def jupyterlite_build(app: Sphinx, error):
572572
573573 jupyterlite_dir = str (app .env .config .jupyterlite_dir )
574574
575+ jupyterlite_build_command_options : Dict [str , Any ] = (
576+ app .env .config .jupyterlite_build_command_options
577+ )
578+
575579 config = []
576580 if jupyterlite_config :
577581 config = ["--config" , jupyterlite_config ]
@@ -614,6 +618,22 @@ def jupyterlite_build(app: Sphinx, error):
614618 jupyterlite_dir ,
615619 ]
616620
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+
617637 assert all (
618638 [isinstance (s , str ) for s in command ]
619639 ), f"Expected all commands arguments to be a str, got { command } "
@@ -669,6 +689,9 @@ def setup(app):
669689 app .add_config_value ("jupyterlite_bind_ipynb_suffix" , True , rebuild = "html" )
670690 app .add_config_value ("jupyterlite_silence" , True , rebuild = True )
671691
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+
672695 app .add_config_value ("global_enable_try_examples" , default = False , rebuild = True )
673696 app .add_config_value ("try_examples_global_theme" , default = None , rebuild = True )
674697 app .add_config_value ("try_examples_global_warning_text" , default = None , rebuild = True )
0 commit comments