Get the path to the Chrome executable for Kaleido. This function is used by the `plotly_get_chrome` command line utility. Parameters ---------- path: str or Path or None The path to the directory where Chrome should be installed. If None, the default download pa
(path: Union[str, Path, None] = None)
| 867 | |
| 868 | |
| 869 | def get_chrome(path: Union[str, Path, None] = None) -> Path: |
| 870 | """ |
| 871 | Get the path to the Chrome executable for Kaleido. |
| 872 | This function is used by the `plotly_get_chrome` command line utility. |
| 873 | |
| 874 | Parameters |
| 875 | ---------- |
| 876 | path: str or Path or None |
| 877 | The path to the directory where Chrome should be installed. |
| 878 | If None, the default download path will be used. |
| 879 | """ |
| 880 | if not kaleido_available() or kaleido_major() < 1: |
| 881 | raise ValueError( |
| 882 | """ |
| 883 | This command requires Kaleido v1.0.0 or greater. |
| 884 | Install it using `pip install 'kaleido>=1.0.0'` or `pip install 'plotly[kaleido]'`." |
| 885 | """ |
| 886 | ) |
| 887 | |
| 888 | # Use default download path if no path was specified |
| 889 | if path: |
| 890 | user_specified_path = True |
| 891 | chrome_install_path = Path(path) # Ensure it's a Path object |
| 892 | else: |
| 893 | user_specified_path = False |
| 894 | from choreographer.cli.defaults import default_download_path |
| 895 | |
| 896 | chrome_install_path = default_download_path |
| 897 | |
| 898 | # If install path was chosen by user, make sure there is an existing directory |
| 899 | # located at chrome_install_path; otherwise fail |
| 900 | if user_specified_path: |
| 901 | if not chrome_install_path.exists(): |
| 902 | raise ValueError( |
| 903 | f""" |
| 904 | The specified install path '{chrome_install_path}' does not exist. |
| 905 | Please specify a path to an existing directory using the --path argument, |
| 906 | or omit the --path argument to use the default download path. |
| 907 | """ |
| 908 | ) |
| 909 | # Make sure the path is a directory |
| 910 | if not chrome_install_path.is_dir(): |
| 911 | raise ValueError( |
| 912 | f""" |
| 913 | The specified install path '{chrome_install_path}' already exists but is not a directory. |
| 914 | Please specify a path to an existing directory using the --path argument, |
| 915 | or omit the --path argument to use the default download path. |
| 916 | """ |
| 917 | ) |
| 918 | |
| 919 | return kaleido.get_chrome_sync(path=chrome_install_path) |
| 920 | |
| 921 | |
| 922 | __all__ = ["to_image", "write_image", "scope", "full_figure_for_development"] |
no test coverage detected