# -*- 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           python 1.0
PortGroup           mpi 1.0

name                py-netcdf4
python.rootname     netCDF4
version             1.7.2
revision            1

categories-append   science
license             MIT
maintainers         {fastmail.fm:jswhit @jswhit} openmaintainer

description         Python/numpy interface to netCDF
long_description    netCDF version 4 has many features not found in \
                    earlier versions of the library and is implemented \
                    on top of HDF5. This module can read and write files \
                    in both the new netCDF 4 and the old netCDF \
                    3 format, and can create files that are readable by \
                    HDF5 clients.

homepage            https://unidata.github.io/netcdf4-python/

distname            netcdf4-${version}

checksums           rmd160  1465d546f8fb95bffa306b05b5628bab3d4b7cd2 \
                    sha256  a4c6375540b19989896136943abb6d44850ff6f1fa7d3f063253b1ad3f8b7fce \
                    size    835064

mpi.enforce_variant netcdf
mpi.setup

build.env-append    USE_NCCONFIG=1
destroot.env-append USE_NCCONFIG=1

python.versions     39 310 311 312

if {${name} ne ${subport}} {
    patchfiles      patch-numpy-pyproject.toml.diff

    depends_build-append \
                    path:bin/cython-${python.branch}:py${python.version}-cython \
                    port:py${python.version}-oldest-supported-numpy \
                    port:py${python.version}-setuptools_scm

    depends_lib-append \
                    port:netcdf \
                    port:py${python.version}-certifi \
                    port:py${python.version}-cftime \
                    port:hdf5 \
                    port:py${python.version}-numpy

    depends_test-append \
                    path:bin/cython-${python.branch}:py${python.version}-cython \
                    port:py${python.version}-packaging

    pre-configure {
        # py-netcdf4's setup.py uses nc-config for flags and libs but not compiler
        configure.cc    {*}[exec ${prefix}/bin/nc-config --cc]
    }

    test.run        yes

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} Changelog \
           README.md ${destroot}${docdir}
    }
}