# -*- 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
# $Id: Portfile 120332 2014-05-23 14:17:14Z stromnov@macports.org $

PortSystem          1.0
PortGroup           python 1.0
PortGroup           select 1.0

set realname        ipython

name                py-${realname}
version             2.1.0
revision            0
platforms           darwin
license             BSD
supported_archs     noarch

python.versions     24 25 26 27 31 32 33 34

maintainers         akitada openmaintainer

description         An enhanced Interactive Python shell
long_description    Provide an interactive shell superior to the Python default. \
                    Serve as an embeddable, ready to use interpreter for your own programs. \
                    Offer a flexible framework which can be used as the base environment for \
                    other systems with Python as the underlying language.  \
                    Allow interactive testing of threaded graphical toolkits.

homepage            http://ipython.org
master_sites        http://pypi.python.org/packages/source/i/ipython/ \
                    https://github.com/ipython/ipython/releases/download/rel-${version} \
                    https://github.com/ipython/ipython/archive/

distname            ${realname}-${version}

checksums           rmd160  be336a84908bd9ee0476ea6986193c8b034c4988 \
                    sha256  ca86a6308c4b53ea8a040ba776066dc9a7af4ac738ad43ab2059a016c09b0c2d

# IPython 1.0 requires Python ≥ 2.6.5 or ≥ 3.2.1. It does not support Python 3.0, 3.1, or 2.5.
# IPython 2.0 requires Python ≥ 2.7 or ≥ 3.3.
if {${name} ne ${subport} && [lsearch {24 25 26 31 32} ${python.version}] != -1} {
    if {${subport} eq "py24-${realname}" || ${subport} eq "py25-${realname}"} {
        version             0.10.2
        revision            1
        checksums           rmd160  365a4eb9b534df1a9aa8717f173e9a032224ea01 \
                            sha256  9ed5fe693d92e6ba9ecc3e367ae5607b80d66db53b0a636fa39fe15ae3df8c47
    } elseif {${subport} eq "py26-${realname}" || ${subport} eq "py32-${realname}"} {
        version             1.2.1
        revision            0
        checksums           rmd160  318f97b515bd984d5eaac0e2558a5d67e3d5378d \
                            sha256  c27aeae9b8e5c4a2d28ba0f04b879216d6f96f36380cd465a823b1efb0595874
    } elseif {${subport} eq "py31-${realname}"} {
        version             0.13.2
        revision            1
        checksums           rmd160  afdd4e7fed6b3d23d5577b66671c9b868ef1f847 \
                            sha256  17fbeea1dff2318d617d90fdf7af4eb35dc48c61389a2dffaab8ff100fb100ea
    }
    master_sites        http://archive.ipython.org/release/${version}
    distname            ${realname}-${version}
}

if {${name} ne ${subport} && ${python.version} < 30 && ${python.version} > 25} {
    variant scientific description "Use ScientificPython to provide physical quantities support" {
        depends_lib-append      port:py${python.version}-scientific
    }
    default_variants        +scientific
}

if {${name} ne ${subport} && ${python.version} >= 26} {
    variant parallel description "Support for parallel computing" {
        depends_lib-append      port:py${python.version}-zmq
    }

    variant notebook requires parallel description "Support for IPython HTML notebook" {
        depends_lib-append      port:py${python.version}-jinja2 \
                                port:py${python.version}-requests \
                                port:py${python.version}-sphinx \
                                port:py${python.version}-tornado
    }

    variant pyqt4 conflicts pyside requires parallel description "Support for the Qt console using pyqt4" {
        # Can use either py*-pyqt4 or py*-pyqt4-devel.
        depends_lib-append      path:share/py${python.version}-sip/PyQt4:py${python.version}-pyqt4 \
                                port:py${python.version}-pygments
    }

    variant pyside conflicts pyqt4 requires parallel description "Support for the Qt console using pyside" {
        depends_lib-append      port:py${python.version}-pyside \
                                port:py${python.version}-pygments
    }
}

if {${name} ne ${subport}} {
    depends_lib-append      port:py${python.version}-readline
    depends_run             port:ipython_select

    if {${python.version} >= 30} {
        depends_build-append    port:py${python.version}-setuptools
    }

    if {${python.version} >= 25} {
        depends_build-append    port:gzip
    }

    post-destroot {
        if {${subport} eq "py24-${realname}"} {
            foreach f {ipython pycolor} {
                move ${destroot}${prefix}/share/man/man1/${f}.1.gz \
                     ${destroot}${prefix}/share/man/man1/${f}-${python.branch}.1.gz
            }
            move ${destroot}${prefix}/share/doc/${realname} ${destroot}${prefix}/share/doc/${subport}
        } elseif {${subport} eq "py25-${realname}"} {
            foreach f {ipcluster ipcontroller ipengine ipython ipython-wx ipythonx irunner pycolor} {
                move ${destroot}${prefix}/share/man/man1/${f}.1.gz \
                     ${destroot}${prefix}/share/man/man1/${f}-${python.branch}.1.gz
            }
            move ${destroot}${prefix}/share/doc/${realname} ${destroot}${prefix}/share/doc/${subport}
        } elseif {${subport} eq "py26-${realname}" || ${subport} eq "py31-${realname}" || ${subport} eq "py32-${realname}"} {
            # Since IPython 0.13, the man pages are no longer gzipped, so to ensure
            # that ipython_select works correctly, we gzip the man pages.
            set gzip [findBinary gzip ${portutil::autoconf::gzip_path}]
            foreach f {ipcluster ipcontroller ipengine iplogger ipython irunner pycolor} {
                system "$gzip -9vf ${destroot}${python.prefix}/share/man/man1/${f}.1"
                file attributes ${destroot}${python.prefix}/share/man/man1/${f}.1.gz -permissions 00444
                ln -s ${python.prefix}/share/man/man1/${f}.1.gz ${destroot}${prefix}/share/man/man1/${f}-${python.branch}.1.gz
            }
        } else {
            # Since IPython 0.13, the man pages are no longer gzipped, so to ensure
            # that ipython_select works correctly, we gzip the man pages.
            set gzip [findBinary gzip ${portutil::autoconf::gzip_path}]
            foreach f {ipcluster ipcontroller ipengine ipython} {
                system "$gzip -9vf ${destroot}${python.prefix}/share/man/man1/${f}.1"
                file attributes ${destroot}${python.prefix}/share/man/man1/${f}.1.gz -permissions 00444
                ln -s ${python.prefix}/share/man/man1/${f}.1.gz ${destroot}${prefix}/share/man/man1/${f}-${python.branch}.1.gz
            }
        }
    }

    test.run                no

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

    notes "
To make the Python ${python.branch} version of IPython the one that is run\
when you execute the commands without a version suffix, e.g. 'ipython', run:

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

    livecheck.type          none
} else {
    livecheck.type          regex
    livecheck.url           http://pypi.python.org/packages/source/i/ipython/
    livecheck.regex         ${realname}-(\\d+(?:\\.\\d+)*)
}
