Skip to content

Commit db0feea

Browse files
authored
Merge branch 'main' into secondary-y-shared
2 parents a83c6b4 + 4cd70ad commit db0feea

File tree

11 files changed

+94
-38
lines changed

11 files changed

+94
-38
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## Unreleased
5+
## [6.2.0] - 2025-06-26
66

7+
### Added
8+
- Add SRI (Subresource Integrity) hash support for CDN script tags when using `include_plotlyjs='cdn'`. This enhances security by ensuring browser verification of CDN-served plotly.js files [[#5165](https://github.com/plotly/plotly.py/pull/5165)] (with thanks to @ddworken)
9+
10+
### Fixed
11+
- Allow setting Plotly.js path via `pio.defaults` [[#5207](https://github.com/plotly/plotly.py/pull/5207)]
12+
13+
### Changed
14+
- Refactor validation code to reduce bundle size [[#5214](https://github.com/plotly/plotly.py/pull/5214)] (with thanks to @bmaranville)
715
- Add deprecation warnings when using Kaleido v0 or deprecated image export features [[#5177](https://github.com/plotly/plotly.py/pull/5236)]
816

917
## [6.1.2] - 2025-05-27
@@ -24,9 +32,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2432
- Add support for Kaleido>=v1.0.0 for image generation [[#5062](https://github.com/plotly/plotly.py/pull/5062), [#5177](https://github.com/plotly/plotly.py/pull/5177)]
2533
- Reduce package bundle size by 18-24% via changes to code generation [[#4978](https://github.com/plotly/plotly.py/pull/4978)]
2634

27-
### Added
28-
- Add SRI (Subresource Integrity) hash support for CDN script tags when using `include_plotlyjs='cdn'`. This enhances security by ensuring browser verification of CDN-served plotly.js files [[#PENDING](https://github.com/plotly/plotly.py/pull/PENDING)]
29-
3035
### Fixed
3136
- Fix third-party widget display issues in v6 [[#5102](https://github.com/plotly/plotly.py/pull/5102)]
3237
- Add handling for case where `jupyterlab` or `notebook` is not installed [[#5104](https://github.com/plotly/plotly.py/pull/5104/files)]

doc/apidoc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# The short X.Y version
2525
version = ""
2626
# The full version, including alpha/beta/rc tags
27-
release = "6.0.1"
27+
release = "6.2.0"
2828

2929

3030
# -- General configuration ---------------------------------------------------

doc/python/static-image-export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ The following settings are available.
269269

270270
`default_scale`: The default image scale factor applied on image export.
271271

272-
`default_format`: The default image format used on export. One of "png", "jpeg", "webp", "svg", or "pdf". ("eps" support is deprecated and available with Kaleido v0 only)
272+
`default_format`: The default image format used on export. One of "png", "jpeg", "webp", "svg", or "pdf". ("eps" support is available with Kaleido v0 only)
273273

274274
`mathjax`: Location of the MathJax bundle needed to render LaTeX characters. Defaults to a CDN location. If fully offline export is required, set this to a local MathJax bundle.
275275

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plotly==6.0.1
1+
plotly==6.2.0
22
anywidget
33
cufflinks==0.17.3
44
dash-bio

plotly/basedatatypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,8 +3404,8 @@ def show(self, *args, **kwargs):
34043404
plot is. The default is set in plotly.js.
34053405
34063406
height: int or float
3407-
An integer or float that determines the number of pixels wide the
3408-
plot is. The default is set in plotly.js.
3407+
An integer or float specifying the height of the plot in pixels.
3408+
The default is set in plotly.js.
34093409
34103410
config: dict
34113411
A dict of parameters to configure the figure. The defaults are set

plotly/io/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ._html import to_html, write_html
1818
from ._renderers import renderers, show
1919
from . import base_renderers
20-
from ._kaleido import defaults
20+
from ._kaleido import defaults, get_chrome
2121

2222
__all__ = [
2323
"to_image",
@@ -38,6 +38,7 @@
3838
"base_renderers",
3939
"full_figure_for_development",
4040
"defaults",
41+
"get_chrome",
4142
]
4243
else:
4344
__all__, __getattr__, __dir__ = relative_import(
@@ -59,6 +60,7 @@
5960
"._renderers.renderers",
6061
"._renderers.show",
6162
"._kaleido.defaults",
63+
"._kaleido.get_chrome",
6264
],
6365
)
6466

plotly/io/_kaleido.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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"]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ classifiers = [
3232
]
3333
requires-python = ">=3.8"
3434
license = {file="LICENSE.txt"}
35-
version = "6.1.2"
35+
version = "6.2.0"
3636
dependencies = [
3737
"narwhals>=1.15.1",
3838
"packaging"
@@ -83,7 +83,7 @@ dev = [
8383
]
8484

8585
[project.scripts]
86-
plotly_get_chrome = "plotly.io._kaleido:get_chrome"
86+
plotly_get_chrome = "plotly.io._kaleido:plotly_get_chrome"
8787

8888
[tool.pytest.ini_options]
8989
markers = [

tests/test_io/test_to_from_plotly_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def numpy_unicode_array(request):
109109
params=[
110110
datetime.datetime(2003, 7, 12, 8, 34, 22),
111111
datetime.datetime.now(),
112-
np.datetime64(datetime.datetime.utcnow()),
112+
np.datetime64(datetime.datetime.now(datetime.timezone.utc)),
113113
pd.Timestamp(datetime.datetime.now()),
114114
eastern.localize(datetime.datetime(2003, 7, 12, 8, 34, 22)),
115115
eastern.localize(datetime.datetime.now()),

tests/test_optional/test_kaleido/test_kaleido.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,24 @@ def test_fig_to_image():
293293
mock_calc_fig.assert_called_once()
294294
args, _ = mock_calc_fig.call_args
295295
assert args[0] == test_fig.to_dict()
296+
297+
298+
def test_get_chrome():
299+
"""Test that plotly.io.get_chrome() can be called."""
300+
301+
if not kaleido_available() or kaleido_major() < 1:
302+
# Test that ValueError is raised when Kaleido requirements aren't met
303+
with pytest.raises(
304+
ValueError, match="This command requires Kaleido v1.0.0 or greater"
305+
):
306+
pio.get_chrome()
307+
else:
308+
# Test normal operation when Kaleido v1+ is available
309+
with patch(
310+
"plotly.io._kaleido.kaleido.get_chrome_sync",
311+
return_value="/mock/path/to/chrome",
312+
) as mock_get_chrome:
313+
pio.get_chrome()
314+
315+
# Verify that kaleido.get_chrome_sync was called
316+
mock_get_chrome.assert_called_once()

0 commit comments

Comments
 (0)