# -*- 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 119142 2014-04-18 04:44:18Z eborisch@macports.org $

PortSystem          1.0
name                py-spyder-devel
version             2.3.0beta4
revision            0
# Preference on mailing list is to use small numbers for epoch.
# This is already a date code, so sticking with dates.
epoch               20130508

PortGroup           python 1.0

python.versions     26 27 32 33

PortGroup           qt4 1.0
categories-append   devel
platforms           darwin
maintainers         eborisch openmaintainer
license             MIT
homepage            http://packages.python.org/spyder/
description         Spyder is the Scientific PYthon Development EnviRonment
long_description    ${description}. \
                    Spyder provides a powerful interactive development \
                    environment for the Python language with advanced \
                    editing, interactive testing, debugging and introspection \
                    features as well as a numerical computing environment \
                    thanks to the support of IPython (enhanced interactive \
                    Python interpreter) and popular Python libraries such as \
                    NumPy (linear algebra), SciPy (signal and image \
                    processing) or matplotlib (interactive 2D/3D plotting) \
                    development environment with advanced editing, \
                    interactive testing, debugging and introspection features.

master_sites        https://bitbucket.org/spyder-ide/spyderlib/downloads
distname            spyder-${version}
use_zip             yes
supported_archs     noarch

#pyNN-scipy doesn't build universal
universal_variant   no 

if {${name} ne ${subport}} {
    checksums \
        rmd160  6c9eb242fd1c7c9c1094fb547746e9ce162a11ee \
        sha256  e852e46c61e642a24123bb922eec2d5acf75db802f312bb2836c84a49ba5a084

    conflicts           py${python.version}-spyder
    
    # Set the pylint executable name
    set LINT_BIN_NAME   pylint-${python.branch}
    set WINPDB_BIN_NAME winpdb-${python.branch}
    patchfiles          patch-widgets-pylintgui.py.diff \
                        spyderlib_baseconfig.py.diff \
                        spyderlib_plugins_editor.py.diff \
                        spyderlib_start_app.py.diff \
                        spyderlib_spyder.py.diff \
                        spyderlib_utils_programs.py.diff

    post-patch {
        reinplace "s|@@WINPDB_BIN_NAME@@|${WINPDB_BIN_NAME}|g" \
            ${worksrcpath}/spyderlib/plugins/editor.py
        reinplace "s|@@LINT_BIN_NAME@@|${LINT_BIN_NAME}|g" \
            ${worksrcpath}/spyderplugins/widgets/pylintgui.py
        reinplace "s|\"assistant\"|\"Assistant\"|g" \
            ${worksrcpath}/spyderlib/spyder.py
        reinplace "s|\"linguist\"|\"Linguist\"|g" \
            ${worksrcpath}/spyderlib/spyder.py
        reinplace "s|\"designer\"|\"Designer\"|g" \
            ${worksrcpath}/spyderlib/spyder.py
        reinplace "s|@@PREFIX@@|${prefix}|g" \
            ${worksrcpath}/spyderlib/spyder.py
        reinplace "s|@@APPS_DIR@@|${applications_dir}|g" \
            ${worksrcpath}/spyderlib/utils/programs.py
        reinplace "s|Ctrl\+I|Cmd+I|" \
            ${worksrcpath}/spyderlib/plugins/inspector.py
        # Windows newlines in the file cause compile() (in 2.6) to choke
        reinplace "s|\r||g" \
            ${worksrcpath}/doc/conf.py
    }

    # Can use either py*-pyqt4 or py*-pyqt4-devel.
    # Bare minimum
    depends_lib-append  \
        path:share/py${python.version}-sip/PyQt4:py${python.version}-pyqt4 \
        port:py${python.version}-sphinx \
        port:py${python.version}-zmq
    
    variant tiny description {
        Remove all optional dependencies for quickest install. Dependencies\
        are detected/enabled at runtime and may be installed separately.
    } conflicts small {}

    variant small description {
        Remove most optional dependencies for quicker install. Dependencies\
        are detected/enabled at runtime and may be installed separately.
    } conflicts tiny {}
    
    # These add very little to the install time
    if {![ variant_isset tiny ]} {
        depends_lib-append \
            port:py${python.version}-htmldocs \
            port:py${python.version}-pylint \
            port:py${python.version}-pep8 \
            port:py${python.version}-pyflakes
        if { ${python.version} < 30 } {
            depends_lib-append \
                port:py${python.version}-rope
        }
    }

    # These add substantially to the install time
    if {![ variant_isset small ] &&
        ![ variant_isset tiny  ] } {
        depends_lib-append \
            path:${python.pkgd}/h5py/__init__.py:py${python.version}-h5py \
            port:py${python.version}-ipython \
            port:py${python.version}-matplotlib \
            port:py${python.version}-scipy
    }

    if { ${python.version} < 30 } {
        variant pil description {
           Support image objects in editor through PIL (many dependencies.)
        } {
            depends_lib-append \
                port:py${python.version}-pil
        }
    }

    post-extract {
      fs-traverse f ${worksrcpath} {
        touch $f
      }
    }
    
    post-destroot {
        if {${python.version} == ${python.default_version}} {
          ln -s ${python.prefix}/bin/spyder ${destroot}${prefix}/bin/
        }

        set OPTCMD    [concat "HOME=${destroot}/tmp/spyder "  \
                       "PYTHONPATH=${destroot}${python.pkgd} "  \
                       "./spyder --optimize"]
        
        file mkdir ${destroot}/tmp/spyder
        system "cd ${destroot}${python.prefix}/bin && ${OPTCMD}"
        delete ${destroot}/tmp/spyder
        delete \
          ${destroot}${prefix}/bin/spyder_win_post_install.py-${python.branch}
        delete ${destroot}${python.prefix}/bin/spyder_win_post_install.py
    }

    if {${python.version} == ${python.default_version}} {
        set EXENAME   "'spyder'    "
    } else {
        set EXENAME   "'spyder-${python.branch}'"
    }
    
    notes \
"
##############################################################
### Spyder is launched from the terminal with ${EXENAME} ###
##############################################################"
}

livecheck.type      regex
livecheck.url       https://bitbucket.org/spyder-ide/spyderlib/downloads
livecheck.regex     spyder-(\[0-9\]+(\.\[0-9betarc]+)*)\.zip
