# -*- 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-openssl
python.rootname     pyopenssl
version             25.3.0
revision            0

categories-append   devel security
license             Apache-2
maintainers         {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
platforms           {darwin any} freebsd

description         python wrapper around the OpenSSL library
long_description    \
    This python module is a rather thin wrapper around (a subset of) the \
    OpenSSL library. With thin wrapper a lot of the object methods do \
    nothing more than calling a corresponding function in the OpenSSL library.
homepage            https://pyopenssl.org/
supported_archs     noarch
installs_libs       no

checksums           rmd160  458cc3355e7e0461a0fd95bc12e294cf5ed0f7f8 \
                    sha256  c981cb0a3fd84e8602d7afc209522773b94c1c2446a3c710a75b06fe1beae329 \
                    size    184073

python.versions     27 310 311 312 313 314

# Match py-cryptography setting here:
set openssl_darwin_min_ver 13

if {${name} ne ${subport}} {
    depends_lib-append      path:lib/libssl.dylib:openssl \
                            port:py${python.version}-cryptography

    if {${python.version} >= 38 && ${python.version} < 313} {
        depends_lib-append  port:py${python.version}-typing_extensions
    }

    post-destroot {
        xinstall -m 0644 -W ${worksrcpath} \
            CHANGELOG.rst \
            CODE_OF_CONDUCT.rst \
            CONTRIBUTING.rst \
            INSTALL.rst \
            README.rst \
            LICENSE \
                ${destroot}${prefix}/share/doc/${subport}
    }

    if {${python.version} == 27 \
        || ${os.platform} eq "darwin" && ${os.major} < ${openssl_darwin_min_ver}} {
        PortGroup       github 1.0

        # TODO: see if we can upgrade this, reverting commits which rely on Rust.
        github.setup    pyca pyopenssl 21.0.0
        # Change github.tarball_from to 'releases' or 'archive' next update
        github.tarball_from tarball
        checksums       rmd160  5806276d4716458a77c32f91a0c7f8ee30fe1dfb \
                        sha256  5d1d93fb3d55be740e444b991bccc5db26b1cfd3666cbbd8b6d01dc7a6cc5430 \
                        size    172965
        revision        0
        epoch           1
    } else {
        variant docs description {build html documentation} {
            depends_build-append    port:py${python.version}-sphinx \
                                    port:py${python.version}-sphinx_rtd_theme

            post-build {
                system -W ${worksrcpath}/doc "/usr/bin/make SPHINXBUILD=${prefix}/bin/sphinx-build-${python.branch} html"
            }

            post-destroot {
                copy ${worksrcpath}/doc/_build/html ${destroot}${prefix}/share/doc/${subport}
            }
        }
    }
}
