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

# please verify compatibility with py-spyder before updating
name                py-python-lsp-server
version             1.12.2
revision            0

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

description         A Python implementation of the Language Server Protocol
long_description    Fork of the python-language-server project, maintained by the Spyder \
                    IDE team and the community.

distname            python_lsp_server-${version}

checksums           rmd160  3e81bc1a37a8d57482e52b5e4156605a3ae8c9cf \
                    sha256  fea039a36b3132774d0f803671184cf7dde0c688e7b924f23a6359a66094126d \
                    size    115054

homepage            https://github.com/python-lsp/python-lsp-server/

python.versions     39 310 311 312 313

if {${subport} ne ${name}} {
    depends_build-append \
                    port:py${python.version}-setuptools_scm

    depends_lib-append \
                    port:py${python.version}-autopep8 \
                    port:py${python.version}-codestyle \
                    port:py${python.version}-docstring-to-markdown \
                    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-lsp-jsonrpc \
                    port:py${python.version}-rope \
                    port:py${python.version}-ujson \
                    port:py${python.version}-whatthepatch \
                    port:py${python.version}-yapf

    patchfiles-append   patch-pylsp_plugins_flake8_lint.py.diff \
                        patch-test_plugins_flake8_lint.py.diff

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

    test.run        yes

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

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

    depends_run-append \
                    port:python-lsp-server_select

    select.group    python-lsp-server
    select.file     ${filespath}/py${python.version}-pylsp

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

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