# -*- 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        tensorflow addons 0.12.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
name                py-${github.author}-${github.project}

license             Apache-2
maintainers         nomaintainer

description         TensorFlow Addons.
long_description    TensorFlow Addons is a repository of contributions \
                    that conform to well-established API patterns, but \
                    implement new functionality not available in core \
                    TensorFlow.

homepage            https://github.com/tensorflow/addons

checksums           rmd160  7c5411b253b2c0e80ed5dda5e69f015db1aacdd3 \
                    sha256  692a428d8f4cfa12c37ce2c1de33d7afb1a86ff90601d7442eabedaf41045ae9 \
                    size    610590

python.versions     39

if {${name} ne ${subport}} {
    PortGroup       bazel 1.0

    # Should match the version required by main tensorflow port
    bazel.version   3.1

    # Conflicts with tensorflow-macos
    if { (${build_arch} eq {arm64} && (${python.version} eq 38 || ${python.version} eq 39))
        || (${build_arch} eq {x86_64} && ${python.version} eq 38) } {
        conflicts   py${python.version}-tensorflow-macos
    }

    depends_build-append \
                    port:bash \
                    port:py${python.version}-brotli \
                    port:py${python.version}-pip \
                    port:py${python.version}-pyobjc \
                    port:py${python.version}-setuptools \
                    path:${python.pkgd}/tensorflow:py${python.version}-tensorflow \
                    port:py${python.version}-typing_extensions \
                    port:py${python.version}-wheel \
                    path:bin/rsync:rsync

    depends_run-append \
                    port:py${python.version}-typeguard

    depends_test-append \
                    port:py${python.version}-Faker \
                    port:py${python.version}-flaky \
                    port:py${python.version}-hypothesis \
                    port:py${python.version}-pytest \
                    port:py${python.version}-pytest-forked \
                    port:py${python.version}-pytest-html \
                    port:py${python.version}-pytest-lazy-fixture \
                    port:py${python.version}-pytest-metadata \
                    port:py${python.version}-pytest-xdist \
                    port:py${python.version}-requests-mock \
                    port:py${python.version}-typedapi \
                    port:py${python.version}-typeguard \
                    port:py${python.version}-typing_extensions

    post-extract {
        reinplace "s| python | ${python.bin} |g"  build_deps/build_pip_pkg.sh
        reinplace "s|macosx_10_13|macosx_10_10|g" build_deps/build_pip_pkg.sh
    }

    # Use correct python in bazel build
    bazel.python_version ${python.branch}

    use_configure   yes

    bazel.configure_cmd     ${python.bin}
    bazel.configure_args    configure.py
    bazel.configure_pre_args

    bazel.run_bazel_fetch    no
    bazel.extra_build_opts   --enable_runfiles
    bazel.build_target       build_pip_pkg
    bazel.post_build_cmd     ./bazel-bin/build_pip_pkg artifacts

    destroot.cmd  pip-${python.branch}
    destroot.args \
                    --ignore-installed \
                    --no-cache-dir \
                    --no-dependencies \
                    --root ${destroot} \
                    ${worksrcpath}/artifacts/tensorflow_addons-*.whl
    destroot.post_args

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} LICENSE README.md \
            ${destroot}${docdir}
    }

    # test not working yet
    # pre-test {
    #     set test_path ${workpath}/test
    #     xinstall -d ${test_path}${python.pkgd}
    #     system -W ${worksrcpath} "${destroot.cmd} ${destroot.target} \
    #            --ignore-installed \
    #            --no-cache-dir \
    #            --no-dependencies \
    #            --prefix=${python.prefix} \
    #            --root ${test_path} \
    #            ./artifacts/tensorflow_addons-*.whl"
    #     test.env-append \
    #            PYTHONPATH=${test_path}${python.pkgd}
    # }
    #
    # test.run        yes
    # test.cmd        py.test-${python.branch}
    # test.target

    livecheck.type  none
}
