# -*- 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
PortGroup             github 1.0

name                  pybombs

set pythons_suffixes {27 35 36 37 38 39}
set default_py_ver    38

categories            science python
license               GPL-3
platforms             {darwin any}
supported_archs       noarch
maintainers           {michaelld @michaelld}

description           Python Build Overlay Managed Bundle System

long_description      PyBOMBS (Python Build Overlay Managed Bundle System) is the GNU Radio install management system for resolving dependencies and pulling in out-of-tree projects from CGRAN (Comprehensive GNU Radio Archive Network).

subport ${name}-devel {}

if {${subport} eq ${name}} {

    github.setup    pybombs pybombs 2.3.5 v
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums       rmd160  52c72515bd0826d6a3f1c7d4309d8fc047b1adad \
                    sha256  96ecf3607f5e952f7df3808a4501a946eba34e42c23577e8caf820d8f98ba4f3 \
                    size    102864
    revision        0

    worksrcdir      gnuradio-pybombs-1e08616
    conflicts       ${name}-devel

    # fix the version to be more explicit
    post-patch {
        reinplace "s@${version}@${version} MacPorts@g" ${worksrcpath}/pybombs/__init__.py
    }

} else {

    github.setup    pybombs pybombs 81f70b7a1b95005f0b0ba9ab1c897d3d160858f0
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version         20211001-[string range ${github.version} 0 7]
    checksums       rmd160  6d9b4499b5fcb53b47c0ae82b1d4dfd877ed6d70 \
                    sha256  2d51429d1a7c707630aa6a95022b9a6b48917dae368c12ea6a6f0a88f7314ead \
                    size    103046
    revision        0

    worksrcdir      gnuradio-${github.project}-[string range ${github.version} 0 6]
    long_description    ${long_description} \
        This port is kept up with the ${name} GIT 'master' branch, is typically updated weekly to monthly.
    conflicts       ${name}

    # fix the version to be very explicit
    post-patch {
        set mps "git-[string range ${github.version} 0 7] MacPorts"
        reinplace "/__version__/s@\\\"\\\(.*\\\)*\\\"@\\\"\\1-${mps}\\\"@g" \
            ${worksrcpath}/pybombs/__init__.py
    }
}

# declare +python* variants

foreach this_py_version_no_dot ${pythons_suffixes} {
    set ndx [lsearch -exact ${pythons_suffixes} ${this_py_version_no_dot}]
    set this_conflicts_no_dot [lreplace ${pythons_suffixes} ${ndx} ${ndx}]
    set this_conflicts [join ${this_conflicts_no_dot} " python"]
    set py_version_with_dot [join [split ${this_py_version_no_dot} ""] "."]
    set this_description "Use Python ${py_version_with_dot}"
    variant python${this_py_version_no_dot} \
        conflicts {*}python${this_conflicts} \
        description ${this_description} "
            python.default_version ${this_py_version_no_dot}
            depends_build-append \
                port:py${this_py_version_no_dot}-setuptools
            depends_lib-append \
                port:py${this_py_version_no_dot}-future \
                port:py${this_py_version_no_dot}-requests \
                port:py${this_py_version_no_dot}-six \
                port:py${this_py_version_no_dot}-ruamel-yaml
    "
}

# set default, if no variants selected

set PY_VER_NO_DOT 0
foreach this_py_version_no_dot ${pythons_suffixes} {
    if {[variant_isset python${this_py_version_no_dot}]} {
        set PY_VER_NO_DOT ${this_py_version_no_dot}
        break
    }
}

if {${PY_VER_NO_DOT} == 0} {
    default_variants +python${default_py_ver}
}

# make sure the default variant is not deselected alone

set PY_VER_NO_DOT 0
foreach this_py_version_no_dot ${pythons_suffixes} {
    if {[variant_isset python${this_py_version_no_dot}]} {
        set PY_VER_NO_DOT ${this_py_version_no_dot}
        break
    }
}

if {${PY_VER_NO_DOT} == 0} {
    ui_error "\n\nYou must select a Python variant; you cannot select -python${default_py_ver} alone.\n"
    return -code error "Invalid variant selection."
}
