# -*- 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

name                py-blosc2
version             4.11.0
revision            1

categories-append   archivers devel
maintainers         nomaintainer
license             BSD

description         Python wrapper for Blosc2
long_description    A Python wrapper for the extremely fast Blosc2 \
                    compression library

homepage            https://pypi.python.org/pypi/blosc2

set miniexpr_hash   f0b8c94771cd21d3c9029d6ccec204ab3a67584f
set sleef_hash      7623d6cfa2712462880fa63a4d0f0b5f775d1a83

master_sites-append https://github.com/Blosc/miniexpr/archive/${miniexpr_hash}/:miniexpr \
                    https://github.com/shibatch/sleef/archive/${sleef_hash}:sleef
distfiles-append    miniexpr-${miniexpr_hash}${extract.suffix}:miniexpr \
                    sleef-${sleef_hash}${extract.suffix}:sleef

checksums           ${distname}${extract.suffix} \
                    rmd160  1306cf4efef2aad15747e959c8bd15d5cdee5f3f \
                    sha256  3c610b076ad0422d861ff10732013c7c3461135968c3c442630542e71249a4a2 \
                    size    6820440 \
                    miniexpr-${miniexpr_hash}${extract.suffix} \
                    rmd160  2cc7c13cb615da93a38d5419dd528693ed18af57 \
                    sha256  b437e354416d234cfcc7e79fff1a61646103721f9a92e02ea5c27ac09b6cfc31 \
                    size    481423 \
                    sleef-${sleef_hash}${extract.suffix} \
                    rmd160  230d8cb9864c282c8130a620f015918a13eb7b21 \
                    sha256  22affd077d1fa19f0052c39cfc14b8f2e1227da70dc7928e056bebca1d35ac53 \
                    size    1817461

python.versions     310 311 312 313 314

python.pep517_backend   scikit

if {$subport ne $name} {
    # https://github.com/Blosc/python-blosc2/issues/699
    patch.dir       ${workpath}/miniexpr-${miniexpr_hash}
    patchfiles      miniexpr-accelerate-ppc.patch

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

    depends_lib-append  port:blosc2 \
                        port:py${python.version}-httpx \
                        port:py${python.version}-msgpack \
                        port:py${python.version}-ndindex \
                        port:py${python.version}-numexpr \
                        port:py${python.version}-numpy \
                        port:py${python.version}-pydantic \
                        port:py${python.version}-requests \
                        port:py${python.version}-rich \
                        port:py${python.version}-threadpoolctl

    # Build fails with Apple gcc with multiple errors:
    compiler.blacklist-append \
                        *gcc-4.0 *gcc-4.2 {clang < 900}

    build.env-append    SKBUILD_CMAKE_DEFINE=FETCHCONTENT_SOURCE_DIR_MINIEXPR=${workpath}/miniexpr-${miniexpr_hash}\;FETCHCONTENT_SOURCE_DIR_SLEEF=${workpath}/sleef-${sleef_hash} \
                        USE_SYSTEM_BLOSC2=1

    pre-build {
        build.env-append    ARCHFLAGS=[get_canonical_archflags cc]
    }

    build.args-append   -Cbuild.verbose=true

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -m 755 -d ${destroot}${docdir}
        xinstall -m 644 -W ${worksrcpath} LICENSE.txt README.rst \
            RELEASE_NOTES.md \
            ${destroot}${docdir}
    }
}
