Skip to content

Commit

Permalink
Add package Cartopy (#3909)
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Jun 14, 2023
1 parent 71cc8bc commit e3789b8
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/project/changelog.md
Expand Up @@ -59,7 +59,8 @@ myst:
{pr}`3331`.
- New packages: sourmash {pr}`3635`, screed {pr}`3635`, bitstring {pr}`3635`,
deprecation {pr}`3635`, cachetools {pr}`3635`, xyzservices {pr}`3786`,
simplejson {pr}`3801`, protobuf {pr}`3813`, peewee {pr}`3897`.
simplejson {pr}`3801`, protobuf {pr}`3813`, peewee {pr}`3897`,
Cartopy {pr}`3909`, pyshp {pr}`3909`.
- Upgraded libmpfr to 4.2.0 {pr}`3756`.
- Upgraded scipy to 1.10.1 {pr}`3794`

Expand Down
39 changes: 39 additions & 0 deletions packages/Cartopy/meta.yaml
@@ -0,0 +1,39 @@
package:
name: Cartopy
version: 0.21.1
top-level:
- cartopy
source:
url: https://files.pythonhosted.org/packages/e8/11/ed3e364b3910f0951821e6b5a03a03ce425464b72aa3da08d47b78ae17bd/Cartopy-0.21.1.tar.gz
sha256: 89d5649712c8582231c6e11825a04c85f6f0cee94dbb89e4db23eabca1cc250a
patches:
- patches/0001-setup-geos-config.patch
test:
imports:
- cartopy
- cartopy.trace
- cartopy.mpl.geoaxes
- cartopy.crs
requirements:
host:
- geos
- numpy
run:
- shapely
- pyshp
- pyproj
- geos
- matplotlib
- scipy

build:
vendor-sharedlib: true
script: |
export GEOS_CONFIG=${WASM_LIBRARY_DIR}/bin/geos-config
echo ${GEOS_CONFIG}
about:
home: http://scitools.org.uk/cartopy
PyPI: https://pypi.org/project/Cartopy/
summary: A library providing cartographic tools for python
license: LGPL-3.0-or-later
20 changes: 20 additions & 0 deletions packages/Cartopy/patches/0001-setup-geos-config.patch
@@ -0,0 +1,20 @@
diff --git a/setup.py b/setup.py
index 8e061479..c1b592ff 100644
--- a/setup.py
+++ b/setup.py
@@ -81,11 +81,12 @@ def file_walk_relative(top, remove=''):

# GEOS
try:
- geos_version = subprocess.check_output(['geos-config', '--version'])
+ geos_config = os.environ.get("GEOS_CONFIG", "/src/packages/.libs/bin/geos-config")
+ geos_version = subprocess.check_output([geos_config, '--version'])
geos_version = tuple(int(v) for v in geos_version.split(b'.')
if 'dev' not in str(v))
- geos_includes = subprocess.check_output(['geos-config', '--includes'])
- geos_clibs = subprocess.check_output(['geos-config', '--clibs'])
+ geos_includes = subprocess.check_output([geos_config, '--includes'])
+ geos_clibs = subprocess.check_output([geos_config, '--clibs'])
except (OSError, ValueError, subprocess.CalledProcessError):
warnings.warn(
'Unable to determine GEOS version. Ensure you have %s or later '
46 changes: 46 additions & 0 deletions packages/Cartopy/test_cartopy.py
@@ -0,0 +1,46 @@
from functools import reduce

import pytest
from pytest_pyodide import run_in_pyodide

DECORATORS = [
pytest.mark.xfail_browsers(node="No supported matplotlib backends on node"),
pytest.mark.skip_refcount_check,
pytest.mark.skip_pyproxy_check,
pytest.mark.driver_timeout(60),
]


def matplotlib_test_decorator(f):
return reduce(lambda x, g: g(x), DECORATORS, f)


@pytest.mark.driver_timeout(60)
@run_in_pyodide(packages=["Cartopy"])
def test_imports(selenium):
import cartopy
import cartopy.trace

print(cartopy, cartopy.trace)


@matplotlib_test_decorator
@run_in_pyodide(packages=["Cartopy", "matplotlib", "pyodide-http"])
def test_matplotlib(selenium):
import io

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import pyodide_http

pyodide_http.patch_all()

ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()

fd = io.BytesIO()
plt.savefig(fd, format="svg")

content = fd.getvalue().decode("utf8")
assert len(content) == 128402
assert content.startswith("<?xml")
2 changes: 2 additions & 0 deletions packages/libproj/meta.yaml
Expand Up @@ -5,6 +5,8 @@ package:
source:
sha256: 76ed3d0c3a348a6693dfae535e5658bbfd47f71cb7ff7eb96d9f12f7e068b1cf
url: https://download.osgeo.org/proj/proj-8.2.1.tar.gz
patches:
- patches/0001-stod-empty-zero.patch

requirements:
host:
Expand Down
20 changes: 20 additions & 0 deletions packages/libproj/patches/0001-stod-empty-zero.patch
@@ -0,0 +1,20 @@
diff --git a/src/iso19111/internal.cpp b/src/iso19111/internal.cpp
index 4810202d..14fb8d83 100644
--- a/src/iso19111/internal.cpp
+++ b/src/iso19111/internal.cpp
@@ -242,6 +242,15 @@ bool ends_with(const std::string &str, const std::string &suffix) noexcept {
double c_locale_stod(const std::string &s) {

const auto s_size = s.size();
+ // Ensure that empty strings are parsed as 0.0, matching the behaviour of
+ // <cstdlib>'s strtod
+ // Without this patch, initialisation in Cartopy fails when an empty string
+ // is passed to this function and an invalid argument exception is thrown.
+ // This exception is not triggered in the non-Emscripten build.
+ if (s_size == 0) {
+ return 0.0;
+ }
+
// Fast path
if (s_size > 0 && s_size < 15) {
std::int64_t acc = 0;
16 changes: 16 additions & 0 deletions packages/pyshp/meta.yaml
@@ -0,0 +1,16 @@
package:
name: pyshp
version: 2.3.1
top-level:
- shapefile
source:
url: https://files.pythonhosted.org/packages/98/2f/68116db5b36b895c0450e3072b8cb6c2fac0359279b182ea97014d3c8ac0/pyshp-2.3.1-py2.py3-none-any.whl
sha256: 67024c0ccdc352ba5db777c4e968483782dfa78f8e200672a90d2d30fd8b7b49
test:
imports:
- shapefile
about:
home: https://github.com/GeospatialPython/pyshp
PyPI: https://pypi.org/project/pyshp
summary: Pure Python read/write support for ESRI Shapefile format
license: MIT

0 comments on commit e3789b8

Please sign in to comment.