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

github.setup        pydicom pynetdicom 3.0.4 v
github.tarball_from archive
name                py-pynetdicom
python.versions     310 311 312 313
platforms           {darwin any}
license             MIT BSD
maintainers         {eborisch @eborisch} openmaintainer
supported_archs     noarch

description         A Python implementation of the DICOM networking protocol

long_description    pynetdicom is a pure Python 3 package that implements the \
                    DICOM networking protocol. Working with pydicom, it \
                    allows the easy creation of DICOM Service Class Users \
                    (SCUs) and Service Class Providers (SCPs).

checksums \
    rmd160  c7f72de501ec8575e57a9325feab53dd2f3303f9 \
    sha256  2d9608fc303d5ecc3f451c8a658057526f3a70f9e84659be13ed16938425dace \
    size    1826902

if {${name} ne ${subport}} {
    depends_build-append    port:py${python.version}-flit_core
    depends_lib-append      port:py${python.version}-pydicom

    variant doc description "Build offline documentation" {
        depends_build-append \
            port:py${python.version}-matplotlib\
            port:py${python.version}-sphinx \
            port:py${python.version}-sphinx-bootstrap-theme \
            port:py${python.version}-sphinx-copybutton \
            port:py${python.version}-sphinx-gallery \
            port:py${python.version}-sphinx-issues \
            port:py${python.version}-sphinx_rtd_theme

        notes "
            Documentation installed in :
              file://${prefix}/share/doc/${subport}/html/index.html
        "
    }

    if {[variant_isset doc]} {
        notes "
            Documentation installed at:
            ${prefix}/share/doc/${subport}/html/index.html
        "
    }

    post-extract {
        reinplace s/sphinx-build/sphinx-build-${python.branch}/ \
            docs/Makefile
        # Temporary until upstream releases project with new build setup
        reinplace /requires/s/2/3/ pyproject.toml
    }

    post-build {
        if {[variant_isset doc]} {
            system -W ${worksrcpath}/docs/ \
                "env PYTHONPATH='${worksrcpath}/build/lib' make html"
        }
    }

    post-destroot {
        set DOCDIR ${destroot}${prefix}/share/doc/${subport}
        xinstall -d ${DOCDIR}
        xinstall -W ${worksrcpath} -m 0644 \
            LICENCE \
            README.rst \
            ${DOCDIR}

        if {[variant_isset doc]} {
            file copy ${worksrcpath}/docs/_build/html ${DOCDIR}
        }

        set EXDIR ${destroot}${prefix}/share/examples/${subport}
        xinstall -d ${EXDIR}
        system -W ${worksrcpath}/pynetdicom/apps "cp -R * ${EXDIR}/"
    }
}
