# -*- 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.3
revision            0

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 36 37 38 39 310

homepage            https://www.psycopg.org

checksums           rmd160  1e9d1fea5280b58c19812d07559498404d166e80 \
                    sha256  8e841d1bf3434da985cc5ef13e6f75c8981ced601fd70cc6bf33351b91562981 \
                    size    380611

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
    }

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

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

    post-patch {
        if {[variant_isset postgresql14]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql14/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql13]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql13/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql12]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql12/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql11]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql11/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql10]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql10/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

        if {[variant_isset postgresql96]} {
            reinplace \
                s|@PG_CONFIG@|${prefix}/lib/postgresql96/bin/pg_config|g \
                ${worksrcpath}/setup.cfg
        }

    }

    variant postgresql14 conflicts postgresql96 \
            postgresql10 postgresql11 postgresql12 postgresql13 \
            description "Build using postgresql v14" {
                depends_lib-append  port:postgresql14
    }

    variant postgresql13 conflicts postgresql96 \
            postgresql10 postgresql11 postgresql12 postgresql14 \
            description "Build using postgresql v13" {
                depends_lib-append  port:postgresql13
    }

    variant postgresql12 conflicts postgresql96 \
            postgresql10 postgresql11 postgresql13 postgresql14 \
            description "Build using postgresql v12" {
                depends_lib-append  port:postgresql12
    }

    variant postgresql11 conflicts postgresql96 \
            postgresql10 postgresql12 postgresql13 postgresql14 \
            description "Build using postgresql v11" {
                depends_lib-append  port:postgresql11
    }

    variant postgresql10 conflicts postgresql96 \
            postgresql11 postgresql12 postgresql13 postgresql14 \
            description "Build using postgresql v10" {
                depends_lib-append  port:postgresql10
    }

    variant postgresql96 conflicts \
            postgresql10 postgresql11 postgresql12 postgresql13 postgresql14 \
            description "Build using postgresql v9.6" {
                depends_lib-append  port:postgresql96
    }

    if {
        ![variant_isset postgresql96] &&
        ![variant_isset postgresql10] &&
        ![variant_isset postgresql11] &&
        ![variant_isset postgresql12] &&
        ![variant_isset postgresql13] &&
        ![variant_isset postgresql14]
    } {
        default_variants +postgresql14
    }

    livecheck.type      none
} else {
    livecheck.type      pypi
}

universal_variant       no
