# -*- 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                    poetry
version                 2.2.1
revision                1

categories-append       devel
platforms               {darwin any}
license                 MIT
supported_archs         noarch

maintainers             {gmail.com:davidgilman1 @dgilman} openmaintainer

description             Python dependency management and packaging made easy.

long_description        Poetry: Dependency Management for Python. \
                        \
                        Poetry helps you declare, manage and install \
                        dependencies of Python projects, ensuring you have \
                        the right stack everywhere.

homepage                https://python-poetry.org/

checksums               rmd160  87d6ec9ce78436800e2df141b8f1cdb08b6f1b75 \
                        sha256  bef9aa4bb00ce4c10b28b25e7bac724094802d6958190762c45df6c12749b37c \
                        size    3441978

variant python310 conflicts python311 python312 python313 python314 description {Use Python 3.10} {}
variant python311 conflicts python310 python312 python313 python314 description {Use Python 3.11} {}
variant python312 conflicts python310 python311 python313 python314 description {Use Python 3.12} {}
variant python313 conflicts python310 python311 python312 python314 description {Use Python 3.13} {}
variant python314 conflicts python310 python311 python312 python313 description {Use Python 3.14} {}

if {![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312] && ![variant_isset python313] } {
    default_variants +python314
}

foreach pv {314 313 312 311 310} {
    if {[variant_isset python${pv}]} {
        python.default_version  ${pv}
        break
    }
}

python.pep517_backend poetry

# These are in pyproject.toml order
depends_lib-append \
    port:py${python.version}-poetry-core \
    port:py${python.version}-poetry-plugin-export \
    port:py${python.version}-poetry-plugin-shell \
    port:py${python.version}-build \
    port:py${python.version}-cachecontrol \
    port:py${python.version}-filelock \
    port:py${python.version}-cleo \
    port:py${python.version}-dulwich \
    port:py${python.version}-fastjsonschema \
    port:py${python.version}-installer \
    port:py${python.version}-keyring \
    port:py${python.version}-packaging \
    port:py${python.version}-pkginfo \
    port:py${python.version}-platformdirs \
    port:py${python.version}-pyproject_hooks \
    port:py${python.version}-requests \
    port:py${python.version}-requests-toolbelt \
    port:py${python.version}-shellingham \
    port:py${python.version}-tomlkit \
    port:py${python.version}-trove-classifiers \
    port:py${python.version}-virtualenv \
    port:py${python.version}-xattr \
    port:py${python.version}-findpython \
    port:py${python.version}-pbs_installer


if {${python.version} < 311} {
    depends_lib-append \
        port:py${python.version}-tomli
}

# Shell completion
post-destroot {
    xinstall -d "${destroot}${prefix}/etc/bash_completion.d"
    xinstall -d "${destroot}${prefix}/share/zsh/site-functions"
    xinstall -d "${destroot}${prefix}/share/fish/vendor_completions.d"
    system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/poetry completions bash > ${destroot}${prefix}/etc/bash_completion.d/poetry"
    system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/poetry completions zsh > ${destroot}${prefix}/share/zsh/site-functions/_poetry"
    system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/poetry completions fish > ${destroot}${prefix}/share/fish/vendor_completions.d/poetry.fish"
    reinplace "s|${destroot}||g" \
        ${destroot}${prefix}/etc/bash_completion.d/poetry \
        ${destroot}${prefix}/share/zsh/site-functions/_poetry \
        ${destroot}${prefix}/share/fish/vendor_completions.d/poetry.fish
}

test.run                yes
test.cmd                ${python.bin}
test.target             -m poetry
