Exemplo n.º 1
0
def define_custom_scripts(tpl_rman):
    if ut.in_virtual_env():
        fmtdict = {
            'sys_dist_packages': ut.get_global_dist_packages_dir(),
            'venv_site_packages': ut.get_site_packages_dir(),
        }
        # Allows us to use a system qt install in a virtual environment.
        tpl_rman['PyQt4'].add_script(
            'system_to_venv',
            ut.codeblock(r"""
            # STARTBLOCK bash
            ln -s {sys_dist_packages}/PyQt4/ {venv_site_packages}/PyQt4
            ln -s {sys_dist_packages}/sip*.so {venv_site_packages}/
            ln -s {sys_dist_packages}/sip*.py {venv_site_packages}/
            # ENDBLOCK bash
            """)).format(**fmtdict)
        # TODO: add custom build alternative
        pass
    else:
        pass

    ibeis_rman['pyflann'].add_script(
        'install',
        ut.codeblock(r'''
        # STARTBLOCK bash
        # The pyflann source lives here
        cd {repo_dir}/src/python
        # But the setup script is generated during build
        python {repo_dir}/build/src/python/setup.py develop
        # ENDBLOCK bash
        ''').format(repo_dir=ibeis_rman['pyflann'].dpath))

    # TODO: allow system installation as well
    tpl_rman['cv2'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        cd $CODE_DIR
        git clone https://github.com/Itseez/opencv.git
        cd opencv
        # Get Extras
        git clone https://github.com/Itseez/opencv_contrib.git
        mkdir -p build27
        cd build27

        if [[ "$VIRTUAL_ENV" == ""  ]]; then
            export LOCAL_PREFIX=/usr/local
            export PYTHON2_PACKAGES_PATH=$LOCAL_PREFIX/lib/python2.7/dist-packages
        else
            export LOCAL_PREFIX=$VIRTUAL_ENV/local
            export PYTHON2_PACKAGES_PATH=$LOCAL_PREFIX/lib/python2.7/site-packages
        fi

        echo "LOCAL_PREFIX = $LOCAL_PREFIX"
        echo "PYTHON2_PACKAGES_PATH = $PYTHON2_PACKAGES_PATH"
        # use dist packages on ubuntu. may need to change for other platforms
        cmake -G "Unix Makefiles" \
            -D WITH_OPENMP=ON \
            -D CMAKE_BUILD_TYPE=RELEASE \
            -D PYTHON2_PACKAGES_PATH=$PYTHON2_PACKAGES_PATH \
            -D CMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \
            -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
            ..

        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS
        # ENDBLOCK
        """))

    tpl_rman['cv2'].add_script(
        'install',
        ut.codeblock(r"""
        # STARTBLOCK bash
        cd $CODE_DIR
        sudo make install
        # Hack because cv2 does not want to be installed for some reason
        cp lib/cv2.so $PYTHON2_PACKAGES_PATH
        # Test makesure things working
        python -c "import numpy; print(numpy.__file__)"
        python -c "import numpy; print(numpy.__version__)"
        python -c "import cv2; print(cv2.__version__)"
        python -c "import cv2; print(cv2.__file__)"
        #python -c "import vtool"

        # Check if we have contrib modules
        python -c "import cv2; print(cv2.xfeatures2d)"
        # ENDBLOCK
        """))
Exemplo n.º 2
0
def define_custom_scripts(tpl_rman, wbia_rman, PY2, PY3):
    """
    export THEANO_FLAGS="device=cpu,print_active_device=True,enable_initial_driver_test=True"
    set THEANO_FLAGS=device=cpu,print_active_device=True,enable_initial_driver_test=True,print_test_value=True

    python -c "import pydot; print(pydot.__file__)"
    python -c "import pydot; print(pydot.__version__)"
    python -c "import pydot; print(pydot.find_graphviz())"
    DEVICE="cuda" python -c "import pygpu;pygpu.test()"
    python -c "import theano; print(theano.__file__)"
    # python -c "import pylearn2; print(pylearn2.__file__)"
    python -c "import lasagne; print(lasagne.__file__)"
    python -c "import wbia_cnn; print(wbia_cnn.__file__)"
    python -c "import detecttools; print(detecttools.__file__)"

    # http://stackoverflow.com/questions/18042919/how-to-install-pyqt5-on-a-new-virtualenv-and-work-on-an-idle
    pip install vext.pyqt5
    sudo apt-get install pyqt5-dev
    sudo apt-get install python3-pyqt5
    python
    python -c "import sip; print('[test] Python can import sip')"
    python -c "import sip; print('sip.__file__=%r' % (sip.__file__,))"
    python -c "import sip; print('sip.SIP_VERSION=%r' % (sip.SIP_VERSION,))"
    python -c "import sip; print('sip.SIP_VERSION_STR=%r' % (sip.SIP_VERSION_STR,))"

    ln -s /usr/lib/python3/dist-packages/PyQt5/ /home/joncrall/venv3/lib/python3.4/site-packages/PyQt5
    ln -s /usr/lib/python3/dist-packages/sip*.so /home/joncrall/venv3/lib/python3.4/site-packages/
    ln -s /usr/lib/python3/dist-packages/sip*.py /home/joncrall/venv3/lib/python3.4/site-packages/
    """
    import utool as ut

    major = str(sys.version_info.major)
    minor = str(sys.version_info.minor)
    majorminor = [major, minor]
    pyoff = '2' if sys.version_info.major == 3 else '3'
    pyon = majorminor[0]
    plat_spec = get_plat_specifier()
    # build_dname = 'build' + ''.join(majorminor)
    build_dname = 'cmake_builds/build' + plat_spec

    script_fmtdict = {
        'pyexe': sys.executable,
        'pyversion': 'python' + '.'.join(majorminor),
        'pypkg_var': 'PYTHON' + pyon + '_PACKAGES_PATH',
        'build_dname': build_dname,
        'pyoff': pyoff,
        'pyon': pyon,
        'cv_pyon_var': 'BUILD_opencv_python' + pyon,
        'cv_pyoff_var': 'BUILD_opencv_python' + pyoff,
        'plat_spec': plat_spec,
        'source_dpath': '../..',
        'libext': ut.get_lib_ext(),
    }

    if os.environ.get('VIRTUAL_ENV', '') == '':
        if sys.platform.startswith('darwin'):
            local_prefix = '/opt/local'
        else:
            local_prefix = '/usr/local'
    else:
        local_prefix = os.environ['VIRTUAL_ENV']

    opencv_dir = os.path.join(local_prefix, '/share/OpenCV')
    if not os.path.exists(opencv_dir):
        if not ut.get_argflag('--opencv'):
            opencv_dir = ''
            print(
                'OpenCV is not installed in the expected location: {}'.format(
                    opencv_dir))
            print(
                'Running this script with --opencv will build and install it there'
            )

    # define bash variables for different combinations of python distros and
    # virtual environments
    python_bash_setup = ut.codeblock(r"""
        # STARTBLOCK bash

        if [[ "$VIRTUAL_ENV" == ""  ]]; then
            # The case where we are installying system-wide
            # It is recommended that a virtual enviornment is used instead
            export PYTHON_EXECUTABLE=$(which {pyversion})
            if [[ '$OSTYPE' == 'darwin'* ]]; then
                # Mac system info
                export LOCAL_PREFIX=/opt/local
                export {pypkg_var}=$($PYTHON_EXECUTABLE -c "import site; print(site.getsitepackages()[0])")
                export PYTHON_PACKAGES_PATH=${pypkg_var}
                export _SUDO="sudo"
            else
                # Linux system info
                export LOCAL_PREFIX=/usr/local
                export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/dist-packages
                export PYTHON_PACKAGES_PATH=${pypkg_var}
                export _SUDO="sudo"
            fi
            # No windows support here
        else
            # The prefered case where we are in a virtual environment
            export PYTHON_EXECUTABLE=$(which python)
            # export LOCAL_PREFIX=$VIRTUAL_ENV/local
            export LOCAL_PREFIX=$VIRTUAL_ENV
            export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/site-packages
            export PYTHON_PACKAGES_PATH=${pypkg_var}
            export _SUDO=""
        fi

        echo "LOCAL_PREFIX = $LOCAL_PREFIX"
        echo "{pypkg_var} = ${pypkg_var}"
        # ENDBLOCK bash
        """).format(**script_fmtdict)
    script_fmtdict['python_bash_setup'] = python_bash_setup

    # ===================
    # PYFLANN SETUP SCRIPTS
    # ===================

    wbia_rman['pyflann'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}

        cd {repo_dir}
        mkdir -p {build_dname}
        cd {build_dname}

        cmake -G "Unix Makefiles" \
            -DCMAKE_BUILD_TYPE="Release" \
            -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
            -DBUILD_EXAMPLES=Off \
            -DBUILD_TESTS=Off \
            -DBUILD_PYTHON_BINDINGS=On \
            -DBUILD_MATLAB_BINDINGS=Off \
            -DBUILD_CUDA_LIB=Off\
            -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX\
            {source_dpath}

        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS

        # ENDBLOCK bash
        """).format(repo_dir=wbia_rman['pyflann'].dpath, **script_fmtdict),
    )

    wbia_rman['pyflann'].add_script(
        'install',
        ut.codeblock(r"""
        # STARTBLOCK bash
        # The pyflann source lives here
        cd {repo_dir}/src/python
        # Need to run build to move the libs to the build directory
        python setup.py build
        # Use pip to editable install
        pip install -e {repo_dir}/src/python

        # Old way of doing it
        # But the setup script is generated during build
        # python {repo_dir}/build/src/python/setup.py develop

        python -c "from vtool_ibeis._pyflann_backend import pyflann as pyflann; print(pyflann.__file__)" --verb-flann
        python -c "from vtool_ibeis._pyflann_backend import pyflann as pyflann; print(pyflann)" --verb-flann
        # ENDBLOCK bash
        """).format(repo_dir=wbia_rman['pyflann'].dpath),
    )

    # ===================
    # HESAFF
    # ===================

    wbia_rman['hesaff'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}
        cd $CODE_DIR/hesaff
        mkdir -p {build_dname}
        cd {build_dname}

        # only specify an explicit opencv directory if we know one exists
        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then
            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"
        else
            OPENCV_ARGS=""
        fi

        echo 'Configuring with cmake'
        if [[ '$OSTYPE' == 'darwin'* ]]; then
            cmake -G "Unix Makefiles" \
                -DCMAKE_OSX_ARCHITECTURES=x86_64 \
                -DCMAKE_C_COMPILER=clang2 \
                -DCMAKE_CXX_COMPILER=clang2++ \
                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \
                $OPENCV_ARGS \
                {source_dpath}
        else
            cmake -G "Unix Makefiles" \
                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \
                $OPENCV_ARGS \
                {source_dpath}
        fi

        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS

        export MAKE_EXITCODE=$?
        echo "MAKE_EXITCODE=$MAKE_EXITCODE"

        # Move the compiled library into the source folder
        if [[ $MAKE_EXITCODE == 0 ]]; then
            #make VERBOSE=1
            cp -v libhesaff{libext} {source_dpath}/pyhesaff/libhesaff{plat_spec}{libext}
        fi

        # ENDBLOCK
        """).format(**script_fmtdict),
    )

    # ===================
    # PYDARKNET
    # ===================

    wbia_rman['pydarknet'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}
        cd $CODE_DIR/pydarknet

        mkdir -p {build_dname}
        cd {build_dname}

        if [[ "$(which nvcc)" == "" ]]; then
            export CMAKE_CUDA=Off
        else
            export CMAKE_CUDA=On
        fi

        # only specify an explicit opencv directory if we know one exists
        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then
            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"
        else
            OPENCV_ARGS=""
        fi

        echo 'Configuring with cmake'
        if [[ '$OSTYPE' == 'darwin'* ]]; then
            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"
        else
            export CONFIG="-DCMAKE_BUILD_TYPE='Release' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"
        fi
        export CONFIG="$CONFIG -DCUDA=$CMAKE_CUDA"
        echo "CONFIG = $CONFIG"

        cmake $CONFIG -G 'Unix Makefiles' {source_dpath}
        #################################
        echo 'Building with make'
        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS -w
        #################################

        export MAKE_EXITCODE=$?
        echo "MAKE_EXITCODE=$MAKE_EXITCODE"

        # Move the compiled library into the source folder
        if [[ $MAKE_EXITCODE == 0 ]]; then
            echo 'Moving the shared library'
            # cp -v lib* ../pydarknet
            cp -v lib*{libext} {source_dpath}/pydarknet
            # cp -v libdarknet{libext} {source_dpath}/pydarknet/libdarknet{plat_spec}{libext}
        fi

        # ENDBLOCK
        """).format(**script_fmtdict),
    )

    # ===================
    # PYRF
    # ===================

    wbia_rman['pyrf'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}
        cd $CODE_DIR/pyrf

        mkdir -p {build_dname}
        cd {build_dname}

        # only specify an explicit opencv directory if we know one exists
        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then
            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"
        else
            OPENCV_ARGS=""
        fi

        echo 'Configuring with cmake'
        if [[ '$OSTYPE' == 'darwin'* ]]; then
            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"
        else
            export CONFIG="-DCMAKE_BUILD_TYPE='Release' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"
        fi
        echo "CONFIG = $CONFIG"

        cmake $CONFIG -G 'Unix Makefiles' {source_dpath}
        #################################
        echo 'Building with make'
        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS -w
        #################################

        export MAKE_EXITCODE=$?
        echo "MAKE_EXITCODE=$MAKE_EXITCODE"

        # Move the compiled library into the source folder
        if [[ $MAKE_EXITCODE == 0 ]]; then
            echo 'Moving the shared library'
            # cp -v lib* ../pyrf
            cp -v lib*{libext} {source_dpath}/pyrf
            # cp -v libpyrf{libext} {source_dpath}/pyrf/libpyrf{plat_spec}{libext}
        fi

        # ENDBLOCK
        """).format(**script_fmtdict),
    )

    # ===================
    # OPENCV SETUP SCRIPTS
    # ===================
    """
    ./super_setup.py --dump-scripts
    """
    tpl_rman['cv2'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}
        # Checkout opencv core
        cd $CODE_DIR
        # export REPO_DIR=$CODE_DIR/opencv
        export REPO_DIR={repo_dpath}
        # git clone https://github.com/Itseez/opencv.git
        cd $REPO_DIR
        # Checkout opencv extras
        git clone https://github.com/Itseez/opencv_contrib.git
        # cd opencv_contrib
        # git pull
        # cd ..
        # git pull
        mkdir -p $REPO_DIR/{build_dname}
        cd $REPO_DIR/{build_dname}

        cmake -G "Unix Makefiles" \
            -D WITH_OPENMP=ON \
            -D CMAKE_BUILD_TYPE=RELEASE \
            -D {cv_pyoff_var}=Off \
            -D {cv_pyon_var}=On \
            -D PYTHON_DEFAULT_EXECUTABLE="{pyexe}" \
            -D {pypkg_var}=${pypkg_var} \
            -D CMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \
            -D OPENCV_EXTRA_MODULES_PATH=$REPO_DIR/opencv_contrib/modules \
            -D WITH_CUDA=Off \
            -D BUILD_opencv_dnn=Off \
            -D BUILD_opencv_dnn_modern=Off \
            -D WITH_VTK=Off \
            -D WITH_CUDA=Off \
            -D WITH_MATLAB=Off \
            $REPO_DIR
            # -D WITH_OPENCL=Off \
            # -D BUILD_opencv_face=Off \
            # -D BUILD_opencv_objdetect=Off \
            # -D BUILD_opencv_video=Off \
            # -D BUILD_opencv_videoio=Off \
            # -D BUILD_opencv_videostab=Off \
            # -D BUILD_opencv_ximgproc=Off \
            # -D BUILD_opencv_xobjdetect=Off \
            # -D BUILD_opencv_xphoto=Off \
            # -D BUILD_opencv_datasets=Off \
            # -D CXX_FLAGS="-std=c++11" \ %TODO

        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS
        # ENDBLOCK
        """).format(repo_dpath=ut.unexpanduser(tpl_rman['cv2'].dpath),
                    **script_fmtdict),
    )

    tpl_rman['cv2'].add_script(
        'install',
        ut.codeblock(r"""
        # STARTBLOCK bash
        {python_bash_setup}

        cd $CODE_DIR/opencv/{build_dname}

        $_SUDO make install
        # Hack because cv2 does not want to be installed for some reason
        # cp lib/cv2.so $PYTHON_PACKAGES_PATH
        # Seems to work now that local is removed from prefix
        # cp -v lib/cv2.so $PYTHON_PACKAGES_PATH
        # Test makesure things working
        python -c "import numpy; print(numpy.__file__)"
        python -c "import numpy; print(numpy.__version__)"
        python -c "import cv2; print(cv2.__version__)"
        python -c "import cv2; print(cv2.__file__)"
        #python -c "import vtool_ibeis"
        # Check if we have contrib modules
        python -c "import cv2; print(cv2.xfeatures2d)"
        # ENDBLOCK
        """).format(**script_fmtdict),
    )

    # if GET_ARGFLAG('--libgpuarray'):
    tpl_rman['libgpuarray'].add_script(
        'build',
        ut.codeblock(r"""
        # STARTBLOCK bash

        # Ensure the repo was checked out
        if [ ! -d {repo_dpath} ]; then
            git clone https://github.com/Theano/libgpuarray.git {repo_dpath}
        fi


        {python_bash_setup}
        cd {repo_dpath}

        # need a specific version of libgpuarray
        git checkout tags/v0.6.2 -b v0.6.2

        mkdir -p {repo_dpath}/{build_dname}
        cd {repo_dpath}/{build_dname}

        # First build the C library
        cmake {repo_dpath} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX
        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS
        $_SUDO make install

        # Now build the python libarary
        cd {repo_dpath}
        python setup.py build_ext -L $LOCAL_PREFIX/lib -I $LOCAL_PREFIX/include
        python setup.py build
        # python setup.py install
        $_SUDO pip install -e {repo_dpath}

        # DEVICE="<test device>" python -c "import pygpu;pygpu.test()"
        # DEVICE="gpu0" python -c "import pygpu;pygpu.test()"
        cd ~
        $_SUDO pip install nose
        DEVICE="cuda" python -c "import pygpu;pygpu.test()"

        # pip uninstall pygpu
        # ENDBLOCK
        """).format(repo_dpath=ut.unexpanduser(tpl_rman['libgpuarray'].dpath),
                    **script_fmtdict),
    )

    # ===================
    # PYQT SETUP SCRIPTS
    # ===================

    if ut.in_virtual_env():
        try:
            fmtdict = {
                'sys_dist_packages':
                ut.get_global_dist_packages_dir(),
                'venv_site_packages':
                ut.get_site_packages_dir(),
                'pyqt':
                'PyQt4' if PY2 else 'PyQt5',
                # Need the PyQT5 SVG module for IPython to work properly
                'debian-python-qt':
                ('python-qt4'
                 if PY2 else 'qt5-default python3-pyqt5 debian-python-qt-svg'),
                'pip-python-qt':
                'python-qt4' if PY2 else 'python-qt5',
            }
            # sys_dist_packages = ut.get_global_dist_packages_dir()
            # sys_pyqt_dir = sys_dist_packages + '/{pyqt}'
            # Allows us to use a system qt install in a virtual environment.
            system_to_venv = ut.codeblock(r"""
                # STARTBLOCK bash
                # Creates a symlink to the global PyQt in a virtual env
                export GLOBAL_DIST_PACKAGES="{sys_dist_packages}"
                export VENV_DIST_PACKAGES="{venv_site_packages}"
                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then
                    echo "have qt"
                    ls $GLOBAL_DIST_PACKAGES/{pyqt}
                    ls $VENV_DIST_PACKAGES/{pyqt}
                else
                    # Ensure PyQt is installed first (FIXME make this work for non-debian systems)
                    sudo apt-get install {debian-python-qt}
                    # pip install {pip-python-qt}
                fi
                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then
                    # Install system pyqt packages to virtual envirment via symlink
                    ln -s $GLOBAL_DIST_PACKAGES/{pyqt}/ $VENV_DIST_PACKAGES/{pyqt}
                    ln -s $GLOBAL_DIST_PACKAGES/sip*.so $VENV_DIST_PACKAGES/
                    ln -s $GLOBAL_DIST_PACKAGES/sip*.py $VENV_DIST_PACKAGES/
                else
                    echo "{pyqt} DOES NOT SEEM TO BE INSTALLED ON THE SYSTEM"
                fi
                echo "testing"
                python -c "import {pyqt}; print({pyqt})"
                # ENDBLOCK bash
                """).format(**fmtdict)
            # TODO: add custom build alternative
            tpl_rman['PyQt'].add_script('system_to_venv', system_to_venv)
        except NotImplementedError:
            pass
