@@ -775,11 +775,13 @@ def full_figure_for_development(
775775        return  go .Figure (fig , skip_invalid = True )
776776
777777
778- def  get_chrome () ->  None :
778+ def  plotly_get_chrome () ->  None :
779779    """ 
780780    Install Google Chrome for Kaleido (Required for Plotly image export). 
781-     This function can be run from the command line using the command `plotly_get_chrome` 
782-     defined in pyproject.toml 
781+     This function is a command-line wrapper for `plotly.io.get_chrome()`. 
782+ 
783+     When running from the command line, use the command `plotly_get_chrome`; 
784+     when calling from Python code, use `plotly.io.get_chrome()`. 
783785    """ 
784786
785787    usage  =  """ 
@@ -813,16 +815,60 @@ def get_chrome() -> None:
813815
814816    # Handle "--path" flag 
815817    chrome_install_path  =  None 
816-     user_specified_path  =  False 
817818    if  "--path"  in  cli_args :
818819        path_index  =  cli_args .index ("--path" ) +  1 
819820        if  path_index  <  len (cli_args ):
820821            chrome_install_path  =  cli_args [path_index ]
821822            cli_args .remove ("--path" )
822823            cli_args .remove (chrome_install_path )
823824            chrome_install_path  =  Path (chrome_install_path )
824-             user_specified_path  =  True 
825+ 
826+     # If any arguments remain, command syntax was incorrect -- print usage and exit 
827+     if  len (cli_args ) >  1 :
828+         print (usage )
829+         sys .exit (1 )
830+ 
831+     if  not  cli_yes :
832+         print (
833+             f""" 
834+ Plotly will install a copy of Google Chrome to be used for generating static images of plots. 
835+ Chrome will be installed at: { chrome_install_path }  """ 
836+         )
837+         response  =  input ("Do you want to proceed? [y/n] " )
838+         if  not  response  or  response [0 ].lower () !=  "y" :
839+             print ("Cancelled" )
840+             return 
841+     print ("Installing Chrome for Plotly..." )
842+     exe_path  =  get_chrome (chrome_install_path )
843+     print ("Chrome installed successfully." )
844+     print (f"The Chrome executable is now located at: { exe_path }  " )
845+ 
846+ 
847+ def  get_chrome (path : Union [str , Path , None ] =  None ) ->  Path :
848+     """ 
849+     Get the path to the Chrome executable for Kaleido. 
850+     This function is used by the `plotly_get_chrome` command line utility. 
851+ 
852+     Parameters 
853+     ---------- 
854+     path: str or Path or None 
855+         The path to the directory where Chrome should be installed. 
856+         If None, the default download path will be used. 
857+     """ 
858+     if  not  kaleido_available () or  kaleido_major () <  1 :
859+         raise  ValueError (
860+             """ 
861+ This command requires Kaleido v1.0.0 or greater. 
862+ Install it using `pip install 'kaleido>=1.0.0'` or `pip install 'plotly[kaleido]'`." 
863+ """ 
864+         )
865+ 
866+     # Use default download path if no path was specified 
867+     if  path :
868+         user_specified_path  =  True 
869+         chrome_install_path  =  Path (path )  # Ensure it's a Path object 
825870    else :
871+         user_specified_path  =  False 
826872        from  choreographer .cli .defaults  import  default_download_path 
827873
828874        chrome_install_path  =  default_download_path 
@@ -848,25 +894,7 @@ def get_chrome() -> None:
848894""" 
849895            )
850896
851-     # If any arguments remain, command syntax was incorrect -- print usage and exit 
852-     if  len (cli_args ) >  1 :
853-         print (usage )
854-         sys .exit (1 )
855- 
856-     if  not  cli_yes :
857-         print (
858-             f""" 
859- Plotly will install a copy of Google Chrome to be used for generating static images of plots. 
860- Chrome will be installed at: { chrome_install_path }  """ 
861-         )
862-         response  =  input ("Do you want to proceed? [y/n] " )
863-         if  not  response  or  response [0 ].lower () !=  "y" :
864-             print ("Cancelled" )
865-             return 
866-     print ("Installing Chrome for Plotly..." )
867-     exe_path  =  kaleido .get_chrome_sync (path = chrome_install_path )
868-     print ("Chrome installed successfully." )
869-     print (f"The Chrome executable is now located at: { exe_path }  " )
897+     return  kaleido .get_chrome_sync (path = chrome_install_path )
870898
871899
872900__all__  =  ["to_image" , "write_image" , "scope" , "full_figure_for_development" ]
0 commit comments