# -*- 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           github 1.0
PortGroup           python 1.0
PortGroup           qt5 1.0
PortGroup           select 1.0

github.setup        spyder-ide spyder 06562dd073d3473c24e658849a09ab6266af3426
name                py-spyder-devel
version             20210223-[string range ${github.version} 0 7]
revision            0
# the epoch is here for historical reasons and cannot be removed
epoch               20161005

categories-append   devel
platforms           darwin
supported_archs     noarch
license             MIT
maintainers         {reneeotten @reneeotten} openmaintainer

description         Spyder is the Scientific PYthon Development EnviRonment
long_description    ${description}. \
                    Spyder is a powerful scientific environment written in Python, \
                    for Python, and designed by and for scientists, engineers and data \
                    analysts. It offers a unique combination of the advanced editing, \
                    analysis, debugging, and profiling functionality of a comprehensive \
                    development tool with the data exploration, interactive execution, \
                    deep inspection, and beautiful visualization capabilities of a \
                    scientific package.

homepage            https://www.spyder-ide.org/

checksums           rmd160  cf069489d95dcf0597112e93c1ee3d5f7821b173 \
                    sha256  a0ef0954e72308c3c3a33218b733470870c4d4b1d6514108b03b51c023c86e8f \
                    size    11613194

python.versions     36 37 38 39

if {${name} ne ${subport}} {
    conflicts       py${python.version}-spyder

    depends_lib-append \
                    port:py${python.version}-applaunchservices \
                    port:py${python.version}-atomicwrites \
                    port:py${python.version}-chardet \
                    port:py${python.version}-cloudpickle \
                    port:py${python.version}-cookiecutter \
                    port:py${python.version}-diff-match-patch \
                    port:py${python.version}-intervaltree \
                    port:py${python.version}-ipython \
                    port:py${python.version}-jsonschema \
                    port:py${python.version}-keyring \
                    port:py${python.version}-language-server \
                    port:py${python.version}-nbconvert \
                    port:py${python.version}-numpydoc \
                    port:py${python.version}-pexpect \
                    port:py${python.version}-pickleshare \
                    port:py${python.version}-psutil \
                    port:py${python.version}-pyls-black \
                    port:py${python.version}-pyls-spyder \
                    port:py${python.version}-pygments \
                    port:py${python.version}-pylint \
                    port:py${python.version}-pyqt5 \
                    port:py${python.version}-pyqt5-webengine \
                    port:py${python.version}-qdarkstyle \
                    port:py${python.version}-qtawesome \
                    port:py${python.version}-qtconsole \
                    port:py${python.version}-qtpy \
                    port:py${python.version}-setuptools \
                    port:py${python.version}-sphinx \
                    port:py${python.version}-spyder-kernels \
                    port:py${python.version}-textdistance \
                    port:py${python.version}-three-merge \
                    port:py${python.version}-watchdog \
                    port:py${python.version}-zmq

    variant small description "Remove all optional dependencies." {}

    if {![ variant_isset small ]} {
        depends_lib-append \
                    port:py${python.version}-cython \
                    port:py${python.version}-matplotlib \
                    port:py${python.version}-numpy \
                    port:py${python.version}-pandas \
                    port:py${python.version}-scipy \
                    port:py${python.version}-sympy
    }

    variant docs description "Include offline Python and Qt documentation." {
        depends_lib-append \
                    port:py${python.version}-htmldocs \
                    port:qt5-docs
    }

    variant pil description "Support image objects in editor through Pillow." {
        depends_lib-append \
                    port:py${python.version}-Pillow
    }

    patchfiles-append \
                    patch-spyder_config_base.py.diff \
                    patch-spyder_plugins_editor_plugin.py.diff \
                    patch-spyder_app_start.py.diff \
                    patch-spyder_app_utils.py.diff \
                    patch-spyder_utils_programs.py.diff \
                    patch-spyder_config_lsp.py.diff \
                    patch-setup.py.diff

    set WINPDB_BIN_NAME winpdb-${python.branch}
    set PYLS_BIN_NAME   pyls-${python.branch}

    post-patch {
        reinplace "s|@@WINPDB_BIN_NAME@@|${WINPDB_BIN_NAME}|g" \
            ${worksrcpath}/spyder/plugins/editor/plugin.py
        reinplace "s|\"assistant\"|\"Assistant\"|g" \
            ${worksrcpath}/spyder/app/mainwindow.py
        reinplace "s|\"linguist\"|\"Linguist\"|g" \
            ${worksrcpath}/spyder/app/mainwindow.py
        reinplace "s|\"designer\"|\"Designer\"|g" \
            ${worksrcpath}/spyder/app/mainwindow.py
        reinplace "s|@@PREFIX@@|${prefix}|g" \
            ${worksrcpath}/spyder/app/utils.py
        reinplace "s|@@APPS_DIR@@|${applications_dir}/Qt5|g" \
            ${worksrcpath}/spyder/utils/programs.py
        reinplace "s|@@PYLS_BIN_NAME@@|${PYLS_BIN_NAME}|g" \
            ${worksrcpath}/spyder/config/lsp.py

        # temporary workaround for parso/jedi version restrictions
        reinplace {s|PARSO_REQVER = '=0\.7\.0'|PARSO_REQVER = '>=0.7.0'|g} \
            ${worksrcpath}/spyder/dependencies.py
        reinplace {s|parso==0\.7\.0|parso>=0.7.0|g} ${worksrcpath}/setup.py

        reinplace {s|JEDI_REQVER = '=0\.17\.2'|JEDI_REQVER = '>=0.17.2'|g} \
            ${worksrcpath}/spyder/dependencies.py
        reinplace {s|jedi==0\.17\.2|jedi>=0.17.2|g} ${worksrcpath}/setup.py

        # temporary workaround for spyder-kernels version restrictions
        # see: https://github.com/spyder-ide/spyder/commit/e85aa5fdd4e4236e9082c3908e942c3d5d2de5e1
        reinplace {s|spyder-kernels>=1\.10\.2,<1\.11\.0|spyder-kernels>=>=2.0.0dev0|g} ${worksrcpath}/setup.py
    }

    post-destroot {
        delete ${destroot}${prefix}/bin/spyder_win_post_install.py-${python.branch}
        delete ${destroot}${python.prefix}/bin/spyder_win_post_install.py

        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} AUTHORS.txt Announcements.md \
            CHANGELOG.md CONTRIBUTING.md LICENSE.txt README.md RELEASE.md \
            NOTICE.txt ${destroot}${docdir}
    }

    depends_run-append \
                    port:spyder_select

    select.group    spyder
    select.file     ${filespath}/spyder-${python.version}

    notes "
To make the Python ${python.branch} version of spyder the one that is run\
when you execute the commands without a version suffix, e.g. 'spyder', run:

sudo port select --set ${select.group} [file tail ${select.file}]
"

    livecheck.type  none
}