Exemplo n.º 3
0
def total_purge_developed_repo(repodir):
    r"""
    Outputs commands to help purge a repo

    Args:
        repodir (str): path to developed repository

    CommandLine:
        python -m utool.util_sysreq total_purge_installed_repo --show

    Ignore:
        repodir = ut.truepath('~/code/Lasagne')

    Example:
        >>> # DISABLE_DOCTEST
        >>> from utool.util_sysreq import *  # NOQA
        >>> import utool as ut
        >>> repodir = ut.get_argval('--repodir', default=None)
        >>> result = total_purge_installed_repo(repodir)
    """
    assert repodir is not None
    import utool as ut
    import os
    repo = ut.util_git.Repo(dpath=repodir)

    user = os.environ['USER']

    fmtdict = dict(
        user=user,
        modname=repo.modname,
        reponame=repo.reponame,
        dpath=repo.dpath,
        global_site_pkgs=ut.get_global_dist_packages_dir(),
        local_site_pkgs=ut.get_local_dist_packages_dir(),
        venv_site_pkgs=ut.get_site_packages_dir(),
    )

    commands = [
        _.format(**fmtdict) for _ in [
            'pip uninstall {modname}',
            'sudo -H pip uninstall {modname}',
            'sudo pip uninstall {modname}',
            'easy_install -m {modname}',
            'cd {dpath} && python setup.py develop --uninstall',
            # If they still exist try chowning to current user
            'sudo chown -R {user}:{user} {dpath}',
        ]
    ]
    print('Normal uninstall commands')
    print('\n'.join(commands))

    possible_link_paths = [
        _.format(**fmtdict) for _ in [
            '{dpath}/{modname}.egg-info',
            '{dpath}/build',
            '{venv_site_pkgs}/{reponame}.egg-info',
            '{local_site_pkgs}/{reponame}.egg-info',
            '{venv_site_pkgs}/{reponame}.egg-info',
        ]
    ]
    from os.path import exists, basename
    existing_link_paths = [path for path in possible_link_paths]
    print('# Delete paths and eggs')
    for path in existing_link_paths:
        if exists(path):
            if ut.get_file_info(path)['owner'] != user:
                print('sudo /bin/rm -rf {path}'.format(path=path))
            else:
                print('/bin/rm -rf {path}'.format(path=path))
        #ut.delete(path)

    print('# Make sure nothing is in the easy install paths')
    easyinstall_paths = [
        _.format(**fmtdict) for _ in [
            '{venv_site_pkgs}/easy-install.pth',
            '{local_site_pkgs}/easy-install.pth',
            '{venv_site_pkgs}/easy-install.pth',
        ]
    ]
    for path in easyinstall_paths:
        if exists(path):
            easy_install_list = ut.readfrom(path,
                                            verbose=False).strip().split('\n')
            easy_install_list_ = [basename(p) for p in easy_install_list]
            index1 = ut.listfind(easy_install_list_, repo.reponame)
            index2 = ut.listfind(easy_install_list_, repo.modname)
            if index1 is not None or index2 is not None:
                print('Found at index1=%r, index=%r' % (index1, index2))
                if ut.get_file_info(path)['owner'] != user:
                    print('sudo gvim {path}'.format(path=path))
                else:
                    print('gvim {path}'.format(path=path))

    checkcmds = [
        _.format(**fmtdict)
        for _ in ['python -c "import {modname}; print({modname}.__file__)"']
    ]
    import sys
    assert repo.modname not in sys.modules
    print("# CHECK STATUS")
    for cmd in checkcmds:
        print(cmd)
