This IPython extension adds a new %eups magic that allows one to call EUPS from IPython, setup products into the current IPython notebook's environment, as well as setup EUPS itself.
This comes in very handy when we want the Python notebook to fully capture the products (possibly down to the product version) that were used to execute it.
It's also handy when in the middle of some analysis you realize you've forgotten to setup a product you need.
In [1]:
%load_ext eups_magic
In [2]:
%eups list oorb
In [3]:
%eups setup oorb lsst-g650e0a6f6c
import pyoorb
pyoorb.__file__
Out[3]:
ipython-eupsDownload the ipython-eups script and run it any time you'd ordinarily run IPython:
wget http://eupsforge.net/ipython-eups
chmod +x ipython-eups
This script sets up the environment required for %eups magic to work, before transparently handing of control to your IPython interpreter.
You can also alias your ipython to ipython-eups:
alias ipython="...path/to/ipython-eups" # for bash, ksh, zsh
alias ipython "...path/to/ipython-eups" # for csh, tcsh
Appending these to your .bashrc (for bash) or .cshrc (for csh and tcsh) will make this automatic.
To activate the %eups magic, load the eups_magic extension. It's best to begin your notebooks with this.
In [1]:
%load_ext eups_magic
The message above tells us we've forgotten to setup EUPS itself (i.e., by sourcing setups.sh script). That's fine; we can do it from the notebook itself:
In [2]:
%eups init /Users/mjuric/projects/eups
We can tell %eups to remember the path to default EUPS:
In [3]:
%eups init --set-default /Users/mjuric/projects/eups
... and from now on we can run %eups init without an argument:
In [4]:
%eups init
Furthermore, now that we have the default set up, %eups init will automatically run when the extension is loaded so nothing is needed beyond %load_ext eups_magic.
The %eups magic lets you run any EUPS subcommand. For example, let's see which products are available:
In [5]:
%eups list oorb
Let's try to import a module from a product that hasn't been setup-ed yet:
In [6]:
import pyoorb
OK, so we'll set it up first:
In [7]:
%eups setup oorb lsst-g650e0a6f6c
Let's check if this worked:
In [8]:
%eups list -s
... and now we can use its modules directly from this notebook:
In [9]:
import pyoorb
We can also unsetup a module.
Hint: Note however that because of how Python handles modules, this will not unload an already loaded module. Furthermore, while pure-Python modules can be reloaded with reload(), that is not possible for C extensions (see http://bugs.python.org/issue1144263).
Bottom line: this will not enable you to switch out a version of a module at runtime, unless the module is pure Python and you remember to call reload.
In [10]:
%eups unsetup oorb lsst-g650e0a6f6c
%eups list -s
Mistakes are reported:
In [11]:
%eups foobar
We can setting up a list of products in a loop, using IPython variable expansion:
In [12]:
products = [('oorb', 'lsst-g650e0a6f6c')]
for product, version in products:
%eups setup $product $version
%eups list -s
All EUPS subcommands work:
In [13]:
%eups distrib list -s http://eupsforge.net
You can even install products from within your IPython notebook:
In [14]:
%eups distrib install -r http://eupsforge.net vitables
In [16]:
%eups list vitables
In [17]:
import os
linkfarm = os.environ['IPYTHON_EUPS_LIB_LINKFARM']
print os.environ['DYLD_LIBRARY_PATH']
print linkfarm
! ls -l $linkfarm
! ls -l $linkfarm/lib/