File: setup.py

package info (click to toggle)
python-numarray 1.5.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,668 kB
  • ctags: 11,384
  • sloc: ansic: 113,864; python: 22,422; makefile: 197; sh: 11
file content (232 lines) | stat: -rw-r--r-- 8,491 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
"""numarray: array processing for numbers, strings, records and objects.

Numarray is an array processing package designed to efficiently
manipulate large multi-dimensional arrays.  Numarray is modelled after
Numeric and features c-code generated from python template scripts,
the capacity to operate directly on arrays in files, and improved type
promotions.  Numarray provides support for manipulating arrays
consisting of numbers, strings, records, or objects using the same
basic infrastructure and syntax.
"""

DOCLINES = __doc__.split("\n")


from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.command.config import config
from distutils.sysconfig import get_config_var, customize_compiler
from distutils.cygwinccompiler import CygwinCCompiler, Mingw32CCompiler
from distutils.bcppcompiler import BCPPCompiler
from distutils.msvccompiler import MSVCCompiler
try:
  from distutils.command.config import log
except:
  pass


import sys, os, os.path
import glob

from generate import VERSION, EXTRA_COMPILE_ARGS, EXTRA_LINK_ARGS, SELFTEST

from generate import NUMARRAY_PACKAGES, NUMARRAY_PACKAGE_DIRS, NUMARRAY_EXTENSIONS, NUMARRAY_DATA_FILES
from cfg_examples import EXAMPLES_PACKAGES, EXAMPLES_PACKAGE_DIRS, EXAMPLES_EXTENSIONS, EXAMPLES_DATA_FILES
from cfg_packages import ADDONS_PACKAGES,   ADDONS_PACKAGE_DIRS,   ADDONS_EXTENSIONS,   ADDONS_DATA_FILES

PACKAGE_DIRS = {}
PACKAGE_DIRS.update(NUMARRAY_PACKAGE_DIRS)
PACKAGE_DIRS.update(EXAMPLES_PACKAGE_DIRS)
PACKAGE_DIRS.update(ADDONS_PACKAGE_DIRS)

# =================================================================
# Configuration:
# Running "python setup.py config" determines some machine
# parameters that are used in dlapack_lite.c and zlapack_lite.c.

def prepend_path(p):
  try:
    os.environ["PATH"] = p + os.pathsep + os.environ["PATH"]
  except KeyError:
    pass

class config_numarray(config):
    def run (self):
        # Get a compiler
        self._check_compiler()
        try: log.set_verbosity(0)
        except: pass
        self.dump_source = 0
        # Switch off optimization
        if isinstance(self.compiler, BCPPCompiler):
            self.compiler.compile_options.remove('/O2')
        elif isinstance(self.compiler, MSVCCompiler):
	    if sys.version_info < (2,4):
              self.compiler.compile_options.remove('/Ox')
              self.compiler.compile_options.remove('/GX')
        else:
            if isinstance(self.compiler, CygwinCCompiler):
                cc = 'gcc'
            elif isinstance(self.compiler, Mingw32CCompiler):
                cc = 'gcc -mno-cygwin'
            else: # UnixCCompiler
                cc = get_config_var('CC')
            if os.environ.has_key('CC'):
                cc = os.environ['CC']
            self.compiler.set_executable('compiler_so',cc)
        directory = os.path.join("Packages","LinearAlgebra2","Src")
        testcode = """\
#include "%s"
""" % os.path.join(directory,"config.c")
        prepend_path(".")

        if sys.version_info < (2,3):
          self.compiler.exe_extension = ""
        
        if self.try_run(testcode, include_dirs=[directory]):
            print "Wrote config.h"
            if os.path.isfile(os.path.join(directory,"config.h")):
                os.remove(os.path.join(directory,"config.h"))
            os.rename("config.h",os.path.join(directory,"config.h"))
        else:
            print "Configuration failed, using default compilation"
            if os.path.isfile(os.path.join(directory,"config.h")):
                os.remove(os.path.join(directory,"config.h"))

        # Restore usual compiler flags
        if isinstance(self.compiler, BCPPCompiler):
            self.compiler.compile_options.append('/O2')
        elif isinstance(self.compiler, MSVCCompiler):
            self.compiler.compile_options.append('/Ox')
            self.compiler.compile_options.append('/GX')
        else:
            customize_compiler(self.compiler)

        try: log.set_verbosity(1)
        except: pass