Exemplo n.º 4
0
def total_purge_developed_repo(repodir):
    r"""
    Outputs commands to help purge a repo

    Args:
        repodir (str): path to developed repository

    CommandLine:
        python -m utool.util_sysreq total_purge_installed_repo --show

    Ignore:
        repodir = ut.truepath('~/code/Lasagne')

    Example:
        >>> # DISABLE_DOCTEST
        >>> from utool.util_sysreq import *  # NOQA
        >>> import utool as ut
        >>> repodir = ut.get_argval('--repodir', default=None)
        >>> result = total_purge_installed_repo(repodir)
    """
    assert repodir is not None
    import utool as ut
    import os
    repo = ut.util_git.Repo(dpath=repodir)

    user = os.environ['USER']

    fmtdict = dict(
        user=user,
        modname=repo.modname,
        reponame=repo.reponame,
        dpath=repo.dpath,
        global_site_pkgs=ut.get_global_dist_packages_dir(),
        local_site_pkgs=ut.get_local_dist_packages_dir(),
        venv_site_pkgs=ut.get_site_packages_dir(),
    )

    commands = [_.format(**fmtdict) for _ in [
        'pip uninstall {modname}',
        'sudo -H pip uninstall {modname}',
        'sudo pip uninstall {modname}',
        'easy_install -m {modname}',
        'cd {dpath} && python setup.py develop --uninstall',
        # If they still exist try chowning to current user
        'sudo chown -R {user}:{user} {dpath}',
    ]]
    print('Normal uninstall commands')
    print('\n'.join(commands))

    possible_link_paths = [_.format(**fmtdict) for _ in [
        '{dpath}/{modname}.egg-info',
        '{dpath}/build',
        '{venv_site_pkgs}/{reponame}.egg-info',
        '{local_site_pkgs}/{reponame}.egg-info',
        '{venv_site_pkgs}/{reponame}.egg-info',
    ]]
    from os.path import exists, basename
    existing_link_paths = [path for path in possible_link_paths]
    print('# Delete paths and eggs')
    for path in existing_link_paths:
        if exists(path):
            if ut.get_file_info(path)['owner'] != user:
                print('sudo /bin/rm -rf {path}'.format(path=path))
            else:
                print('/bin/rm -rf {path}'.format(path=path))
        #ut.delete(path)

    print('# Make sure nothing is in the easy install paths')
    easyinstall_paths = [_.format(**fmtdict) for _ in [
        '{venv_site_pkgs}/easy-install.pth',
        '{local_site_pkgs}/easy-install.pth',
        '{venv_site_pkgs}/easy-install.pth',
    ]]
    for path in easyinstall_paths:
        if exists(path):
            easy_install_list = ut.readfrom(path, verbose=False).strip().split('\n')
            easy_install_list_ = [basename(p) for p in easy_install_list]
            index1 = ut.listfind(easy_install_list_, repo.reponame)
            index2 = ut.listfind(easy_install_list_, repo.modname)
            if index1 is not None or index2 is not None:
                print('Found at index1=%r, index=%r' % (index1, index2))
                if ut.get_file_info(path)['owner'] != user:
                    print('sudo gvim {path}'.format(path=path))
                else:
                    print('gvim {path}'.format(path=path))

    checkcmds = [_.format(**fmtdict) for _ in [
        'python -c "import {modname}; print({modname}.__file__)"'
    ]]
    import sys
    assert repo.modname not in sys.modules
    print("# CHECK STATUS")
    for cmd in checkcmds:
        print(cmd)
