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

name                py-scikit-learn
version             1.8.0
revision            1

categories-append   science
license             BSD

python.versions     310 311 312 313 314

maintainers         {stromnov @stromnov} openmaintainer

description         Easy-to-use and general-purpose machine learning in Python

long_description    Scikit-learn integrates machine learning algorithms \
                    in the tightly-knit scientific Python world, building upon \
                    numpy, scipy, and matplotlib. As a machine-learning module, \
                    it provides versatile tools for data mining and analysis \
                    in any field of science and engineering.

homepage            https://scikit-learn.org/

distname            scikit_learn-${version}

checksums           rmd160  ba06b6952dd210a24a57ba4c61f6560bccb61141 \
                    sha256  9bccbb3b40e3de10351f8f5068e105d0f4083b1a65fa07b6634fbc401a6287fd \
                    size    7335585

if {${name} ne ${subport}} {
    if {${python.version} == 310} {
        version     1.7.2
        revision    0
        checksums   rmd160  62aae858f955093394ccf21154d14b342c57e140 \
                    sha256  20e9e49ecd130598f1ca38a1d85090e1a600147b9c02fa6f15d69cb53d968fda \
                    size    7193136
    }

    if {${python.version} == 310} {
        patchfiles  patch-version-caps-pyproject.toml-1.7.2.diff
    } else {
        patchfiles  patch-version-caps-pyproject.toml.diff
    }

    distname        scikit_learn-${version}

    # ensure MacPorts's Python is used, don't attempt the systems "python3"
    post-patch {
        reinplace "s|/usr/bin/env python3|${python.bin}|g" {*}[glob ${worksrcpath}/sklearn/_build_utils/*.py]
    }

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

    depends_lib-append  port:py${python.version}-numpy \
                        port:py${python.version}-scipy \
                        port:py${python.version}-joblib \
                        port:py${python.version}-threadpoolctl

    compiler.openmp_version 2.5

    if {[string match *clang* ${configure.compiler}]} {
        depends_lib-append  port:libomp
    }

    python.pep517_backend meson
    python.add_archflags no

    build.env-append    "CPPFLAGS=${configure.cppflags} -I${prefix}/include/libomp -Xpreprocessor -fopenmp" \
                        "CFLAGS=${configure.cc_archflags} -I${prefix}/include/libomp" \
                        "CXXFLAGS=${configure.cxx_archflags} -I${prefix}/include/libomp" \
                        "LDFLAGS=${configure.ld_archflags} -L${prefix}/lib/libomp -lomp" \
                        DYLD_LIBRARY_PATH=${prefix}/lib/libomp CYTHON=${prefix}/bin/cython-${python.branch}
    destroot.env-append "CPPFLAGS=${configure.cppflags} -I${prefix}/include/libomp -Xpreprocessor -fopenmp" \
                        "CFLAGS=${configure.cc_archflags} -I${prefix}/include/libomp" \
                        "CXXFLAGS=${configure.cxx_archflags} -I${prefix}/include/libomp" \
                        "LDFLAGS=${configure.ld_archflags} -L${prefix}/lib/libomp -lomp" \
                        DYLD_LIBRARY_PATH=${prefix}/lib/libomp CYTHON=${prefix}/bin/cython-${python.branch}

    livecheck.type      none
}
