File: mynipy

package info (click to toggle)
nipy 0.1.2%2B20100526-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,992 kB
  • ctags: 13,434
  • sloc: python: 47,720; ansic: 41,334; makefile: 197
file content (83 lines) | stat: -rwxr-xr-x 2,375 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python

"""
Simple script to quickly change the symbolic link to your nipy source branch.

When you build your source branch, perform an inplace build::

   cd trunk-lp # directory containing 'nipy' package directory
   python setup.py build_ext --inplace

Then ``mynipy`` will update the symlink in your site-packages directory
to point to the branch you specify.  This allows you to quickly switch
your working version of nipy without having to reinstall to your
site-packages or modify your PYTHONPATH.

Install
-------

We don't have a proper installer yet, simply copy this into a bin
directory and make sure it's permissions are executable.  For instance,
I installed mynipy in my local bin directory::

    $HOME/local/bin/mynipy

Usage
-----

From your nipy-repo, which has several nipy branches as
subdirectories like this::

    nipy-repo/trunk-lp
    nipy-repo/trunk-dev
    nipy-repo/trunk-mbrett

This will make the 'trunk-mbrett' my current nipy package::
    
    $ mynipy trunk-mbrett
    
"""

import os
from os.path import join as pjoin, split as psplit, \
    isdir, isfile, abspath
import sys
import subprocess

cwd = os.getcwd()
try:
    nipypath = abspath(sys.argv[1])
except IndexError: # default, current directory
    nipypath = cwd
nipy_pkg_path = pjoin(nipypath, 'nipy')

if not isdir(nipy_pkg_path):
    raise OSError('No nipy path in input path ' + nipypath)

print "Changing 'nipy' path to: \n  ", nipy_pkg_path, "\n"

# Find where nipy is now. If we're in a source branch directory, the
# 'import nipy' below would give us the source dir, not the
# site-packages directory, so we ..
if isdir('nipy') and isfile(pjoin('nipy', '__init__.py')):
    if cwd in sys.path:
        sys.path.remove(cwd)
    os.chdir('..')
try:
    import nipy
    site_pkgs, nipy_ln  = psplit(nipy.__path__[0])
except ImportError:
    # first time this script is run, we'll place it where numpy is installed
    try:
        import numpy
    except ImportError:
        raise ImportError('Unable to determine where to install nipy.')
    else:
        print 'First developer install of nipy,'
        print '\t installing nipy link with numpy is installed.'
        site_pkgs, numpy_ln  = psplit(numpy.__path__[0])
        site_pkgs = pjoin(site_pkgs, 'nipy')

cmd = 'ln -sf %s %s' % (nipy_pkg_path, site_pkgs)
print cmd
subprocess.call(cmd, shell=True)