Exemplo n.º 5
0
def define_custom_scripts(tpl_rman):
    if ut.in_virtual_env():
        fmtdict = {
            'sys_dist_packages': ut.get_global_dist_packages_dir(),
            'venv_site_packages': ut.get_site_packages_dir(),
        }
        # Allows us to use a system qt install in a virtual environment.
        tpl_rman['PyQt4'].add_script('system_to_venv', ut.codeblock(
            r"""
            # STARTBLOCK bash
            ln -s {sys_dist_packages}/PyQt4/ {venv_site_packages}/PyQt4
            ln -s {sys_dist_packages}/sip*.so {venv_site_packages}/
            ln -s {sys_dist_packages}/sip*.py {venv_site_packages}/
            # ENDBLOCK bash
            """)).format(**fmtdict)
        # TODO: add custom build alternative
        pass
    else:
        pass

    ibeis_rman['pyflann'].add_script('install', ut.codeblock(
        r'''
        # STARTBLOCK bash
        # The pyflann source lives here
        cd {repo_dir}/src/python
        # But the setup script is generated during build
        python {repo_dir}/build/src/python/setup.py develop
        # ENDBLOCK bash
        ''').format(repo_dir=ibeis_rman['pyflann'].dpath)
    )

    # TODO: allow system installation as well
    tpl_rman['cv2'].add_script('build', ut.codeblock(
        r"""
        # STARTBLOCK bash
        cd $CODE_DIR
        git clone https://github.com/Itseez/opencv.git
        cd opencv
        # Get Extras
        git clone https://github.com/Itseez/opencv_contrib.git
        mkdir -p build27
        cd build27

        if [[ "$VIRTUAL_ENV" == ""  ]]; then
            export LOCAL_PREFIX=/usr/local
            export PYTHON2_PACKAGES_PATH=$LOCAL_PREFIX/lib/python2.7/dist-packages
        else
            export LOCAL_PREFIX=$VIRTUAL_ENV/local
            export PYTHON2_PACKAGES_PATH=$LOCAL_PREFIX/lib/python2.7/site-packages
        fi

        echo "LOCAL_PREFIX = $LOCAL_PREFIX"
        echo "PYTHON2_PACKAGES_PATH = $PYTHON2_PACKAGES_PATH"
        # use dist packages on ubuntu. may need to change for other platforms
        cmake -G "Unix Makefiles" \
            -D WITH_OPENMP=ON \
            -D CMAKE_BUILD_TYPE=RELEASE \
            -D PYTHON2_PACKAGES_PATH=$PYTHON2_PACKAGES_PATH \
            -D CMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \
            -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
            ..

        export NCPUS=$(grep -c ^processor /proc/cpuinfo)
        make -j$NCPUS
        # ENDBLOCK
        """))

    tpl_rman['cv2'].add_script('install', ut.codeblock(
        r"""
        # STARTBLOCK bash
        cd $CODE_DIR
        sudo make install
        # Hack because cv2 does not want to be installed for some reason
        cp lib/cv2.so $PYTHON2_PACKAGES_PATH
        # Test makesure things working
        python -c "import numpy; print(numpy.__file__)"
        python -c "import numpy; print(numpy.__version__)"
        python -c "import cv2; print(cv2.__version__)"
        python -c "import cv2; print(cv2.__file__)"
        #python -c "import vtool"

        # Check if we have contrib modules
        python -c "import cv2; print(cv2.xfeatures2d)"
        # ENDBLOCK
        """)
    )