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

set _name           obspy
set _conflicts      obspy-devel
set _n              [string index ${_name} 0]

name                py-${_name}
version             1.1.0
revision            1
conflicts           py-${_conflicts}

categories-append   science
platforms           darwin
license             LGPL-3

maintainers         {petr @petrrr} openmaintainer

description         Python framework for processing seismological data

long_description    \
    ObsPy is an open-source project dedicated to provide a Python framework \
    for processing seismological data. It provides support for file formats \
    and signal processing routines which allow the manipulation, analysis \
    and visualization of seismological time series. The goal of the ObsPy \
    project is to facilitate rapid application development for seismology.

homepage            http://www.obspy.org/

use_zip             yes
distname            ${_name}-${version}
master_sites        pypi:${_n}/${_name}/

checksums           md5     2336f8f4879dbb4b1056ef5727edbf41 \
                    rmd160  cfc1c65b2bd956990baea2316d8221da82efbecd \
                    sha256  ef48b4e52a8166c35c46775b523899ffaa00658018822103e1ad9f5008050d61

python.versions     27 35 36 37

if {${name} ne ${subport}} {
    conflicts               py${python.version}-${_conflicts}

    # py-scipy is not universal
    universal_variant       no

    depends_build-append    port:py${python.version}-setuptools \
                            port:py${python.version}-numpy

    depends_lib-append      port:py${python.version}-decorator \
                            port:py${python.version}-future \
                            port:py${python.version}-lxml \
                            port:py${python.version}-matplotlib \
                            port:py${python.version}-numpy \
                            port:py${python.version}-scipy \
                            port:py${python.version}-requests \
                            port:py${python.version}-sqlalchemy

    # soft dependencies added for simplicity
    depends_lib-append      port:py${python.version}-gdal \
                            port:py${python.version}-geographiclib \
                            port:py${python.version}-pyshp

    # Note: Required for post-installation testing only
    depends_run-append      port:py${python.version}-flake8 \
                            port:py${python.version}-flake8-pep8-naming \
                            port:py${python.version}-pyproj

    # Python 3.3+: mock is available as unittest.mock
    if { ${python.version} < 33 } {
        depends_run-append  port:py${python.version}-mock
    }

    # add manpages
    depends_build-append    port:help2man

    post-build {
        set libarch [glob -tail -directory ${worksrcpath}/build lib.*]
        set libsrc build/${libarch}/obspy/lib
        set libtgt ${worksrcpath}/obspy/lib

        # hack: link to built libraries to make scripts (and help2man) work
        foreach l [glob -tail -directory ${worksrcpath}/${libsrc} *.so] {
            ln -s ../../${libsrc}/${l} ${libtgt}/.
        }

        system -W ${worksrcpath} "${build.cmd} build_man"
    }
    post-destroot {
        system -W ${worksrcpath} "${destroot.cmd} install_man  ${destroot.destdir}"
    }

    # port select
    depends_run-append  port:${_name}_select

    select.group    ${_name}
    select.file     ${filespath}/${_name}${python.version}

    notes-append "
To make this Python ${python.branch} version of ObsPy the default \
(i.e, use its script by their default names, e.g. obspy-runtests, etc.), run:

sudo port select --set ${select.group} [file tail ${select.file}]
    "

    livecheck.type  none
} else {
    livecheck.type  regex
    livecheck.url   https://pypi.python.org/pypi/${_name}/json
    livecheck.regex "\"${_name}-(\[.\\d\]+)\\${extract.suffix}\""
}