For reasons that are a bit beyond me, `--host` and `PLATFORM_TRIPLET`
seem to be independent, in particular we've had an empty
`PLATFORM_TRIPLET`. This is unfortunate because `PLATFORM_TRIPLET`
is used to generate the SOABI config variable which in turn is used
to decide whether a .so file is a good match for loading. We'd like
for linux Pythons not to try to import emscripten .so files (it
raises `ImportError: some_file.so: invalid ELF header`). Similarly,
we'd like to avoid attempting to load linux .so files in wasm. These
platform tags are our friends.

Anyways, this PR sets `PLATFORM_TRIPLET` and ensures that .so files
built by pywasmcross are tagged with our SOABI tag.

I moved the .so file renaming from pywasmcross to buildpkg just
before running the post script. That is a better place to put it in
case the package wants to look at the .so file after linking it. It
might be surprised that we moved it.

I also improved the error message if we try to `loadWebAssemblyModule`
something that is actually say a Linux .so file and updated get_dynlibs
to filter out .so files that have an incompatible abi tag.
Set PLATFORM_TRIPLET, include platform in so names, only load compatible so files. For reasons that are a bit beyond me, `--host` and `PLATFORM_TRIPLET`
seem to be independent, in particular we've had an empty
`PLATFORM_TRIPLET`. This is unfortunate because `PLATFORM_TRIPLET`
is used to generate the SOABI config variable which in turn is used
to decide whether a .so file is a good match for loading. We'd like
for linux Pythons not to try to import emscripten .so files (it
raises `ImportError: some_file.so: invalid ELF header`). Similarly,
we'd like to avoid attempting to load linux .so files in wasm. These
platform tags are our friends.

Anyways, this PR sets `PLATFORM_TRIPLET` and ensures that .so files
built by pywasmcross are tagged with our SOABI tag.

I moved the .so file renaming from pywasmcross to buildpkg just
before running the post script. That is a better place to put it in
case the package wants to look at the .so file after linking it. It
might be surprised that we moved it.

I also improved the error message if we try to `loadWebAssemblyModule`
something that is actually say a Linux .so file and updated get_dynlibs
to filter out .so files that have an incompatible abi tag.
import os

from pyodide_build.testing import run_in_pyodide

if "CI" in os.environ:
    xfail_browsers = {"chrome": "scikit-image takes too long to load in CI "}
else:
    xfail_browsers = {}


@run_in_pyodide(
    packages=["scikit-image"], driver_timeout=40, xfail_browsers=xfail_browsers
)
def test_skimage():
    import numpy as np
    from skimage import color, data
    from skimage.util import view_as_blocks

    # get astronaut from skimage.data in grayscale
    l = color.rgb2gray(data.astronaut())
    assert l.size == 262144
    assert l.shape == (512, 512)

    # size of blocks
    block_shape = (4, 4)

    # see astronaut as a matrix of blocks (of shape block_shape)
    view = view_as_blocks(l, block_shape)
    assert view.shape == (128, 128, 4, 4)

    from skimage.filters import threshold_otsu

    to = threshold_otsu(l)
    assert to.hex() == "0x1.8e00000000000p-2"

    from skimage.color import rgb2gray
    from skimage.data import astronaut
    from skimage.filters import sobel
    from skimage.segmentation import felzenszwalb, quickshift, slic, watershed
    from skimage.util import img_as_float

    img = img_as_float(astronaut()[::2, ::2])

    segments_fz = felzenszwalb(img, scale=100, sigma=0.5, min_size=50)
    segments_slic = slic(img, n_segments=250, compactness=10, sigma=1)
    segments_quick = quickshift(img, kernel_size=3, max_dist=6, ratio=0.5)
    gradient = sobel(rgb2gray(img))
    segments_watershed = watershed(gradient, markers=250, compactness=0.001)

    assert len(np.unique(segments_fz)) == 194
    assert len(np.unique(segments_slic)) == 196
    assert len(np.unique(segments_quick)) == 695
    assert len(np.unique(segments_watershed)) == 256

import os

from pyodide_build.testing import run_in_pyodide

if "CI" in os.environ:
    xfail_browsers = {"chrome": "scikit-image takes too long to load in CI "}
else:
    xfail_browsers = {}


@run_in_pyodide(
    packages=["scikit-image"], driver_timeout=40, xfail_browsers=xfail_browsers
)
def test_skimage():
    import numpy as np
    from skimage import color, data
    from skimage.util import view_as_blocks

    # get astronaut from skimage.data in grayscale
    l = color.rgb2gray(data.astronaut())
    assert l.size == 262144
    assert l.shape == (512, 512)

    # size of blocks
    block_shape = (4, 4)

    # see astronaut as a matrix of blocks (of shape block_shape)
    view = view_as_blocks(l, block_shape)
    assert view.shape == (128, 128, 4, 4)

    from skimage.filters import threshold_otsu

    to = threshold_otsu(l)
    assert to.hex() == "0x1.8e00000000000p-2"

    from skimage.color import rgb2gray
    from skimage.data import astronaut
    from skimage.filters import sobel
    from skimage.segmentation import felzenszwalb, quickshift, slic, watershed
    from skimage.util import img_as_float

    img = img_as_float(astronaut()[::2, ::2])

    segments_fz = felzenszwalb(img, scale=100, sigma=0.5, min_size=50)
    segments_slic = slic(img, n_segments=250, compactness=10, sigma=1)
    segments_quick = quickshift(img, kernel_size=3, max_dist=6, ratio=0.5)
    gradient = sobel(rgb2gray(img))
    segments_watershed = watershed(gradient, markers=250, compactness=0.001)

    assert len(np.unique(segments_fz)) == 194
    assert len(np.unique(segments_slic)) == 196
    assert len(np.unique(segments_quick)) == 695
    assert len(np.unique(segments_watershed)) == 256
