~jtaylor/ubuntu/precise/python-numpy/multiarch-fix-818867

« back to all changes in this revision

Viewing changes to numpy/f2py/lib/extgen/setup_py.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik, Riku Voipio, Tiziano Zito, Carlos Galisteo, Ondrej Certik
  • Date: 2008-07-08 15:08:16 UTC
  • mfrom: (0.1.21 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080708150816-ekf992jcp2k1eua3
Tags: 1:1.1.0-3
[ Riku Voipio ]
* debian/control: atlas is not available on armel, and after a quick look
  neither on alpha. I'd also suggest dropping
  libatlas-sse-dev|libatlas-sse2-dev|libatlas-3dnow-dev alternative combo
  away, these are potentially dangerous on buildd's. Ondrej: dropped.
  (Closes: #489568)

[ Tiziano Zito ]
* patch: build _dotblas.c when ATLAS is not installed, build-conflict with
  atlas, build-depend on blas+lapack only, as it used to be (Closes: #489726)

[ Carlos Galisteo ]
* debian/control
  - Added Homepage field.

[ Ondrej Certik ]
* Checked the package on i386 and amd64, both with and without atlas, all
  tests run and the numpy package is faster if atlas is around. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
__all__ = ['SetupPy']
 
3
 
 
4
import os
 
5
import sys
 
6
from numpy.distutils.exec_command import exec_command
 
7
from base import Component
 
8
from utils import FileSource
 
9
 
 
10
def write_files(container):
 
11
    s = ['creating files and directories:']
 
12
    for filename, i in container.label_map.items():
 
13
        content = container.list[i]
 
14
        d,f = os.path.split(filename)
 
15
        if d and not os.path.isdir(d):
 
16
            s.append('  %s/' % (d))
 
17
            if not Component._generate_dry_run:
 
18
                os.makedirs(d)
 
19
        s.append('  %s' % (filename))
 
20
        if not Component._generate_dry_run:
 
21
            overwrite = True
 
22
            if os.path.isfile(filename):
 
23
                overwrite = False
 
24
                f = file(filename, 'r')
 
25
                i = 0
 
26
                for line in f:
 
27
                    if 'is generated using ExtGen tool' in line:
 
28
                        overwrite = True
 
29
                        break
 
30
                    i += 1
 
31
                    if i>5: break
 
32
                if not overwrite:
 
33
                    s[-1] += ' - unknown file exists, skipping'
 
34
                else:
 
35
                    s[-1] += ' - extgen generated file exists, overwriting'
 
36
            if overwrite:
 
37
                f = file(filename,'w')
 
38
                f.write(content)
 
39
                f.close()
 
40
    return '\n'.join(s)
 
41
 
 
42
 
 
43
class SetupPy(Component):
 
44
 
 
45
    """
 
46
    >>> from __init__ import *
 
47
    >>> s = SetupPy('SetupPy_doctest')
 
48
    >>> s += PyCModule('foo')
 
49
    >>> s,o = s.execute('build_ext', '--inplace')
 
50
    >>> assert s==0,`s`
 
51
    >>> import SetupPy_doctest as mypackage
 
52
    >>> print mypackage.foo.__doc__ #doctest: +ELLIPSIS
 
53
    This module 'foo' is generated with ExtGen from NumPy version...
 
54
 
 
55
    """
 
56
    template_setup_py_start = '''\
 
57
def configuration(parent_package='', top_path = ''):
 
58
    from numpy.distutils.misc_util import Configuration
 
59
    config = Configuration('',parent_package,top_path)'''
 
60
    template_setup_py_end = '''\
 
61
    return config
 
62
if __name__ == "__main__":
 
63
    from numpy.distutils.core import setup
 
64
    setup(configuration=configuration)
 
65
'''
 
66
    template = '%(SourceWriter)s'
 
67
 
 
68
    container_options = dict(
 
69
      SourceWriter = dict(user_defined_str = write_files),
 
70
      TMP = dict()
 
71
    )
 
72
 
 
73
    component_container_map = dict(
 
74
        FileSource = 'SourceWriter',
 
75
        ExtensionModule = 'TMP',
 
76
    )
 
77
 
 
78
    def initialize(self, build_dir, *components, **options):
 
79
        self.name = self.path = build_dir
 
80
        if not self.path:
 
81
            self.setup_py = setup_py = Component.PySource('extgen_setup.py')
 
82
            self.init_py = init_py = Component.PySource('extgen__init__.py')
 
83
        else:
 
84
            self.setup_py = setup_py = Component.PySource('setup.py')
 
85
            self.init_py = init_py = Component.PySource('__init__.py')
 
86
 
 
87
        setup_py += self.template_setup_py_start
 
88
 
 
89
        self += init_py
 
90
        self += setup_py
 
91
 
 
92
        map(self.add, components)
 
93
 
 
94
        return self
 
95
 
 
96
    def finalize(self):
 
97
        self.setup_py += self.template_setup_py_end
 
98
 
 
99
    def execute(self, *args):
 
100
        """
 
101
        Run generated setup.py file with given arguments.
 
102
        """
 
103
        if not args:
 
104
            raise ValueError('need setup.py arguments')
 
105
        self.info(self.generate(dry_run=False))
 
106
        cmd = [sys.executable,'setup.py'] + list(args)
 
107
        self.info('entering %r directory' % (self.path))
 
108
        self.info('executing command %r' % (' '.join(cmd)))
 
109
        try:
 
110
            r = exec_command(cmd, execute_in=self.path, use_tee=False)
 
111
        except:
 
112
            self.info('leaving %r directory' % (self.path))
 
113
            raise
 
114
        else:
 
115
            self.info('leaving %r directory' % (self.path))
 
116
        return r
 
117
 
 
118
 
 
119
def _test():
 
120
    import doctest
 
121
    doctest.testmod()
 
122
 
 
123
if __name__ == "__main__":
 
124
    _test()