# -*- 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-tables
version             3.9.2
categories-append   science
license             BSD

python.versions     27 37 38 39 310 311

maintainers         nomaintainer

description         Package for managing hierarchical datasets
long_description    PyTables is a package for managing hierarchical datasets \
                    and designed to efficiently and easily cope with \
                    extremely large amounts of data

homepage            https://www.pytables.org/

checksums           md5 7557f426070725fd93cf33740eb3d229 \
                    rmd160 9c5ff800403559316b9d6b6c766d86b219f38177 \
                    sha256 d470263c2e50c4b7c8635a0d99ac1ff2f9e704c24d71e5fa33c4529e7d0ad9c3

mpi.setup

if {${name} ne ${subport}} {
    # Last version that supports python 2.7
    if {${python.version} == 27} {
        version     3.5.2
        revision    8
        checksums   rmd160 9e5aa9f3b270888c853eb5f30cd6461a362bb1c1 \
                    sha256 b220e32262bab320aa41d33125a7851ff898be97c0de30b456247508e2cc33c2 \
                    size   7825372
    } elseif {${python.version} == 37} {
        version     3.7.0
        revision    1
        checksums   md5 d67a870ee90748a260e3ab3d6774533a \
                    rmd160 19f19a990839ac70ceb0a3c779c56fa7b764ef76 \
                    sha256 e92a887ad6f2a983e564a69902de4a7645c30069fc01abd353ec5da255c5e1fe
    } elseif {${python.version} == 38} {
        version     3.8.0
        revision    1
        checksums   md5 83b2e54523cd83f7a9efbfbb8aa37227 \
                    rmd160 dfdd6649c665416e919e221084c18c24421d74e8 \
                    sha256 34f3fa2366ce20b18f1df573a77c1d27306ce1f2a41d9f9eff621b5192ea8788
        patchfiles-append   pyproject.toml-3.8.0.patch
    }

    build.env-append    BLOSC_DIR=${prefix} \
                        BZIP2_DIR=${prefix} \
                        HDF5_DIR=${prefix} \
                        LZO_DIR=${prefix}
    destroot.env-append BLOSC_DIR=${prefix} \
                        BZIP2_DIR=${prefix} \
                        HDF5_DIR=${prefix} \
                        LZO_DIR=${prefix}

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

    if {${python.version} <= 38} {
        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}
    } else {
        depends_build-append \
                        port:py${python.version}-cython
    }

    mpi.enforce_variant hdf5
    depends_lib-append  port:hdf5 \
                        port:py${python.version}-numpy \
                        port:py${python.version}-numexpr \
                        port:zlib \
                        port:bzip2 \
                        port:lzo2 \
                        port:blosc

    if {${python.version} >= 38} {
        depends_lib-append  port:py${python.version}-blosc2 \
                            port:py${python.version}-cpuinfo

        build.env-append    BLOSC2_DIR=${python.prefix}
        destroot.env-append BLOSC2_DIR=${python.prefix}
    }

    post-patch {
        file rename ${worksrcpath}/src/utils.h ${worksrcpath}/src/xxx_utils.h
        set cfiles [glob -nocomplain -directory ${worksrcpath}/tables *.c]
        if {$cfiles ne ""} {
            delete {*}$cfiles
        }
        reinplace -q {s:utils\.h:xxx_utils.h:} {*}[glob ${worksrcpath}/{src,tables}/*.{c,pxd,pyx}]
    }

    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/share/doc/${subport}
        set docfiles [list LICENSE.txt README.rst THANKS]
        if {${python.version} <= 35} {
            lappend docfiles RELEASE_NOTES.txt VERSION
        }
        xinstall -m 644 -W ${worksrcpath} {*}${docfiles} \
            ${destroot}${prefix}/share/doc/${subport}
    }

    livecheck.type      none
}
