# -*- 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-nbconvert
version             7.16.2
revision            2
categories-append   textproc
license             BSD
supported_archs     noarch
platforms           {darwin any}

python.versions     39 310 311 312 313
python.pep517_backend hatch

maintainers         {stromnov @stromnov} openmaintainer

description         Jupyter Notebooks converter.
long_description    {*}${description}

homepage            https://jupyter.org/

# Must remain in-sync with those in project build script.
set style_css_ver   5.4.0
set index_css_ver   4.0.2
set light_css_ver   4.0.2
set dark_css_ver    4.0.2

set main_distfile   ${distfiles}
set style_distfile  style-${style_css_ver}.css
set index_distfile  index-${index_css_ver}.css
set light_distfile  theme-light-${light_css_ver}.css
set dark_distfile   theme-dark-${dark_css_ver}.css

if {${name} ne ${subport}} {
    master_sites    ${master_sites}:main \
                    https://cdn.jupyter.org/notebook/${style_css_ver}/style/style.min.css?dummy=:style \
                    https://unpkg.com/@jupyterlab/nbconvert-css@${index_css_ver}/style/index.css?dummy=:index \
                    https://unpkg.com/@jupyterlab/theme-light-extension@${light_css_ver}/style/variables.css?dummy=:light \
                    https://unpkg.com/@jupyterlab/theme-dark-extension@${dark_css_ver}/style/variables.css?dummy=:dark

    distfiles       ${main_distfile}:main \
                    ${style_distfile}:style \
                    ${index_distfile}:index \
                    ${light_distfile}:light \
                    ${dark_distfile}:dark

    checksums       ${main_distfile} \
                    rmd160  577dcd82d9e3a9bee11fcaa466626b17ac96d536 \
                    sha256  8310edd41e1c43947e4ecf16614c61469ebc024898eb808cce0999860fc9fb16 \
                    size    854119 \
                    ${style_distfile} \
                    rmd160  05b48b82351654a627bb3a7815bd3808cacdc431 \
                    sha256  5865a609f4437b0464bc121cd567b619074e540a0515a3b82f222f764eb51e01 \
                    size    265101 \
                    ${index_distfile} \
                    rmd160  c6b825c03ada89b2490ac56fe23527a133ec8cbb \
                    sha256  917ff47850a7cc08fd0658026fda7672a85220aaab258e8849e891b37426f947 \
                    size    240379 \
                    ${light_distfile} \
                    rmd160  695dbb5ec518517cdb9b51440fed59e712f6d24b \
                    sha256  11bf3558fd3ed353a4c1401ac0c1730d01df073f6436d357c5bbf02a03bd6962 \
                    size    16019 \
                    ${dark_distfile} \
                    rmd160  b06ee809c64124755c7eec971d9e9471d2599915 \
                    sha256  795f2d5069737cbeb5cba01e6b5c7cadbde227c909e43004c5a60f58d5160aec \
                    size    17102

    patchfiles-append \
                    patch-hatch_build-disable-download.diff

    depends_build-append \
                    port:py${python.version}-setuptools

    # circular dependency: port:py${python.version}-jupyterlab_pygments

    depends_lib-append \
                    port:py${python.version}-beautifulsoup4 \
                    port:py${python.version}-bleach \
                    port:py${python.version}-defusedxml \
                    port:py${python.version}-jinja2 \
                    port:py${python.version}-jupyter_core \
                    port:py${python.version}-jupyterlab_pygments \
                    port:py${python.version}-markupsafe \
                    port:py${python.version}-mistune \
                    port:py${python.version}-nbclient \
                    port:py${python.version}-nbformat \
                    port:py${python.version}-packaging \
                    port:py${python.version}-pandocfilters \
                    port:py${python.version}-pygments \
                    port:py${python.version}-tinycss2 \
                    port:py${python.version}-traitlets

    depends_run-append \
                    port:pandoc

    if {${python.version} < 310} {
        depends_run-append \
                    port:py${python.version}-importlib-metadata
    }

    extract.only    ${main_distfile}
    post-extract {
        set dir_ids [list classic [list style] lab [list index light dark]]
        foreach {dir ids} ${dir_ids} {
            set dir ${worksrcpath}/share/templates/${dir}/static
            foreach id ${ids} {
                set src ${distpath}/[set ${id}_distfile]
                set dst ${dir}/[string map [list -[set ${id}_css_ver].css/ .css] [set ${id}_distfile]/]
                ui_info "copying file: ${src} -> ${dst}"
                copy -force ${src} ${dst}
            }
        }
    }

    notes "
* To convert markdown to formats other than HTML, nbconvert uses pandoc.\
Install it by running:
  sudo port install pandoc
* To convert notebooks to PDF, nbconvert makes use of LaTeX and the XeTeX\
as the rendering engine. Install it by running:
  sudo port install texlive-xetex
"
}
