Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix issue where user-specified `color_continuous_scale` was ignored when template had `autocolorscale=True` [[#5439](https://github.com/plotly/plotly.py/pull/5439)], with thanks to @antonymilne for the contribution!
- Use presence of `COLAB_NOTEBOOK_ID` env var to enable Colab renderer instead of testing import of `google.colab` [[#5473](https://github.com/plotly/plotly.py/pull/5473)], with thanks to @kevineger for the contribution!
- Update tests to be compatible with numpy 2.4 [[#5522](https://github.com/plotly/plotly.py/pull/5522)], with thanks to @thunze for the contribution!
- Add default headers to be passed in to Kaleido v1.3.0 to avoid blocked Open Street Map tiles [#5588](https://github.com/plotly/plotly.py/pull/5588)]

### Updated
- The `__eq__` method for `graph_objects` classes now returns `NotImplemented` to give the other operand an opportunity to handle the comparison [[#5547](https://github.com/plotly/plotly.py/pull/5547)], with thanks to @RazerM for the contribution!
Expand Down
70 changes: 21 additions & 49 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,20 @@ def overwrite_plotlyjs_version_file(plotlyjs_version):
)


def request_json(url):
"""Get JSON data from a URL."""
def get_latest_commit_info(repo, branch):
"""Get latest commit info from GitHub API."""

url = "https://api.github.com/repos/{repo}/commits/{branch}".format(
repo=repo, branch=branch
)
req = requests.get(url)
return json.loads(req.content.decode("utf-8"))


def get_latest_publish_build_info(repo, branch):
"""Get build info from Circle CI."""

url = (
r"https://circleci.com/api/v1.1/project/github/"
r"{repo}/tree/{branch}?limit=100&filter=completed"
).format(repo=repo, branch=branch)

branch_jobs = request_json(url)

# Get most recent successful publish build for branch
builds = [
j
for j in branch_jobs
if j.get("workflows", {}).get("job_name", None) == "publish-dist"
and j.get("status", None) == "success"
]
build = builds[0]
assert req.status_code == 200, "Failed to fetch commit info: %s" % req.text
commit = req.json()

# Extract build info
return {p: build[p] for p in ["vcs_revision", "build_num", "committer_date"]}
return {
"vcs_revision": commit["sha"],
"committer_date": commit["commit"]["committer"]["date"],
}


def get_bundle_schema_local(local):
Expand All @@ -188,29 +174,15 @@ def get_bundle_schema_local(local):
return plotly_archive, plotly_bundle, plotly_schemas


def get_bundle_schema_urls(build_num):
"""Get URLs for required files."""

url = (
"https://circleci.com/api/v1.1/project/github/"
"plotly/plotly.js/{build_num}/artifacts"
).format(build_num=build_num)

artifacts = request_json(url)

# Find archive
archives = [a for a in artifacts if a.get("path", None) == "plotly.js.tgz"]
archive = archives[0]

# Find bundle
bundles = [a for a in artifacts if a.get("path", None) == "dist/plotly.min.js"]
bundle = bundles[0]
def get_github_urls(repo, revision):
"""Get URLs for required files from GitHub."""

# Find schema
schemas = [a for a in artifacts if a.get("path", None) == "dist/plot-schema.json"]
schema = schemas[0]
raw = f"https://raw.githubusercontent.com/{repo}/{revision}"
archive_url = f"https://github.com/{repo}/tarball/{revision}"
bundle_url = raw + "/dist/plotly.min.js"
schema_url = raw + "/dist/plot-schema.json"

return archive["url"], bundle["url"], schema["url"]
return archive_url, bundle_url, schema_url


def update_schema(plotly_js_version):
Expand Down Expand Up @@ -249,9 +221,9 @@ def update_plotlyjs(plotly_js_version, outdir):
def update_schema_bundle_from_master(args):
"""Update the plotly.js schema and bundle from master."""
if args.local is None:
build_info = get_latest_publish_build_info(args.devrepo, args.devbranch)
archive_url, bundle_url, schema_url = get_bundle_schema_urls(
build_info["build_num"]
build_info = get_latest_commit_info(args.devrepo, args.devbranch)
archive_url, bundle_url, schema_url = get_github_urls(
args.devrepo, build_info["vcs_revision"]
)

# Update bundle in package data
Expand Down
3 changes: 3 additions & 0 deletions plotly/io/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def __init__(self):
self.mathjax = None
self.topojson = None
self.plotlyjs = None
# This header is necessary to comply with Open Street Map tile policy:
# https://openstreetmap.github.io/owg-website/policies/tiles/#31-identification
self.headers = {"X-Requested-With": "plotly.py"}


defaults = _Defaults()
4 changes: 4 additions & 0 deletions plotly/io/_kaleido.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def to_image(
kopts["plotlyjs"] = defaults.plotlyjs
if defaults.mathjax:
kopts["mathjax"] = defaults.mathjax
if defaults.headers:
kopts["headers"] = defaults.headers

width = (
width
Expand Down Expand Up @@ -712,6 +714,8 @@ def write_images(
kopts["plotlyjs"] = defaults.plotlyjs
if defaults.mathjax:
kopts["mathjax"] = defaults.mathjax
if defaults.headers:
kopts["headers"] = defaults.headers
kaleido.write_fig_from_object_sync(
kaleido_specs,
kopts=kopts,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [

[project.optional-dependencies]
express = ["numpy>=1.22"]
kaleido = ["kaleido>=1.1.0"]
kaleido = ["kaleido>=1.3.0"]
dev_core = [
"pytest",
"requests",
Expand Down
Loading