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

name                py-language-server
github.setup        palantir python-language-server 0.31.2
revision            0

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

description         An implementation of the Language Server Protocol for Python
long_description    ${description}

checksums           rmd160  c7f21f7d9d978e2ce1bc27008db05b07426d9481 \
                    sha256  6ecad0792983988a9ad41e50382ddc1849071a942e4c67aed1166c0298bb36fb \
                    size    453639

# no support yet for Python 3.8
python.versions     27 35 36 37

if {${subport} ne ${name}} {
    depends_lib-append \
                    port:py${python.version}-autopep8 \
                    port:py${python.version}-codestyle \
                    port:py${python.version}-docstyle \
                    port:py${python.version}-flake8 \
                    port:py${python.version}-flake8-mccabe \
                    port:py${python.version}-jedi \
                    port:py${python.version}-pluggy \
                    port:py${python.version}-pyflakes \
                    port:py${python.version}-pylint \
                    port:py${python.version}-python-jsonrpc-server \
                    port:py${python.version}-rope \
                    port:py${python.version}-setuptools \
                    port:py${python.version}-ujson \
                    port:py${python.version}-yapf

    if {${python.version} eq 27} {
        depends_lib-append  port:py${python.version}-backports-functools_lru_cache \
                            port:py${python.version}-configparser \
                            port:py${python.version}-future
    }

    patchfiles-append   patch-pyls_plugins_flake8_lint.py.diff

    post-patch {
        reinplace "s|@@FLAKE8_BIN@@|flake8-${python.branch}|g" ${worksrcpath}/pyls/plugins/flake8_lint.py
        reinplace "s|@@PYTHON_BIN@@|${python.bin}|g" ${worksrcpath}/pyls/plugins/flake8_lint.py
    }

    depends_test-append \
                    port:py${python.version}-pytest \
                    port:py${python.version}-mock

    test.run        yes
    test.cmd        py.test-${python.branch}
    test.args       -o addopts=''
    test.target
    test.env        PYTHONPATH=${worksrcpath}/build/lib

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

    depends_run-append \
                    port:python-language-server_select

    select.group    python-language-server
    select.file     ${filespath}/py${python.version}-pyls

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

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

    livecheck.type  none
}