# -*- 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-gensim
version             4.3.2
categories-append   textproc
license             LGPL-2.1

python.versions     39 310 311 312

maintainers         {stromnov @stromnov} openmaintainer

description         Python framework for fast Vector Space Modelling

long_description    Gensim is a Python library for topic modelling, document \
                    indexing and similarity retrieval with large corpora. \
                    Target audience is the natural language processing (NLP) and \
                    information retrieval (IR) community.

homepage            https://radimrehurek.com/gensim/

checksums           rmd160  e182299e1af855465cfdbb60bfc092ae34aa9553 \
                    sha256  99ac6af6ffd40682e70155ed9f92ecbf4384d59fb50af120d343ea5ee1b308ab \
                    size    23263982

if {${name} ne ${subport}} {
    depends_build-append \
                        port:py${python.version}-cython-compat
    set compat_path [string replace ${python.pkgd} 0 [string length ${python.prefix}]-1 ${prefix}/lib/py${python.version}-cython-compat]
    build.env-append    PYTHONPATH=${compat_path}

    depends_lib-append  port:py${python.version}-numpy \
                        port:py${python.version}-scipy \
                        port:py${python.version}-smart_open

    # https://github.com/piskvorky/gensim/issues/3518
    if {${configure.cxx_stdlib} ne "libc++"} {
        # Do not replace it with -stdlib=libstdc++,
        # since gcc may be built without stdlib_flag variant.
        # It is also a current default on PowerPC systems.
        patchfiles-append \
                        patch-do-not-hardcode-cpp-runtime.diff
    }

    # unpin cython version
    patch.env-append    PYTHONPATH=${compat_path}
    post-patch {
        set cython_version [exec bash -c "${python.bin} -c 'import cython; print(cython.__version__)' || true"]
        reinplace -E \
            "s|^(CYTHON_STR = 'Cython==)\[\[:digit:].]+(')|\\1${cython_version}\\2|" \
            ${worksrcpath}/setup.py
    }

    # cc1plus: error: unrecognized command line option "-std=c++11"
    compiler.cxx_standard 2011

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 644 -W ${worksrcpath} \
            CHANGELOG.md COPYING README.md \
            ${destroot}${docdir}
    }
}
