@@ -740,30 +740,86 @@ def full_figure_for_development(
740740
741741def get_chrome () -> None :
742742 """
743- Install Google Chrome for Kaleido
743+ Install Google Chrome for Kaleido (Required for Plotly image export).
744744 This function can be run from the command line using the command `plotly_get_chrome`
745745 defined in pyproject.toml
746746 """
747+
748+ usage = """
749+ Usage: plotly_get_chrome [-y] [--path PATH]
750+
751+ Installs Google Chrome for Plotly image export.
752+
753+ Options:
754+ -y Skip confirmation prompt
755+ --path PATH Specify the path to install Chrome. Must be a path to an existing directory.
756+ --help Show this message and exit.
757+ """
758+
747759 if not kaleido_available () or kaleido_major () < 1 :
748760 raise ValueError ("""
749761This command requires Kaleido v1.0.0 or greater.
750762Install it using `pip install 'kaleido>=1.0.0'` or `pip install 'plotly[kaleido]'`."
751763""" )
764+
765+ # Handle command line arguments
752766 import sys
753767
754- cli_yes = len (sys .argv ) > 1 and sys .argv [1 ] == "-y"
768+ cli_args = sys .argv
769+
770+ # Handle "-y" flag
771+ cli_yes = "-y" in cli_args
772+ if cli_yes :
773+ cli_args .remove ("-y" )
774+
775+ # Handle "--path" flag
776+ chrome_install_path = None
777+ user_specified_path = False
778+ if "--path" in cli_args :
779+ path_index = cli_args .index ("--path" ) + 1
780+ if path_index < len (cli_args ):
781+ chrome_install_path = cli_args [path_index ]
782+ cli_args .remove ("--path" )
783+ cli_args .remove (chrome_install_path )
784+ chrome_install_path = Path (chrome_install_path )
785+ user_specified_path = True
786+ else :
787+ from choreographer .cli .defaults import default_download_path
788+ chrome_install_path = default_download_path
789+
790+ # If install path was chosen by user, make sure there is an existing directory
791+ # located at chrome_install_path; otherwise fail
792+ if user_specified_path :
793+ if not chrome_install_path .exists ():
794+ raise ValueError (f"""
795+ The specified install path '{ chrome_install_path } ' does not exist.
796+ Please specify a path to an existing directory using the --path argument,
797+ or omit the --path argument to use the default download path.
798+ """ )
799+ # Make sure the path is a directory
800+ if not chrome_install_path .is_dir ():
801+ raise ValueError (f"""
802+ The specified install path '{ chrome_install_path } ' already exists but is not a directory.
803+ Please specify a path to an existing directory using the --path argument,
804+ or omit the --path argument to use the default download path.
805+ """ )
806+
807+ # If any arguments remain, command syntax was incorrect -- print usage and exit
808+ if len (cli_args ) > 1 :
809+ print (usage )
810+ sys .exit (1 )
811+
755812 if not cli_yes :
756- print (
757- "\n Plotly will install a copy of Google Chrome to be used for generating static images of plots.\n "
758- )
759- # TODO: Print path where Chrome will be installed
760- # print(f"Chrome will be installed at {chrome_download_path}\n")
813+ print (f"""
814+ Plotly will install a copy of Google Chrome to be used for generating static images of plots.
815+ Chrome will be installed at: { chrome_install_path }
816+ """ )
761817 response = input ("Do you want to proceed? [y/n] " )
762818 if not response or response [0 ].lower () != "y" :
763819 print ("Cancelled" )
764820 return
765821 print ("Installing Chrome for Plotly..." )
766- kaleido .get_chrome_sync ()
822+ kaleido .get_chrome_sync (path = chrome_install_path )
767823 print ("Chrome installed successfully." )
768824
769825
0 commit comments