Skip to content

Commit

Permalink
Fix matplotlib 3.10.0 on emscripten 3.1.73 V2 (#1816)
Browse files Browse the repository at this point in the history
* Fix matplotlib 3.10.0 on emscripten 3.1.73
---------

Co-authored-by: emscripten-forge-bot <[email protected]>
  • Loading branch information
DerThorsten and emscripten-forge-bot authored Jan 30, 2025
1 parent 361e56c commit ec084c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
6 changes: 3 additions & 3 deletions recipes/recipes_emscripten/matplotlib/build-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ rm $SRC_DIR/emscripten.meson.cross.temp

cat $SRC_DIR/emscripten.meson.cross

export CFLAGS="$CFLAGS -sWASM_BIGINT"
export CXXFLAGS="$CXXFLAGS -sWASM_BIGINT"
export LDFLAGS="$LDFLAGS -sWASM_BIGINT"
export CFLAGS="$CFLAGS -sWASM_BIGINT -fexceptions"
export CXXFLAGS="$CXXFLAGS -sWASM_BIGINT -fexceptions"
export LDFLAGS="$LDFLAGS -sWASM_BIGINT -fexceptions"

${PYTHON} -m pip install . -vvv --no-deps --no-build-isolation \
-Csetup-args="--cross-file=$SRC_DIR/emscripten.meson.cross" \
Expand Down
31 changes: 31 additions & 0 deletions recipes/recipes_emscripten/matplotlib/patches/static-cast.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 1b919a42a6be3090d4553cafff8f0c0f9e221d60 Mon Sep 17 00:00:00 2001
From: Ian Thomas <[email protected]>
Date: Tue, 14 Jan 2025 14:34:34 +0000
Subject: [PATCH] Static cast patch

---
src/_backend_agg_wrapper.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/_backend_agg_wrapper.cpp b/src/_backend_agg_wrapper.cpp
index 269e2aaa9e..2bad7f4d0b 100644
--- a/src/_backend_agg_wrapper.cpp
+++ b/src/_backend_agg_wrapper.cpp
@@ -250,12 +250,12 @@ PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())

.def_buffer([](RendererAgg *renderer) -> py::buffer_info {
std::vector<py::ssize_t> shape {
- renderer->get_height(),
- renderer->get_width(),
+ static_cast<py::ssize_t>(renderer->get_height()),
+ static_cast<py::ssize_t>(renderer->get_width()),
4
};
std::vector<py::ssize_t> strides {
- renderer->get_width() * 4,
+ static_cast<py::ssize_t>(renderer->get_width() * 4),
4,
1
};
--
2.39.3 (Apple Git-146)
2 changes: 1 addition & 1 deletion recipes/recipes_emscripten/matplotlib/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source:
sha256: 825919da8957bbc19cec35caf8663b734d34af72a0b040c43b7d8c1b76fdcab7
patches:
- patches/fix-threading-and-font-cache.patch
- patches/static-cast.patch

build:
number: 0
Expand Down Expand Up @@ -39,7 +40,6 @@ outputs:
- pybind11
- freetype
- qhull

run:
- contourpy
- cycler
Expand Down
17 changes: 14 additions & 3 deletions recipes/recipes_emscripten/matplotlib/test_import_matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pytest
from pathlib import Path

def test_matplotlib(tmp_path):
tmp_path = Path(tmp_path)

def test_matplotlib():
from pathlib import Path

import matplotlib
import mpl_toolkits
Expand All @@ -12,4 +15,12 @@ def test_matplotlib():

fig = plt.figure()
plt.plot(np.sin(np.linspace(0, 20, 100)))
plt.show();
plt.savefig(tmp_path / 'test.png')
assert (tmp_path / 'test.png').exists()


def test_import_ft2font():
import matplotlib.ft2font

with pytest.raises(Exception):
matplotlib.ft2font.__path__

0 comments on commit ec084c2

Please sign in to comment.