# -*- 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-tensorflow-macos
version             2.11.0
revision            0

categories-append   lang
license             Apache-2
maintainers         nomaintainer
supported_archs     arm64 x86_64

description         Mac-optimized TensorFlow to be used with py-tensorflow-metal.

long_description    Hardware-accelerated TensorFlow and TensorFlow \
                    Addons for macOS 12.0+. Native hardware \
                    acceleration is supported on M1 Macs and \
                    Intel-based Macs through Apple’s ML Compute \
                    framework.

homepage            https://developer.apple.com/metal/tensorflow-plugin/

extract.suffix      .whl
extract.only

# set build_arch by hand on arm64/x86_64 systems to get x86_64/arm64 checksums
# sudo port -d checksum py310-tensorflow-macos os.arch=arm build_arch=arm64
# run `port clean --all py*-tensorflow-macos` afterwards

python.versions     39 310
python.pep517       yes
python.pep517_backend

set minimum_supported_major_version 21
if {${os.arch} ni [list arm i386]
    || ${os.platform} eq {darwin}
        && ${os.major} < ${minimum_supported_major_version}} {
    known_fail      yes
    pre-fetch {
        ui_error "TensorFlow with ML Compute acceleration is only available \
            on macOS [expr ${minimum_supported_major_version} - 9] and later \
            with [join ${supported_archs} " or "] architectures."
        error {unsupported platform}
    }
}

if {${name} ne ${subport}} {
    conflicts       py${python.version}-tensorflow \
                    py${python.version}-tensorflow1 \
                    py${python.version}-tensorflow-addons

    # https://pypi.org/project/tensorflow-macos/#files
    if {${build_arch} eq {arm64}} {
        if {${python.version} eq 310} {
            master_sites \
                    https://files.pythonhosted.org/packages/47/09/13518855221f421241e973bd462e87ea806a51738c577f4ca33a26b718b8/
            checksums \
                    rmd160  59d9cbc2cae6c9060a99b2e5eafbd057c4993b59 \
                    sha256  0bdbd1bb564d01bd735d6d11451f0658c3dd8187369ee9dd3ed6de6bbdd6df53 \
                    size    215570332
        } elseif {${python.version} eq 39} {
            master_sites \
                    https://files.pythonhosted.org/packages/7c/ea/c8f1fab1b2ba4e6d2e90e00ebd7f347d433146ee50b2cb9f06acbcf1473f/
            checksums \
                    rmd160  b55a41d39fdc1bc347ef8e3a7b7688a4db607a46 \
                    sha256  8d56b0d0bd140008b0cc4877804c9c310e1e2735444fa99bc7c88ffb2909153d \
                    size    215570836
        } elseif {${python.version} eq 38} {
            master_sites \
                    https://files.pythonhosted.org/packages/d0/3d/ac33c51e6ebbc7dc4c2eac604b1de6e6abb76f0caff3e347a6f4bfe722c1/
            checksums \
                    rmd160  12e5c958138b4c6865305f9fe6bb0809a1a6f4df \
                    sha256  6810731e2c8353123f6c9c944d2765b58a2226e7eb9fec1e360f73977c6c6aa4 \
                    size    215520579
        }
    } elseif {${build_arch} eq {x86_64}} {
        if {${python.version} eq 310} {
            master_sites \
                    https://files.pythonhosted.org/packages/95/84/bc5baffab6b5173f044ee6ddb1b6d88765dbd4a0a48c015abe6cb4bdc61f/
            checksums \
                    rmd160  0280d169477142e23550112027a02943af7aae49 \
                    sha256  66eb67915cf418eddd3b4c158132609efd50895fa09fd55e4b2f14a3ab85bd34 \
                    size    245483716
        } elseif {${python.version} eq 39} {
            master_sites \
                    https://files.pythonhosted.org/packages/71/d9/43195c8900d3646005f6b236137dfcaa586afe3fa80b4bf6b1c794cfff0b/
            checksums \
                    rmd160  f18d151bcd32c5c9b1199e147bde9e5bd8b3e7e3 \
                    sha256  db97cd91b905bd01069069f07325a2a291705222eb4914148b9574090a5815ae \
                    size    245479786
        } elseif {${python.version} eq 38} {
            master_sites \
                    https://files.pythonhosted.org/packages/de/12/9bb639f8f41d1021bd9ee2b645c8252521598a86e9510d0eaa9865d84890/
            checksums \
                    rmd160  3bd591fced9f82031dc30c261df9d8532faca339 \
                    sha256  881b36d97b67d24197250a091c52c31db14aecfdbf1ac20418a148ec37321978 \
                    size    245455875
        }
    }
    distname tensorflow_macos-${version}-cp${python.version}-cp${python.version}-macosx_12_0_${build_arch}

    depends_run-append \
                    port:py${python.version}-absl \
                    port:py${python.version}-astunparse \
                    port:py${python.version}-flatbuffers \
                    port:py${python.version}-gast \
                    port:py${python.version}-grpcio \
                    port:py${python.version}-h5py \
                    port:py${python.version}-keras \
                    port:py${python.version}-keras_preprocessing \
                    port:py${python.version}-numpy \
                    port:py${python.version}-opt_einsum \
                    port:py${python.version}-protobuf3 \
                    port:py${python.version}-tensorflow_estimator \
                    port:py${python.version}-scipy \
                    port:py${python.version}-tensorboard \
                    port:py${python.version}-termcolor \
                    port:py${python.version}-typing_extensions \
                    port:py${python.version}-wrapt \
                    port:py${python.version}-typeguard

    build           {}

    destroot.target ${distpath}/${distfiles}

    post-destroot {
        # avoid conflict with py${python.version}-tensorboard
        delete      ${destroot}${python.prefix}/bin/tensorboard \
                    ${destroot}${prefix}/bin/tensorboard-${python.branch}
    }

    livecheck.type  none
}
