source: isenes/mpl_buildout/trunk/recipes/numpy_venv.py @ 5440

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/isenes/mpl_buildout/trunk/recipes/numpy_venv.py@5440
Revision 5440, 3.2 KB checked in by spascoe, 11 years ago (diff)

Will get and unpack basemap ready for compiling geos

Line 
1"""
2A recipe to install numpy into a virtualenv environment.
3
4"""
5
6import logging, os, zc.buildout
7from zc.buildout.easy_install import install, Installer
8import pkg_resources
9import subprocess
10
11from recipe import BaseRecipe
12
13class NumpyVenv(BaseRecipe):
14
15    def __init__(self, buildout, name, options):
16        self.name, self.options = name, options
17        self.log = logging.getLogger(self.name)
18
19        #!TODO: support buildout.python option
20        options['executable'] = buildout['buildout']['executable']
21        options['virtualenv'] = os.path.join(
22            buildout['buildout']['parts-directory'],
23            name
24            )
25        options['eggs-directory'] = buildout['buildout']['eggs-directory']
26        options['download-cache'] = buildout['buildout']['download-cache']
27
28        if 'eggs' not in options:
29            options['eggs'] = ''
30
31    def install(self):
32        """
33        The numpy egg is built with the buildout infrastructure and then
34        installed into a virtualenv.  This allows the latest numpy to be
35        built and used for further distribution building even if an older
36        version of numpy is already installed globally.
37       
38        """
39        path = self.options['virtualenv']
40
41        # First install numpy using buildout
42        install(self.options['eggs'].split(), self.options['eggs-directory'])
43
44        # Find the egg
45        e = pkg_resources.Environment([self.options['eggs-directory']])
46        dist = e['numpy'][0]
47                                     
48        # Add the egg to the virtualenv
49        self.options['eggs'] = '%s\n%s' % (self.options['eggs'],
50                                           dist.location)
51        self.create_virtualenv(path)
52
53        # Install MPL using the numpy virtualenv
54        self.install_mpl()
55
56        # Install basemap
57        self.install_basemap()
58
59        return path
60
61
62    def install_mpl(self):
63        venv = self.options['virtualenv']
64        venv_python = os.path.join(venv, 'bin', 'python')
65       
66        install(['matplotlib'], self.options['eggs-directory'],
67                links=self.options['download-cache'],
68                executable = venv_python)
69
70    def install_basemap(self):
71        """
72        Use the numpy virtualenv to get basemap, unpack it,
73        install the embedded geos and build the egg.
74
75        @warning: This method uses internal zc.buildout calls that are
76            subject to change.
77           
78        """
79        venv = self.options['virtualenv']
80        venv_python = os.path.join(venv, 'bin', 'python')
81        venv_easy_install = os.path.join(venv, 'bin', 'easy_install')
82       
83        # Download the source of basemap using zc.buildout
84        i = Installer(venv, 
85                      links = self.options['download-cache'],
86                      executable = venv_python)
87        dist, avail = i._satisfied(pkg_resources.Requirement.parse('basemap'),
88                                 source=True)
89        assert(dist==None)
90
91        #!TODO: remove basemap source tree if present.
92
93        # Unpack into the venv
94        subprocess.call([venv_easy_install, '-eb', venv,
95                         '-f', avail.location, 'basemap'])
96   
97    def update(self):
98        pass
99
100   
Note: See TracBrowser for help on using the repository browser.