source: setup.py @ 2994:e27adc17b966

Revision 2994:e27adc17b966, 29.6 KB checked in by Robert Miller <rlmillster@…>, 6 years ago (diff)

branch merge

Line 
1#!/usr/bin/env python
2DEVEL = False
3
4import distutils.sysconfig, os, sys
5from distutils.core import setup, Extension
6
7
8## Choose cblas library -- note -- make sure to update sage/misc/sagex.py
9## if you change this!!
10if os.environ.has_key('SAGE_CBLAS'):
11    CBLAS=os.environ['SAGE_CBLAS']
12elif os.path.exists('/usr/lib/libcblas.dylib') or \
13     os.path.exists('/usr/lib/libcblas.so'):
14    CBLAS='cblas'
15elif os.path.exists('/usr/lib/libblas.dll.a'):   # untested.
16    CBLAS='blas'
17else:
18    # This is very slow  (?), but *guaranteed* to be available.
19    CBLAS='gslcblas' 
20
21if len(sys.argv) > 1 and sys.argv[1] == "sdist":
22    sdist = True
23else:
24    sdist = False
25
26NO_WARN = True
27
28if not os.environ.has_key('SAGE_ROOT'):
29    print "    ERROR: The environment variable SAGE_ROOT must be defined."
30    sys.exit(1)
31else:
32    SAGE_ROOT  = os.environ['SAGE_ROOT']
33    SAGE_LOCAL = SAGE_ROOT + '/local/'
34    SAGE_DEVEL = SAGE_ROOT + '/devel/'
35
36
37if not os.environ.has_key('SAGE_VERSION'):
38    SAGE_VERSION=0
39else:
40    SAGE_VERSION = os.environ['SAGE_VERSION']
41
42SITE_PACKAGES = '%s/lib/python/site-packages/'%SAGE_LOCAL
43if not os.path.exists(SITE_PACKAGES):
44    SITE_PACKAGES = '%s/lib/python2.5/site-packages/'%SAGE_LOCAL
45    if not os.path.exists(SITE_PACKAGES):
46        SITE_PACKAGES = '%s/lib/python2.4/site-packages/'%SAGE_LOCAL
47        if not os.path.exists(SITE_PACKAGES):       
48            raise RuntimeError, "Unable to find site-packages directory (see setup.py file in sage python code)."
49
50SITE_PACKAGES_REL=SITE_PACKAGES[len(SAGE_LOCAL)+5:]
51       
52if not os.path.exists('build/sage'):
53    os.makedirs('build/sage')
54
55sage_link = SITE_PACKAGES + '/sage'
56if not os.path.islink(sage_link) or not os.path.exists(sage_link):
57    os.system('rm -rf "%s"'%sage_link)
58    os.system('cd %s; ln -sf ../../../../devel/sage/build/sage .'%SITE_PACKAGES)
59
60
61include_dirs = ['%s/include'%SAGE_LOCAL, '%s/include/python'%SAGE_LOCAL, \
62                '%s/sage/sage/ext'%SAGE_DEVEL]
63
64#####################################################   
65       
66ec =    Extension('sage.libs.ec.ec',
67              sources = ["sage/libs/ec/ec.pyx"] +  \
68                        ["sage/libs/ec/%s"%s for s in \
69                         ["analrank.c", "apcompute.c", "arderivs.c",
70                          "arintern.c", "arith.c", "artwists.c",
71                          "arutil.c", "checkit.c", "degphi.c", 
72                          "diskio.c", "docurve.c", "dodisk.c", 
73                          "equation.c", "exotic.c", "fixit.c", 
74                          "iisog2.c", "iisog3.c", "isog.c", "isog2.c",
75                          "isog23.c", "isog24.c", "isog3.c", "isog5.c",
76                          "isog52.c", "isog713.c", "isogNprime.c",
77                          "isoggen.c", "isogsort.c", "isogx0.c", 
78                          "isogx0branch.c", "isogx0branch1.c", 
79                          "isogx0branch2.c", "isogx0branch3.c",
80                          "isogx0branch4.c", "isogx0branch5.c", 
81                          "isogx0branch6.c", "isogx0getd.c", 
82                          "isogx0period.c", "readit.c",
83                          "special.c", "util.c"]], 
84              libraries = ["pari", "m"])
85
86hanke = Extension(name = "sage.libs.hanke.hanke",
87              sources = ["sage/libs/hanke/hanke.pyx",
88                         "sage/libs/hanke/wrap.cc",
89                         "sage/libs/hanke/Matrix_mpz/Matrix_mpz.cc",
90                         "sage/libs/hanke/Matrix_mpz/CountLocal2.cc",
91                         "sage/libs/hanke/Matrix_mpz/CountLocal.cc",
92                         "sage/libs/hanke/Matrix_mpz/Local_Constants.cc",
93                         "sage/libs/hanke/Matrix_mpz/Local_Density_Front.cc",
94                         "sage/libs/hanke/Matrix_mpz/Local_Density_Congruence.cc",
95                         "sage/libs/hanke/Matrix_mpz/Local_Normal.cc",
96                         "sage/libs/hanke/Matrix_mpz/Local_Invariants.cc",
97                         "sage/libs/hanke/Utilities/string_utils.cc",
98                         "sage/libs/hanke/GMP_class_extras/mpz_class_extras.cc",
99                         "sage/libs/hanke/GMP_class_extras/vectors.cc" ],
100                   libraries = ["gmp", "gmpxx", "stdc++"])
101
102ntl = Extension('sage.libs.ntl.ntl',
103                 sources = ["sage/libs/ntl/ntl.pyx", "sage/libs/ntl/ntl_wrap.cc"],
104                 libraries = ["ntl", "gmp", "gmpxx", "m", "stdc++"]
105                 )
106
107mwrank =  Extension("sage.libs.mwrank.mwrank",
108                    sources = ["sage/libs/mwrank/mwrank.pyx",
109                         "sage/libs/mwrank/wrap.cc"],
110                    define_macros = [("NTL_ALL",None)],
111                    libraries = ["mwrank", "ntl", "gmp", "gmpxx", "stdc++", "m", "pari"])
112
113pari = Extension('sage.libs.pari.gen',
114                 sources = ["sage/libs/pari/gen.pyx"],
115                 libraries = ['pari', 'gmp'])
116
117cf = Extension('sage.libs.cf.cf',
118               sources = ["sage/libs/cf/cf.pyxe", "sage/libs/cf/ftmpl_inst.cc"],
119               libraries = ['cf', 'cfmem', 'gmp', 'stdc++', 'm']
120               )
121
122
123givaro_gfq = Extension('sage.rings.finite_field_givaro',
124                       sources = ["sage/rings/finite_field_givaro.pyx"],
125                       libraries = ['givaro', 'gmpxx', 'gmp', 'm', 'stdc++', ],   # this order is needed to compile under windows.
126                       language='c++'
127                       )
128
129
130qd = Extension('sage.rings.real_qdrf',
131                       sources = ["sage/rings/real_qdrf.pyx"],
132                       libraries = ['qd', 'm', 'stdc++', ],
133                       language='c++'
134                       )
135
136matrix = Extension('sage.matrix.matrix', ['sage/matrix/matrix.pyx'])
137
138matrix_misc = Extension('sage.matrix.misc', ['sage/matrix/misc.pyx'],
139                        libraries=['gmp'])
140
141matrix_dense = Extension('sage.matrix.matrix_dense',
142                         ['sage/matrix/matrix_dense.pyx'])
143             
144matrix_sparse = Extension('sage.matrix.matrix_sparse',
145                          ['sage/matrix/matrix_sparse.pyx'])
146
147matrix_generic_dense = Extension('sage.matrix.matrix_generic_dense',
148                                 ['sage/matrix/matrix_generic_dense.pyx'])
149             
150matrix_generic_sparse = Extension('sage.matrix.matrix_generic_sparse',
151                                  ['sage/matrix/matrix_generic_sparse.pyx'])
152
153matrix_domain_dense = Extension('sage.matrix.matrix_domain_dense',
154                                ['sage/matrix/matrix_domain_dense.pyx'])
155
156matrix_domain_sparse = Extension('sage.matrix.matrix_domain_sparse',
157              ['sage/matrix/matrix_domain_sparse.pyx'])
158             
159matrix_pid_dense = Extension('sage.matrix.matrix_pid_dense',
160                       ['sage/matrix/matrix_pid_dense.pyx'])
161             
162matrix_pid_sparse = Extension('sage.matrix.matrix_pid_sparse',
163                       ['sage/matrix/matrix_pid_sparse.pyx'])
164
165
166matrix_integer_sparse = Extension('sage.matrix.matrix_integer_sparse',
167                                  ['sage/matrix/matrix_integer_sparse.pyx'],
168                                  libraries = ['gmp'])
169
170matrix_integer_2x2 = Extension('sage.matrix.matrix_integer_2x2',
171                                 ['sage/matrix/matrix_integer_2x2.pyx'],
172                                 libraries = ['gmp'])
173
174linbox = Extension('sage.matrix.linbox',
175                   ['sage/matrix/linbox.pyx',
176                    'sage/matrix/matrix_modn_dense_linbox.cpp'],
177                   libraries = ['linbox', 'ntl', 'gmp', 'gmpxx', 'stdc++', 'givaro', CBLAS])
178
179matrix_modn_dense = Extension('sage.matrix.matrix_modn_dense',
180                              ['sage/matrix/matrix_modn_dense.pyx'],
181                              libraries = ['gmp'])
182
183matrix_modn_sparse = Extension('sage.matrix.matrix_modn_sparse',
184                               ['sage/matrix/matrix_modn_sparse.pyx'])
185   
186matrix_field_dense = Extension('sage.matrix.matrix_field_dense',
187                       ['sage/matrix/matrix_field_dense.pyx'])
188   
189matrix_field_sparse = Extension('sage.matrix.matrix_field_sparse',
190                       ['sage/matrix/matrix_field_sparse.pyx'])
191
192matrix_rational_dense = Extension('sage.matrix.matrix_rational_dense',
193                                  ['sage/matrix/matrix_rational_dense.pyx',
194                                   'sage/matrix/matrix_rational_dense_linbox.cpp'],
195                                 libraries = ['linbox', 'ntl', 'gmp', 'gmpxx', 'stdc++', 'givaro', CBLAS])
196
197matrix_integer_dense = Extension('sage.matrix.matrix_integer_dense',
198                                 ['sage/matrix/matrix_integer_dense.pyx',
199                                  'sage/matrix/matrix_integer_dense_linbox.cpp'],
200                                  libraries = ['linbox', 'ntl', 'gmp', 'gmpxx', 'stdc++', 'givaro', CBLAS])
201
202matrix_real_double_dense=Extension('sage.matrix.matrix_real_double_dense',
203   ['sage/matrix/matrix_real_double_dense.pyx'],libraries=['gsl',CBLAS],
204   define_macros=[('GSL_DISABLE_DEPRECATED','1')],include_dirs=[SAGE_ROOT+'/local/lib/python2.5/site-packages/numpy/core/include/numpy'])
205
206matrix_complex_double_dense=Extension('sage.matrix.matrix_complex_double_dense',
207   ['sage/matrix/matrix_complex_double_dense.pyx'],libraries=['gsl',CBLAS],
208   define_macros=[('GSL_DISABLE_DEPRECATED','1')],include_dirs=[SAGE_ROOT+'/local/lib/python2.5/site-packages/numpy/core/include/numpy'])
209
210
211solve = Extension('sage.matrix.solve',['sage/matrix/solve.pyx'],libraries = ['gsl',CBLAS],define_macros = 
212   [('GSL_DISABLE_DEPRECATED','1')])
213
214matrix_cyclo_dense = Extension('sage.matrix.matrix_cyclo_dense',
215                               ['sage/matrix/matrix_cyclo_dense.pyx'])
216
217matrix_rational_sparse = Extension('sage.matrix.matrix_rational_sparse',
218                                   ['sage/matrix/matrix_rational_sparse.pyx'],
219                                   libraries = ['gmp'])
220
221matrix_cyclo_sparse = Extension('sage.matrix.matrix_cyclo_sparse',
222                                   ['sage/matrix/matrix_cyclo_sparse.pyx'])
223
224complex_number = Extension('sage.rings.complex_number',
225                            ['sage/rings/complex_number.pyx'],
226                            libraries = ['mpfr', 'gmp'])
227
228free_module_element = Extension('sage.modules.free_module_element',
229                                ['sage/modules/free_module_element.pyx'])
230
231################ GSL wrapping ######################
232gsl_probability=Extension('sage.gsl.probability_distribution',['sage/gsl/probability_distribution.pyx'],libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
233gsl_integration=Extension('sage.gsl.integration',['sage/gsl/integration.pyx'],define_macros=[('GSL_DISABLE_DEPRECATED','1')], libraries=['gsl',CBLAS])
234
235gsl_ode = Extension('sage.gsl.ode',['sage/gsl/ode.pyx'],libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
236
237gsl_fft = Extension('sage.gsl.fft',
238                ['sage/gsl/fft.pyx'],
239                libraries = ['gsl', CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
240
241gsl_interpolation = Extension('sage.gsl.interpolation',
242                ['sage/gsl/interpolation.pyx'],
243                libraries = ['gsl', CBLAS], 
244define_macros=[('GSL_DISABLE_DEPRECATED','1')])
245
246gsl_callback = Extension('sage.gsl.callback',
247                ['sage/gsl/callback.pyx'],
248                libraries = ['gsl', CBLAS]
249,define_macros=[('GSL_DISABLE_DEPRECATED','1')])
250
251real_double = Extension('sage.rings.real_double',
252                ['sage/rings/real_double.pyx'],
253                libraries = ['gsl', CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
254
255complex_double = Extension('sage.rings.complex_double',
256                           ['sage/rings/complex_double.pyx'],
257                           libraries = ['gsl', CBLAS, 'pari', 'gmp'])
258
259real_double_vector = Extension('sage.modules.real_double_vector',['sage/modules/real_double_vector.pyx'],
260                              libraries = ['gsl',CBLAS,'pari','gmp'],define_macros = [('GSL_DISABLE_DEPRECAED','1')])
261
262complex_double_vector = Extension('sage.modules.complex_double_vector',['sage/modules/complex_double_vector.pyx'],
263                           libraries = ['gsl', CBLAS, 'pari', 'gmp'],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
264
265
266gsl_array = Extension('sage.gsl.gsl_array',['sage/gsl/gsl_array.pyx'],
267                libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
268gsl_ode = Extension('sage.gsl.ode',['sage/gsl/ode.pyx'],libraries=['gsl',CBLAS],
269                define_macros=[('GSL_DISABLE_DEPRECATED','1')])
270
271
272dwt = Extension('sage.gsl.dwt',['sage/gsl/dwt.pyx'],
273                 libraries=['gsl',CBLAS],
274                 define_macros=[('GSL_DISABLE_DEPRECATED','1')])
275
276
277#####################################################
278
279ext_modules = [ \
280
281    free_module_element, 
282   
283    complex_double_vector,
284    real_double_vector,
285    ec, 
286    pari, 
287
288    mwrank, 
289
290    ntl, 
291
292    matrix,
293   
294    matrix_misc,
295
296    #cf,
297
298    matrix_dense,
299    matrix_generic_dense,
300
301    matrix_sparse,
302    matrix_generic_sparse,
303
304##     matrix_domain_dense,
305##     matrix_domain_sparse,
306
307##     matrix_pid_dense,
308##     matrix_pid_sparse,
309
310##     matrix_field_dense,
311##     matrix_field_sparse,
312
313     matrix_integer_dense,
314     matrix_rational_dense,
315     matrix_integer_2x2,
316##     matrix_integer_sparse,   
317     matrix_real_double_dense,
318     matrix_complex_double_dense,
319     solve,
320     linbox,
321     matrix_modn_dense,
322     matrix_modn_sparse,
323     givaro_gfq, \
324
325##     matrix_rational_sparse,
326
327##     matrix_cyclo_dense,
328##     matrix_cyclo_sparse,
329   
330    dwt,
331
332    gsl_array,
333    gsl_ode,
334    gsl_fft,
335    gsl_interpolation,
336    gsl_callback,
337    gsl_probability,
338    gsl_integration,
339    real_double,
340    complex_double,
341    #qd,   
342
343    complex_number,
344
345    Extension('sage.ext.sig',
346              sources = ['sage/ext/sig.pyx']), \
347
348    Extension('sage.ext.arith',
349              sources = ['sage/ext/arith.pyx']), \
350
351    Extension('sage.ext.arith_gmp',
352              sources = ['sage/ext/arith_gmp.pyx'],
353              libraries=['gmp']), \
354
355    Extension('sage.ext.multi_modular',
356              sources = ['sage/ext/multi_modular.pyx'],
357              libraries=['gmp']), \
358
359    Extension('sage.structure.coerce',
360              sources = ['sage/structure/coerce.pyx']), \
361
362    Extension('sage.modular.congroup_pyx',
363              sources = ['sage/modular/congroup_pyx.pyx', \
364                         'sage/ext/arith.pyx']), \
365
366    Extension('sage.structure.element',
367              sources = ['sage/structure/element.pyx']), \
368
369    Extension('sage.modules.module',
370              sources = ['sage/modules/module.pyx']), \
371
372    Extension('sage.rings.ring',
373              sources = ['sage/rings/ring.pyx']), \
374
375    Extension('sage.groups.group',
376              sources = ['sage/groups/group.pyx']), \
377
378    Extension('sage.structure.sage_object',
379              sources = ['sage/structure/sage_object.pyx']), \
380
381    Extension('sage.structure.parent',
382              sources = ['sage/structure/parent.pyx']), \
383
384    Extension('sage.structure.parent_base',
385              sources = ['sage/structure/parent_base.pyx']), \
386   
387    Extension('sage.structure.parent_gens',
388              sources = ['sage/structure/parent_gens.pyx']), \
389
390    Extension('sage.ext.interactive_constructors_c',
391              sources = ['sage/ext/interactive_constructors_c.pyx']), \
392
393    Extension('sage.misc.sagex_c',
394              sources = ['sage/misc/sagex_c.pyx']), \
395
396    Extension('sage.rings.real_mpfr',
397              sources = ['sage/rings/real_mpfr.pyx', 'sage/rings/ring.pyx'],
398              libraries = ['mpfr', 'gmp']), \
399
400    Extension('sage.rings.real_mpfi',
401              sources = ['sage/rings/real_mpfi.pyx'],
402              libraries = ['mpfi', 'mpfr', 'gmp']), \
403
404    Extension('sage.rings.integer',
405              sources = ['sage/ext/arith.pyx', 'sage/rings/integer.pyx', \
406                         'sage/ext/mpn_pylong.c', 'sage/ext/mpz_pylong.c'],
407              libraries=['gmp']), \
408
409    Extension('sage.rings.integer_ring',
410              sources = ['sage/rings/integer_ring.pyx'],
411              libraries=['gmp']), \
412
413    Extension('sage.rings.memory', \
414              sources = ['sage/rings/memory.pyx'], \
415              libraries=['gmp']), \
416
417    Extension('sage.rings.bernoulli_mod_p',
418              sources = ['sage/rings/bernoulli_mod_p.pyx', 'sage/ext/arith.pyx'],
419              libraries=['ntl'],
420              include_dirs=['sage/libs/ntl/']), \
421
422    Extension('sage.rings.polynomial_element',
423              sources = ['sage/rings/polynomial_element.pyx']), \
424
425    Extension('sage.rings.polynomial_pyx',
426              sources = ['sage/rings/polynomial_pyx.pyx',
427                         'sage/ext/arith_gmp.pyx'],
428              libraries=['gmp']), \
429
430    Extension('sage.rings.rational',
431              sources = ['sage/rings/rational.pyx',
432                         'sage/ext/arith.pyx', \
433                         'sage/rings/integer.pyx', \
434                         'sage/ext/mpn_pylong.c', 'sage/ext/mpz_pylong.c'],
435              libraries=['gmp']), \
436
437    Extension('sage.rings.sparse_poly', 
438              sources = ['sage/rings/sparse_poly.pyx'],
439              libraries=['gmp']), \
440
441    Extension('sage.rings.polydict',
442              sources = ['sage/rings/polydict.pyx']), \
443
444    Extension('sage.misc.search',
445              ['sage/misc/search.pyx']), \
446
447    Extension('sage.modular.modsym.heilbronn',
448              ['sage/modular/modsym/heilbronn.pyx',
449               'sage/modular/modsym/p1list.pyx',
450               'sage/ext/arith.pyx'],
451              libraries = ['gmp', 'm']), \
452
453    Extension('sage.modular.modsym.p1list',
454              ['sage/modular/modsym/p1list.pyx',
455               'sage/ext/arith.pyx'],
456              libraries = ['gmp']), \
457
458    Extension('sage.structure.mutability',
459              ['sage/structure/mutability.pyx']
460              ), \
461
462    Extension('sage.matrix.matrix0',
463              ['sage/matrix/matrix0.pyx']
464              ), \
465
466    Extension('sage.matrix.matrix1',
467              ['sage/matrix/matrix1.pyx']
468              ), \
469
470    Extension('sage.matrix.matrix2',
471              ['sage/matrix/matrix2.pyx']
472              ), \
473   
474    Extension('sage.matrix.matrix',
475              ['sage/matrix/matrix.pyx']
476              ), \
477
478    Extension('sage.matrix.matrix_window',
479              ['sage/matrix/matrix_window.pyx']
480              ), \
481
482    Extension('sage.matrix.matrix_window_modn_dense',
483              ['sage/matrix/matrix_window_modn_dense.pyx']
484              ), \
485
486    Extension('sage.matrix.strassen',
487              ['sage/matrix/strassen.pyx']
488              ), \
489                           
490    Extension('sage.rings.integer_mod',
491              ['sage/rings/integer_mod.pyx'],
492              libraries = ['gmp']
493              ), \
494
495    Extension('sage.combinat.expnums',
496              ['sage/combinat/expnums.pyx'],
497              libraries = ['gmp']
498              ), \
499                           
500    Extension('sage.graphs.graph_fast',
501              ['sage/graphs/graph_fast.pyx']
502              ), \
503                           
504    ]
505   
506
507#mpc = Extension('sage.rings.mpc',
508#              sources = ['sage/rings/mpc.pyx', 'sage/rings/ring.pyx'],
509#              libraries = ['mpc', 'mpfr', 'gmp'])
510
511
512extra_compile_args = [ ]
513
514if NO_WARN and distutils.sysconfig.get_config_var('CC').startswith("gcc"):
515    extra_compile_args = ['-w']
516
517if DEVEL:
518    extra_compile_args.append('-ggdb')
519    ext_modules.append(hanke)
520    #ext_modules.append(mpc)
521
522for m in ext_modules:
523    m.libraries += ['csage']
524    m.library_dirs += ['%s/lib' % SAGE_LOCAL]
525
526
527######################################################################
528# CODE for generating C/C++ code from Pyrex and doing dependency
529# checking, etc.  In theory distutils would run Pyrex, but I don't
530# trust it at all, and it won't have the more sophisticated dependency
531# checking that we need.
532######################################################################
533
534def is_older(file1, file2):
535    """
536    Return True if either file2 does not exist or is older than file1.
537
538    If file1 does not exist, always return False.
539    """
540    if not os.path.exists(file1):
541        return False
542    if not os.path.exists(file2):
543        return True
544    if os.path.getctime(file2) < os.path.getctime(file1):
545        return True
546    return False
547
548
549def need_to_pyrex(filename, outfile):
550    """
551    INPUT:
552        filename -- The name of a pyrex file in the SAGE source tree.
553        outfile -- The name of the corresponding c or cpp file in the build directory.
554
555    OUTPUT:
556        bool -- whether or not outfile must be regenerated.
557    """
558    if is_older(filename, outfile):   # outfile is older than filename
559        return True
560    base =  os.path.splitext(filename)[0]
561    pxd = base+'.pxd'
562    if is_older(pxd, outfile):   # outfile is older than pxd file (if it exists)
563        return True
564
565    ## comment this out to turn on dependency checking!
566    # return False
567
568    # Now we look inside the file to see what it cimports or include.
569    # If any of these files are newer than outfile, we rebuild
570    # outfile.
571    S = open(filename).readlines()
572    if os.path.exists(pxd):
573        S += open(pxd).readlines()
574    # Take the lines that begin with cimport (it won't hurt to
575    # have extra lines)
576    C = [x.strip() for x in S if 'cimport' in x]
577    for A in C:
578        # Deduce the full module name.
579        # The only allowed forms of cimport are:
580        #        cimport a.b.c.d
581        #        from a.b.c.d cimport e
582        # Also, the cimport can be both have no dots (current directory) or absolute.
583        # The multiple imports with parens, e.g.,
584        #        import (a.b.c.d, e.f.g)
585        # of Python are not allowed in Pyrex.
586        # In both cases, the module name is the second word if we split on whitespace.
587        try:
588            A = A.strip().split()[1]
589        except IndexError:
590            # illegal statement or not really a cimport (e.g., cimport could
591            # be in a comment or something)
592            continue
593
594        # Now convert A to a filename, e.g., a/b/c/d
595        #
596        if '.' in A:
597            # It is an absolute cimport.
598            A = A.replace('.','/') + '.pxd'
599        else:
600            # It is a relative cimport.
601            A =  os.path.split(base)[0] + '/' + A + '.pxd'
602        # Check to see if a/b/c/d.pxd exists and is newer than filename.
603        # If so, we have to regenerate outfile.  If not, we're safe.
604        if os.path.exists(A) and is_older(A, outfile):
605            print "\nRegenerating %s because it depends on %s."%(outfile, A)
606            return True # yep we must rebuild
607
608    # OK, next we move on to include pxi files.
609    # If they change, we likewise must rebuild the pyx file.
610    I = [x for x in S if 'include' in x]
611    # The syntax for include is like this:
612    #       include "../a/b/c.pxi"
613    # I.e., it's a quoted *relative* path to a pxi file.
614    for A in I:
615        try:
616            A = A.strip().split()[1]
617        except IndexError:
618            # Illegal include statement or not really an include
619            # (e.g., include could easily be in a comment or
620            # something).  No reason to crash setup.py!
621            continue
622        # Strip the quotes from either side of the pxi filename.
623        A = A.strip('"').strip("'")
624        # Now take filename (the input argument to this function)
625        # and strip off the last part of the path and stick
626        # A onto it to get the filename of the pxi file relative
627        # where setup.py is being run.
628        A = os.path.split(filename)[0] + '/' + A
629        # Finally, check to see if filename is older than A
630        if os.path.exists(A) and is_older(A, outfile):
631            print "\nBuilding %s because it depends on %s."%(outfile, A)
632            return True
633
634    # We do not have to rebuild.
635    return False
636
637def process_pyrexembed_file(f, m):
638    # This is a pyrexembed file, so process accordingly.
639    dir, base = os.path.split(f[:-5])
640    tmp = '%s/.tmp_pyrexembed'%dir
641    if os.path.exists(tmp) and not os.path.isdir(tmp):
642        print "Please delete file '%s' in %s"%(tmp, dir)
643        sys.exit(1)
644    if not os.path.exists(tmp):
645        os.makedirs(tmp)
646    pyxe_file = "%s/%s.pyxe"%(tmp, base)
647
648    # The following files will be produced by pyrexembed.
649    cpp_file = "%s/%s_embed.cpp"%(dir, base)
650    c_file = "%s/%s.c"%(dir, base)
651    pyx_file = "%s/%s.pyx"%(dir,base)
652    pyx_embed_file = "%s/%s.pyx"%(tmp, base)
653    h_file = "%s/%s_embed.h"%(tmp, base)
654    if is_older(f, pyx_file) or is_older(f, cpp_file) or is_older(f, h_file):
655        os.system('cp -p %s %s'%(f, pyxe_file))
656        os.system('cp -p %s/*.pxi %s'%(dir, tmp))
657        os.system('cp -p %s/*.pxd %s'%(dir, tmp))
658        os.system('cp -p %s/*.h %s'%(dir, tmp))
659        cmd = "pyrexembed %s"%pyxe_file
660        print cmd
661        ret = os.system(cmd)
662        if ret != 0:
663            print "sage: Error running pyrexembed."
664            sys.exit(1)
665        process_pyrex_file(pyx_embed_file, m)
666        cmd = 'cp -p %s/*.pyx %s/; cp -p %s/*.c %s/; cp -p %s/*.h %s/; cp -p %s/*.cpp %s/'%(tmp, dir, tmp, dir, tmp, dir, tmp, dir)
667        print cmd
668        os.system(cmd)
669    return [cpp_file, c_file]
670
671def process_pyrex_file(f, m):
672    """
673    INPUT:
674        f -- file name
675        m -- Extension module description (i.e., object of type Extension).
676    """
677    # This is a pyrex file, so process accordingly.
678    pyx_inst_file = '%s/%s'%(SITE_PACKAGES, f)
679    if is_older(f, pyx_inst_file):
680        print "%s --> %s"%(f, pyx_inst_file)
681        os.system('cp %s %s 2>/dev/null'%(f, pyx_inst_file))
682    outfile = f[:-4] + ".c"
683    if m.language == 'c++':
684        outfile += 'pp'
685
686    if need_to_pyrex(f, outfile):
687        cmd = "pyrexc --embed-positions -I%s %s"%(os.getcwd(), f)
688        print cmd
689        ret = os.system(cmd)
690        if ret != 0:
691            print "sage: Error running pyrexc."
692            sys.exit(1)
693        # If the language for the extension is C++,
694        # then move the resulting output file to have the correct extension.
695        # (I don't know how to tell Pyrex to do this automatically.)
696        if m.language == 'c++':
697            os.system('mv %s.c %s'%(f[:-4], outfile))
698    return [outfile]
699   
700
701def pyrex(ext_modules):
702    for m in ext_modules:
703        m.extra_compile_args += extra_compile_args
704#        m.extra_link_args += extra_link_args
705        new_sources = []
706        for i in range(len(m.sources)):
707            f = m.sources[i]
708            s = open(f).read()
709            if f[-5:] == '.pyxe':# and s.find("#embed") != -1 and s.find('#}embed') != -1:
710                new_sources = process_pyrexembed_file(f, m)
711            elif f[-4:] == ".pyx":
712                new_sources += process_pyrex_file(f, m)
713            else:
714                new_sources.append(f)
715        m.sources = new_sources
716
717
718       
719
720if not sdist:
721    pyrex(ext_modules)
722
723setup(name        = 'sage',
724
725      version     =  SAGE_VERSION,
726     
727      description = 'SAGE: System for Algebra and Geometry Experimentation',
728
729      license     = 'GNU Public License (GPL)',
730     
731      author      = 'William Stein',
732
733      author_email= 'wstein@gmail.com',
734     
735      url         = 'http://modular.math.washington.edu/sage',
736     
737      packages    = ['sage',
738                     
739                     'sage.algebras',
740                     
741                     'sage.catalogue',
742                     
743                     'sage.categories',
744
745                     'sage.coding',
746
747                     'sage.combinat',
748                     
749                     'sage.crypto',
750                     
751                     'sage.databases',
752                     
753                     'sage.ext',
754                     
755                     'sage.calculus',
756
757                     'sage.functions',
758
759                     'sage.geometry',
760
761                     'sage.games',
762
763                     'sage.gsl',
764                     
765                     'sage.graphs',
766                     
767                     'sage.groups',
768                     'sage.groups.abelian_gps',
769                     'sage.groups.matrix_gps',
770                     'sage.groups.perm_gps',
771                     
772                     'sage.interfaces',
773
774                     'sage.lfunctions',
775                     
776                     'sage.libs',
777                     'sage.libs.hanke',
778                     'sage.libs.mwrank',
779                     'sage.libs.ntl',
780                     'sage.libs.ec',
781                     'sage.libs.pari',
782                     'sage.libs.cf',
783                     
784                     'sage.matrix',
785                     
786                     'sage.misc',
787                     
788                     'sage.modules',
789                     
790                     'sage.modular',
791                     'sage.modular.abvar',
792                     'sage.modular.hecke',
793                     'sage.modular.modform',
794                     'sage.modular.modsym',
795                     'sage.modular.ssmod',
796                     
797                     'sage.monoids',
798                     
799                     'sage.plot',
800                     'sage.plot.mpl3d',
801                     
802                     'sage.probability',
803
804                     'sage.quadratic_forms',
805
806                     'sage.rings',
807                     'sage.rings.number_field',
808                     'sage.rings.padics',
809                     
810                     'sage.tests',
811                     
812                     'sage.sets',
813                     
814                     'sage.schemes',
815                     'sage.schemes.generic',
816                     'sage.schemes.jacobians',
817                     'sage.schemes.plane_curves',
818                     'sage.schemes.plane_quartics',
819                     'sage.schemes.elliptic_curves',
820                     'sage.schemes.hyperelliptic_curves',
821
822                     'sage.server',
823                     'sage.server.server1',
824                     'sage.server.notebook',
825                     'sage.server.wiki',
826                     'sage.server.trac',
827                     
828                     'sage.structure',
829                     'sage.dsage'
830                     ],
831     
832      ext_modules = ext_modules,
833      include_dirs = include_dirs)
834
835 
836 
Note: See TracBrowser for help on using the repository browser.