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

github.setup        apple coremltools 9.0
github.tarball_from archive
name                py-coremltools
revision            0

license             BSD MIT Apache-2
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

description         Community Tools for Core ML
long_description    Core ML is an Apple framework that allows \
                    developers to easily integrate machine learning \
                    (ML) models into apps. Core ML is available on \
                    iOS, iPadOS, watchOS, macOS, and tvOS. Core ML \
                    introduces a public file format (.mlmodel) for a \
                    broad set of ML methods including deep neural \
                    networks (convolutional and recurrent), tree \
                    ensembles (boosted trees, random forest, decision \
                    trees), and generalized linear models. Core ML \
                    models can be directly integrated into apps within \
                    Xcode.

checksums           rmd160  5d7462efe4fdbf63b30e911acc21c127e36a3869 \
                    sha256  0582e0307dbdccdcb4936f8b3b6880bb2e815d9a416a3e76127824bd3bec5ce6 \
                    size    27328014

python.versions     310 311 312 313 314

if {${name} ne ${subport}} {
    PortGroup       cmake 1.1

    use_configure   yes
    cmake.generator "Unix Makefiles"

    supported_archs  arm64 x86_64
    universal_variant no

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

    depends_run-append \
                    port:py${python.version}-attrs \
                    port:py${python.version}-cattrs \
                    port:py${python.version}-packaging \
                    port:py${python.version}-protobuf3 \
                    port:py${python.version}-pyaml \
                    port:py${python.version}-sympy \
                    port:py${python.version}-tqdm

    compiler.cxx_standard   2017

    patchfiles      patch-CMakeLists.txt.diff \
                    patch-smoke-test.diff

    # Do not expose installed protobuf headers to the vendored protobuf.
    configure.cppflags-delete -I${prefix}/include
    configure.args-append \
                    -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
                    -Dprotobuf_WITH_ZLIB=OFF \
                    -DPYTHON_EXECUTABLE=${python.bin} \
                    -DPYTHON_INCLUDE_DIR=${python.include} \
                    -DPYTHON_LIBRARY=${python.lib}

    # CMake builds the vendored setuptools extension during configuration.
    configure.env-append "ARCHFLAGS=-arch ${configure.build_arch}"

    # Upstream's dist target builds the native libraries and packages the wheel.
    build.args
    build.target    dist

    destroot.cmd    ${python.bin} -m installer
    destroot.destdir --destdir ${destroot}
    pre-destroot {
        destroot.target [glob ${cmake.build_dir}/dist/*.whl]
    }

    # Exercise the packaged wheel, including its native extensions.
    pre-test {
        delete ${workpath}/test-root
        system "[shellescape ${python.bin}] -m installer --destdir [shellescape ${workpath}/test-root] [shellescape [glob ${cmake.build_dir}/dist/*.whl]]"
    }
    python.test_framework
    test.run        yes
    test.cmd        ${python.bin}
    test.target
    test.args       ${worksrcpath}/macports/smoke_test.py
    test.env-append PYTHONPATH=${workpath}/test-root${python.pkgd}
}
