# -*- 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-psycopg2
version             2.9.10
revision            1

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

description         A python DBAPI-2.0-compliant database adapter for postgresql

long_description    Psycopg2 is a postgresql database adapter for python. \
                    It's fully compliant to python's DBAPI-2.0. psycopg is \
                    designed for heavily multi-threaded applications \
                    featuring connection pooling.

python.versions     27 310 311 312 313 314

homepage            https://www.psycopg.org

checksums           rmd160  1d021a4b1e05a4b69839e53547409584be5d5dce \
                    sha256  12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11 \
                    size    385672

proc pgsql_variant_set {} {
    if {
        [variant_isset postgresql10] ||
        [variant_isset postgresql11] ||
        [variant_isset postgresql12] ||
        [variant_isset postgresql13] ||
        [variant_isset postgresql14] ||
        [variant_isset postgresql15] ||
        [variant_isset postgresql16] ||
        [variant_isset postgresql17]
    } {
        return yes
    } else {
        return no
    }
}

proc pgsql_version {} {
    if {[variant_isset postgresql10]} {
        set pgsql_ver 10
    } elseif {[variant_isset postgresql11]} {
        set pgsql_ver 11
    } elseif {[variant_isset postgresql12]} {
        set pgsql_ver 12
    } elseif {[variant_isset postgresql13]} {
        set pgsql_ver 13
    } elseif {[variant_isset postgresql14]} {
        set pgsql_ver 14
    } elseif {[variant_isset postgresql15]} {
        set pgsql_ver 15
    } elseif {[variant_isset postgresql16]} {
        set pgsql_ver 16
    } elseif {[variant_isset postgresql17]} {
        set pgsql_ver 17
    } else {
        error "No postgresql variant enabled"
    }

    return ${pgsql_ver}
}

if {${name} ne ${subport}} {
    if {${python.version} == 27} {
        # NOTE: Don't reuse old revision, for resurrected Python 2.7 subport
        version     2.8.6
        revision    1

        checksums   rmd160  aea153e22c9ac8b1b504c7e8abcad4310aa12cae \
                    sha256  fb23f6c71107c37fd667cb4ea363ddeb936b348bbd6449278eb92c189699f543 \
                    size    383797

        patchfiles-append \
                    patch-setup.cfg-py27.diff

        if {![pgsql_variant_set]} {
            default_variants +postgresql14
        }

        livecheck.type none
    } else {
        if {![pgsql_variant_set]} {
            default_variants +postgresql17
        }
    }

    set pgsql_ver \
        [pgsql_version]

    if {${python.version} > 27} {
        python.pep517 yes
        depends_build-append port:py${python.version}-virtualenv
        patchfiles-append \
                    patch-setup.cfg.diff
    }

    depends_lib-append  \
                    port:py${python.version}-setuptools \
                    path:lib/libssl.dylib:openssl \
                    port:postgresql${pgsql_ver}

    post-patch {
        reinplace \
            s|@PG_CONFIG@|${prefix}/lib/postgresql${pgsql_ver}/bin/pg_config|g \
            ${worksrcpath}/setup.cfg
    }

    variant postgresql10 conflicts postgresql16 postgresql17 \
            postgresql11 postgresql12 postgresql13 postgresql14 postgresql15 \
            description "Build using postgresql v10" {}

    variant postgresql11 conflicts postgresql16 postgresql17 \
            postgresql10 postgresql12 postgresql13 postgresql14 postgresql15 \
            description "Build using postgresql v11" {}

    variant postgresql12 conflicts postgresql16 postgresql17 \
            postgresql10 postgresql11 postgresql13 postgresql14 postgresql15 \
            description "Build using postgresql v12" {}

    variant postgresql13 conflicts postgresql16 postgresql17 \
            postgresql10 postgresql11 postgresql12 postgresql14 postgresql15 \
            description "Build using postgresql v13" {}

    variant postgresql14 conflicts postgresql16 postgresql17 \
            postgresql10 postgresql11 postgresql12 postgresql13 postgresql15 \
            description "Build using postgresql v14" {}

    variant postgresql15 conflicts postgresql16 postgresql17 \
            postgresql10 postgresql11 postgresql12 postgresql13 postgresql14 \
            description "Build using postgresql v15" {}

    variant postgresql16 conflicts \
            postgresql10 postgresql11 postgresql12 postgresql13 postgresql14 \
            postgresql15 postgresql17 \
            description "Build using postgresql v16" {}

    variant postgresql17 conflicts \
            postgresql10 postgresql11 postgresql12 postgresql13 postgresql14 \
            postgresql15 postgresql16 \
            description "Build using postgresql v17" {}
}

universal_variant       no
