# -*- 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 2.1.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
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  d2c6153d49e83ad2513e1ee0b63f578160caf7aa \
    sha256  67756b0f99a80eb2e6fd1814644474adaf3cd5158072e9400c248efc76431f9b \
    size    1850292

if {${name} ne ${subport}} {
    depends_build-append    port:py${python.version}-poetry-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}/"
    }
}