# -*- 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-jfricas
version             2.0.0
revision            0

categories-append   math
supported_archs     noarch
platforms           {darwin any}
license             BSD

maintainers         nomaintainer

description         FriCAS Jupyter Kernel.
long_description    {*}${description}

homepage            https://github.com/fricas/jfricas

checksums           rmd160  3377e595c0dc865026e93075937422df16ba74a0 \
                    sha256  da8abc50728faf57ce78fcae34a1fb9765719a497a5a7f3deab3c1307d24fbe5 \
                    size    12451

python.versions     310 311

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

    post-patch {
        reinplace "s|^install_kernel_spec()||" ${worksrcpath}/setup.py
    }

    depends_run-append \
                    port:fricas \
                    port:py${python.version}-jupyter \
                    port:py${python.version}-requests

    require_active_variants fricas hunchentoot

    post-destroot {
        set dst ${destroot}${python.prefix}/share/jupyter/kernels/fricas
        xinstall -d ${dst}
        xinstall -m 644 ${filespath}/kernel.json ${dst}
        reinplace "s|%%PYTHON_PREFIX%%|${python.prefix}|g" ${dst}/kernel.json

        # by some reason it is installed with permissions 0640 and 0750, fix it
        fs-traverse item ${destroot}${python.prefix} {
            if {[file isfile ${item}]} {
                file attributes ${item} -permissions 0644
            } else {
                file attributes ${item} -permissions 0755
            }
        }
    }
}
