# -*- 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-undetected-chromedriver
version             3.5.5
revision            0
categories-append   python www
maintainers         nomaintainer
license             GPL-3
supported_archs     noarch
platforms           {darwin any}

description         Custom Selenium Chromedriver
long_description    {*}${description} | Zero-Config | \
                    Passes ALL bot mitigation systems \
                    (like Distil / Imperva/ Datadadome / CloudFlare IUAM)

homepage            https://github.com/ultrafunkamsterdam/undetected-chromedriver

checksums           rmd160  c03f5bedc2c097032a0d105eefbee5e90f5d86d4 \
                    sha256  9f945e1435005247abe17de316bcfda85b284a4177fd5f25167c78ced33b65ec \
                    size    65409

python.versions     39 310 311 312 313

if {${name} ne ${subport}} {
    depends_build-append \
                    port:py${python.version}-requests

    depends_lib-append \
                    port:py${python.version}-selenium \
                    port:py${python.version}-websockets

    post-patch {
        fs-traverse f ${worksrcpath}/undetected_chromedriver {
            if {[file isfile ${f}] && [string match "*.py" ${f}]} {
                reinplace -E -q \
                    "1s|^(#!\[\[:space:]]*)/usr/bin/env\[\[:space:]]+python3|\\1${python.bin}|" \
                    ${f}
            }
        }
    }

    pre-test {
        copy        ${filespath}/uc-test.py ${workpath}
        reinplace -E -q \
            "1s|^(#!\[\[:space:]]*)/usr/bin/env\[\[:space:]]+python3|\\1${python.bin}|" \
                    ${workpath}/uc-test.py
        reinplace -q "s|@PREFIX@|${prefix}|g" \
                    ${workpath}/uc-test.py
        reinplace -q "s|@NAME@|chromedriver|g" \
                    ${workpath}/uc-test.py
    }

    test.run        yes
    python.test_framework
    test.cmd        ${python.bin}
    test.target     ${workpath}/uc-test.py
}

notes-append \
    "This package is intended to be used with the port

    chromedriver +undetected

and the Python code:

    import undetected_chromedriver as uc
    driver = uc.Chrome(driver_executable_path='${prefix}/bin/chromedriver-undetected')
"

