# -*- 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.17.1
revision            0
categories-append   textproc
license             BSD
supported_archs     noarch
platforms           {darwin any}

python.versions     310 311 312 313 314
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  0df92167aa00bb3803a041ded6d22a0aead885fd \
                    sha256  34d0d0a7e73ce3cbab6c5aae8f4f468797280b01fd8bd2ca746da8569eddd7d2 \
                    size    865311 \
                    ${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

    # 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}-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

    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
"
}
