# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           python 1.0

name                py-matplotlib-basemap
# When updating, check if Cython 3 is allowed and/or required and
# update or remove the dependency and PYTHONPATH below.
github.setup        matplotlib basemap 1.2.2 v rel
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            2

categories-append   graphics math
license             LGPL-2.1
maintainers         nomaintainer

description         matplotlib toolkit for plotting data on map projections
long_description    Matplotlib basemap is a matplotlib toolkit python library \
                    for plotting data on map projections

checksums           rmd160  f2c03ce587eb4cd7624bce7f524aa1165c4f0843 \
                    sha256  620ce82a32078865617b2085c5257398fa6086f4408601aa047828655ae450c6 \
                    size    132525148

python.versions     39

build.env-append    GEOS_DIR=${prefix}
destroot.env-append GEOS_DIR=${prefix}

universal_variant   no

if {${name} ne ${subport}} {
    compiler.c_standard 1999

    depends_build-append \
                    port:py${python.version}-setuptools

    depends_lib-append \
                    port:geos \
                    port:py${python.version}-matplotlib \
                    port:py${python.version}-numpy \
                    port:py${python.version}-pyproj \
                    port:py${python.version}-pyshp \
                    port:py${python.version}-six

    # The bundled src/_geoslib.c file is incompatible with Python 3.9
    # See https://github.com/matplotlib/basemap/issues/518
    # regenerate using cythonize
    if {${python.version} eq 39} {
        depends_build-append \
                    port:py${python.version}-cython-compat

        set compat_path [string replace ${python.pkgd} 0 [string length ${python.prefix}]-1 ${prefix}/lib/py${python.version}-cython-compat]
        build.env-append    PYTHONPATH=${compat_path}

        post-extract {
            delete ${worksrcpath}/src/_geoslib.c

            system -W ${worksrcpath} "env PYTHONPATH=${compat_path} ${prefix}/lib/py${python.version}-cython-compat/bin/cythonize -3 ${worksrcpath}/src/_geoslib.pyx"
        }
    }

    post-destroot {
        delete ${destroot}${python.pkgd}/mpl_toolkits/__init__.py
        delete ${destroot}${python.pkgd}/mpl_toolkits/__init__.pyc
    }

    test.run        yes
    python.test_framework
    test.cmd        ${python.bin} lib/mpl_toolkits/basemap/test.py
}