# -*- 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 107562 2013-07-03 00:39:44Z sean@macports.org $

PortSystem          1.0
PortGroup           python 1.0
PortGroup           select 1.0

set realname        ipython

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

maintainers         akitada openmaintainer

description         An enhanced Interactive Python shell
long_description    Provide an interactive shell superior to Python's 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://archive.ipython.org/release/${version}
distname            ${realname}-${version}

checksums           rmd160  afdd4e7fed6b3d23d5577b66671c9b868ef1f847 \
                    sha256  17fbeea1dff2318d617d90fdf7af4eb35dc48c61389a2dffaab8ff100fb100ea

python.versions     24 25 26 27 31 32 33

subport py24-${realname} {
    version             0.10.2
    master_sites        http://archive.ipython.org/release/${version}
    distname            ${realname}-${version}
    checksums           md5     dda59bfc6e256ce786c4bc4aadb220a4 \
                        sha1    d45b97b0f458fd517cb2bfa9ebb3c671c46a21c0 \
                        rmd160  365a4eb9b534df1a9aa8717f173e9a032224ea01
}

subport py25-${realname} {
    version             0.10.2
    revision            2
    master_sites        http://archive.ipython.org/release/${version}
    distname            ${realname}-${version}
    checksums           md5     dda59bfc6e256ce786c4bc4aadb220a4 \
                        sha1    d45b97b0f458fd517cb2bfa9ebb3c671c46a21c0 \
                        rmd160  365a4eb9b534df1a9aa8717f173e9a032224ea01
}

if {$subport != "py31-${realname}" && $subport != "py32-${realname}" && $subport != "py33-${realname}" && $subport != $name} {
    variant scientific description "Use ScientificPython to provide physical quantities support" {
        depends_lib-append      port:py${python.version}-scientific
    }
    default_variants        +scientific
}

if {$subport == "py26-${realname}" || $subport == "py27-${realname}"} {
    variant pyqt4 conflicts pyside requires parallel description "Support for the Qt console using pyqt4" {
        depends_lib-append      port: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 {$subport != "py24-${realname}" && $subport != "py25-${realname}"} {
    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}-tornado
    }
}

if {$subport != $name} {

    post-destroot {
        if {$subport == "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 == "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 == "py26-${realname}" || $subport == "py27-${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
            }
            depends_build-append port:gzip
        } elseif {$subport == "py31-${realname}" || $subport == "py32-${realname}" || $subport == "py33-${realname}"} {
            # IPython does not appear to install man pages with Python 3. If this
            # works again in future, the man pages may have to be gzipped as for
            # Python 2.6 and 2.7. In addition, the man pages should be added back
            # to files/python31 and files/python32.
            # foreach f {ipcluster ipcontroller ipengine iplogger ipython irunner pycolor} {
            #    ln -s ${python.prefix}/share/man/man1/${f}.1.gz ${destroot}${prefix}/share/man/man1/${f}3-${python.branch}.1.gz
            # }
        }
    }

    if {${python.version} >= 30} {
        depends_build-append    port:py${python.version}-setuptools
    }
    depends_lib-append      port:py${python.version}-readline
    depends_run             port:ipython_select
    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}]
"
}

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