# -*- 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-psycopg
version             3.2.9
revision            0

categories-append   databases
maintainers         {snc @nerdling} openmaintainer
license             LGPL-3+
platforms           {darwin any} freebsd
supported_archs     noarch

description         Psycopg 3 is a modern implementation of a PostgreSQL adapter for Python.
long_description    {*}${description}

python.versions     310 311 312 313

homepage            https://www.psycopg.org

checksums           rmd160  33321f195abf6d868e3ee68f0b4bc1f2ac06182d \
                    sha256  2fbb46fcd17bc81f993f28c47f1ebea38d66ae97cc2dbc3cad73b37cefbff700 \
                    size    158122

# PostgreSQL variants
set pg_suffixes {17 16 15 14 13 12}
set pg_variants {}
foreach suffix ${pg_suffixes} {
    lappend pg_variants postgresql${suffix}
}

foreach suffix ${pg_suffixes} {
    set vrt postgresql${suffix}
    set pgversion [string index ${suffix} 0][string index ${suffix} 1]
    set index [lsearch -exact ${pg_variants} ${vrt}]
    set conf [lreplace ${pg_variants} ${index} ${index}]
    variant ${vrt} description "Use PostgreSQL ${pgversion}" conflicts {*}${conf} "
        depends_lib-append      port:${vrt}

        post-patch {
            reinplace s|@@PG_CONFIG@@|${prefix}/lib/postgresql${pgversion}/bin/pg_config|g \
                ${worksrcpath}/psycopg/pq/misc.py
        }
    "
}

set pgdefault "if {"
foreach suffix ${pg_suffixes} {
    set pgdefault "${pgdefault}!\[variant_isset postgresql${suffix}\] && "
}
set pgdefault [string range ${pgdefault} 0 end-4]
set pgdefault "${pgdefault}} { default_variants +postgresql17 }"
eval ${pgdefault}

if {${subport} ne ${name}} {
    patchfiles  patch-psycopg_pq_misc.py.diff

    if {${python.version} < 313} {
        depends_lib-append \
                    port:py${python.version}-typing_extensions
    }
}
