# -*- 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

# Please keep the version of the libxml2 and py-libxml2 ports the same.

name                py-libxml2
version             2.15.2
revision            0
checksums           rmd160  7946932ae4479ae4865f0c0b954587daddd9a1aa \
                    sha256  c8b9bc81f8b590c33af8cc6c336dbff2f53409973588a351c95f1c621b13d09d \
                    size    3148720

set branch          [join [lrange [split ${version} .] 0 1] .]
categories-append   textproc
license             MIT
maintainers         {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description         Python bindings for libxml2
long_description    {*}${description}

homepage            https://gitlab.gnome.org/GNOME/libxml2/-/wikis/Python-bindings
master_sites        gnome:sources/libxml2/${branch}/

distname            libxml2-${version}
dist_subdir         libxml2
use_xz yes

python.versions     27 310 311 312 313 314

if {${name} ne ${subport}} {
    if {${python.version} == 27} {
        known_fail  yes
    }
    depends_build-append \
                    port:py${python.version}-setuptools

    depends_lib-append  \
                    port:libxml2

    worksrcdir      ${worksrcdir}/python

    post-extract {
        # setup.py is generated by configure and is no longer included
        # in the tarball, but we can generate it quicker with some
        # patches.
        copy ${worksrcpath}/setup.py.in ${worksrcpath}/setup.py
        # generator.py expects doxygen xml to be in doc/
        delete ${worksrcpath}/../doc
        move ${worksrcpath}/../dist-doc ${worksrcpath}/../doc
    }

    patchfiles      patch-setup.py.diff

    post-patch {
        reinplace "s|@LIBXML_VERSION@|${version}|g;s|@prefix@|${prefix}|g" ${worksrcpath}/setup.py
    }

    build.env-append    PYTHONPATH=${worksrcpath}

    post-destroot {
      set docdir ${prefix}/share/doc/${subport}
      xinstall -d ${destroot}${docdir}
      xinstall -m 0644 -W ${worksrcpath} README \
        ${destroot}${docdir}
    }
}

livecheck.name      libxml2
livecheck.type      gnome-with-unstable