# =================================================================

#  Pete Shinner's distutils data file fix... from distutils-sig
#data installer with improved intelligence over distutils
#data files are copied into the project directory instead
#of willy-nilly
class smart_install_data(install_data):   
    def run(self):
        #need to change self.install_dir to the library dir
        install_cmd = self.get_finalized_command('install')
        self.install_dir = getattr(install_cmd, 'install_lib')
        return install_data.run(self)

# =================================================================

def headers():
    return glob.glob(os.path.join("Include","numarray","*.h"))

def dolocal():
    """Adds a command line parameter --local=<dir> which is an abbreviation for
    'put all of numarray in <dir>/numarray'."""
    if "--help" in sys.argv:
        print >>sys.stderr
        print >>sys.stderr, "Numarray options:"
        print >>sys.stderr, "--local=<dir>    same as --install-lib=<dir> --install-headers=<dir>/numarray"
    for a in sys.argv:
        if a.startswith("--local="):
            dir = a.split("=")[1]
            sys.argv.extend([
                "--install-lib="+dir,
                "--install-headers="+os.path.join(dir,"numarray")
                ])
            sys.argv.remove(a)
        if a.startswith("--genapi") or a.startswith("--gencode") or \
               a.startswith("--genapi") or a.startswith("--timing"):
            sys.argv.remove(a)
        if a.startswith("--gencode"):
            sys.argv.remove(a)

CLASSIFIERS = """\
Development Status :: 4 - Beta
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved 
Programming Language :: C
Programming Language :: Python
Topic :: Software Development 
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
"""

def find_name(base = 'numarray'):
    '''If "--name-with-python-version" is on the command line then
    append "-pyX.Y" to the base name'''
    name = base
    if '--name-with-python-version' in sys.argv:
        name += '-py%i.%i'%(sys.version_info[0],sys.version_info[1])
        sys.argv.remove('--name-with-python-version')
    return name

CLASSIFIERS = """\
Development Status :: 4 - Beta
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved 
Programming Language :: C
Programming Language :: Python
Topic :: Software Development 
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
"""

def getparams(**p):
    return p

def main():
    if not hasattr(sys, 'version_info') or sys.version_info < (2,2,0,'final'):
        raise SystemExit, "Python 2.2.0 or later required to build numarray."
    dolocal()

    name = find_name()

    p = getparams(name = name,
          cmdclass = {"install_data":smart_install_data,
                      "config":config_numarray},
          version = VERSION,
          description = DOCLINES[0],
          long_description = "\n".join(DOCLINES[2:]),
          url = "http://www.stsci.edu/resources/software_hardware/numarray/",
          download_url = "http://sourceforge.net/projects/numpy",
          author = "Perry Greenfield",
          author_email  = "perry@stsci.edu",
          maintainer = "Todd Miller",
          maintainer_email = "jmiller@stsci.edu",
          classifiers = filter(None, CLASSIFIERS.split("\n")),
          license = "http://www.stsci.edu/resources/software_hardware/pyraf/LICENSE",
          platforms = ["Windows","Linux","Solaris","Mac OS-X"],
          packages    = NUMARRAY_PACKAGES + ADDONS_PACKAGES + EXAMPLES_PACKAGES,
          package_dir = PACKAGE_DIRS,
          headers     = headers(),
          data_files  = NUMARRAY_DATA_FILES + ADDONS_DATA_FILES + EXAMPLES_DATA_FILES,
          ext_modules = NUMARRAY_EXTENSIONS + ADDONS_EXTENSIONS + EXAMPLES_EXTENSIONS)

    if sys.version_info <= (2,3):
        del p["classifiers"]
        del p["download_url"]

    setup(**p)
    
    if SELFTEST:
        import numarray.testall as testall
        testall.test()
#
# Do the installation.
#
if __name__ == "__main__":
  if "config" not in sys.argv and ("build" in sys.argv or "install" in sys.argv):
    sys.argv.insert(sys.argv.index("setup.py")+1, "config")
  main()