Annotation of python/pyGiNaC/setup3.py, revision 1.2

1.1       pearu       1: #!/usr/bin/env python
                      2: #
                      3: #   Setup file for building/installing PyGiNaC
                      4: #
                      5: # Requirements:
                      6: #   Python 2.0 or higher (http://www.python.org/)
                      7: #   GiNaC 0.8.0 or higher (http://www.ginac.de/)
                      8: #     For GiNaC, you'll need CLN 1.1 (http://clisp.cons.org/~haible/packages-cln.html)
                      9: #       Optional, but recommended, CLN can use GMP 3.1.1 (http://www.swox.com/gmp/)
                     10: #   Boost 1.21.1 or higher (http://www.boost.org/)
                     11: #  
                     12: # Usage:
                     13: #   > python setup.py doc install  # this will generate ginac.doc, builds _ginac
                     14: #                                  # and installs the package.
                     15: #   > python setup.py test -v      # this will generate and run test/test_dt.py
                     16: #
                     17: # In Python `import ginac'. Module `ginac' extension classes exposing
                     18: # almost all GiNaC classes to Python.
                     19: # See GiNaC documentation (http://www.ginac.de/tutorial/) for usage.
                     20: #
                     21: # Notes:
                     22: # 1. Compilation of PyGiNaC requires more than 160MB memory (with gcc -O2
                     23: #   on Intel Linux). However, if you don't need all the GiNaC classes
                     24: #   to be exposed to Python, you can edit the list `wrap_input' below
                     25: #   to indicate your needs, this will decrease also the memory consumption
                     26: #   during the compilation. You don't need to worry about class dependencies
                     27: #   they are solved automatically. After you edit `wrap_input', run
                     28: #  > python setup.py reinstall
                     29: #
                     30: # Pearu Peterson <pearu@cens.ioc.ee>
                     31: # 30 March 2001
                     32: 
                     33: __credits__ = """\
                     34: GiNaC people (www.ginac.de), for the GiNaC library.
                     35: Boost.Python people (www.boost.org), for BPL that considerably
                     36: simplified the wrapping of GiNaC C++ classes to Python.
                     37: """
                     38: 
                     39: import sys,os,string,time
                     40: 
                     41: #++++++++++++++ Require Python 2.x +++++++++++++
                     42: 
                     43: if eval(sys.version[0])<2:
                     44:     print "You'll need Python 2.0 or higher to build PyGiNaC"
                     45:     sys.exit()
                     46: 
                     47: #++++++++++++++ Rebuild ++++++++++++++++++++++++
                     48: rebuild = 0
                     49: gendoc = 0
                     50: gentest = 0
                     51: disable_opt = 1 # set 0 for final compilation
                     52: 
                     53: if 'test' in sys.argv:
                     54:     i = sys.argv.index('test')
                     55:     gentest = 1
                     56:     if len(sys.argv)>i+1 and sys.argv[i+1]=='-v':
                     57:         gentest = 2
                     58:         del sys.argv[i+1]
                     59:     del sys.argv[i]
                     60: if 'doc' in sys.argv:
                     61:     del sys.argv[sys.argv.index('doc')]
                     62:     gendoc = 1
                     63: 
                     64: if 'rebuild' in sys.argv:
                     65:     sys.argv[sys.argv.index('rebuild')] = 'build'
                     66:     rebuild = 1
                     67: if 'reinstall' in sys.argv:
                     68:     sys.argv[sys.argv.index('reinstall')] = 'install'
                     69:     rebuild = 1
                     70: 
                     71: wrap_input = ['symbol','numeric','constant','relational',
                     72:               'lst','idx','varidx','power','add','mul',
                     73:               'ncmul','pseries','matrix','function','inifcns',
                     74:               'function','flags','exvector',
                     75:               'indexed','color','clifford','tensor']
                     76: 
                     77: wrap_input = ['symbol','numeric','constant','relational',
                     78:               'lst','power','add','mul',
                     79:               'ncmul','pseries','matrix','function','inifcns',
                     80:               'function','flags','exvector']
                     81: 
                     82: #wrap_input += ['indexed','color','clifford','tensor']
                     83: 
                     84: #wrap_input = ['function','inifcns']
                     85: #wrap_input = ['add','mul','power','lst','pseries','relational','matrix','numeric','constant','symbol','varidx']
                     86: #wrap_input = ['symbol','function']
                     87: #wrap_input = ['symbol','tensor']
                     88: #wrap_input = ['symbol','add','mul','lst','numeric','power']
                     89: 
                     90: wrap_input = ['ex','symbol','numeric','lst','add','mul','power']
                     91: 
                     92: #++++++++++++++++ Parameters ++++++++++++++++
                     93: nof_lst_params = 10   # max 15 for ginac, max 10 for boost.python, min 1
                     94: nof_ncmul_params = 6  # max 6
                     95: nof_function_params = 9 # max 13 for ginac, max 9 for boost.python, min 1
                     96: #++++++++++++++++++++ boost +++++++++++++++++++++
                     97: 
                     98: boost_dir = '/usr/local/share/boost'
                     99: 
                    100: if not os.path.isdir(boost_dir):
                    101:     print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
                    102:     print 'Get Boost from http://www.boost.org/ and fix its path in setup.py'
                    103:     sys.exit()
                    104: 
                    105: bpl_dir = os.path.join(boost_dir,'libs','python','src')
                    106: bpl_src = map(lambda f:os.path.join(bpl_dir,f),
                    107:               ['classes.cpp','conversions.cpp','extension_class.cpp',
                    108:                'functions.cpp','init_function.cpp','module_builder.cpp',
                    109:                'objects.cpp','types.cpp'])
                    110: 
                    111: #++++++++++++++++++++++++++++++++++++++++++++++++
                    112: from distutils.core import setup, Extension
                    113: 
                    114: #+++HACK: replace linker gcc with g++ +++++++++++
                    115: from distutils import sysconfig
                    116: save_init_posix = sysconfig._init_posix
                    117: def my_init_posix():
                    118:     save_init_posix()
                    119:     g = sysconfig._config_vars
                    120:     if g['LDSHARED'][:3]=='gcc':
                    121:         print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
                    122:         g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
                    123:         print 'to',`g['LDSHARED']`
                    124:     if disable_opt and g['OPT'][:6]=='-g -O2':
                    125:         print 'my_init_posix: changing OPT =',`g['OPT']`,
                    126:         g['OPT'] = '-g'+g['OPT'][6:]
                    127:         print 'to',`g['OPT']`
                    128: sysconfig._init_posix = my_init_posix
                    129: 
                    130: #+++++++++++++++++ PyGiNaC version ++++++++++++++
                    131: 
1.2     ! pearu     132: wrapper_dir = 'wrappers3'
        !           133: lib_dir = 'lib3'
        !           134: 
1.1       pearu     135: major_version = 0
1.2     ! pearu     136: minor_version = 3
1.1       pearu     137: try: execfile(os.path.join('tools','get_revision.py'))
                    138: except: revision_version = 0
                    139: version='%d.%d.%d'%(major_version,minor_version,revision_version)
                    140: 
                    141: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
                    142: 
                    143: ginac_cpp = os.path.join('src','_ginac.cpp')
1.2     ! pearu     144: 
1.1       pearu     145: 
                    146: ex_src = [
                    147:     os.path.join(wrapper_dir,'ex_py.cpp'),
                    148:     os.path.join(wrapper_dir,'python_repr.cpp'),
                    149:     os.path.join(wrapper_dir,'python_str.cpp'),
                    150:     ]
                    151: 
                    152: if gentest:
                    153:     #names = ['ex','symbol','numeric','lst','add','mul','power']
                    154:     import re
                    155:     dt_match = re.compile(r'\s*/[*]DT(?P<text>.*?)[*]/',re.M|re.S)
                    156:     mdt_match = re.compile(r'\s*/[*]M_DT(?P<text>.*?)[*]/',re.M|re.S)
                    157:     fdt_match = re.compile(r'\s*/[*]F_DT(?P<text>.*?)[*]/',re.M|re.S)
1.2     ! pearu     158:     todo_match = re.compile(r'\s*/[*]\s*TODO(?P<text>.*?)[*]/',re.M|re.S)
        !           159:     fon = os.path.join(lib_dir,'doc','__init__.py')
1.1       pearu     160:     fo = open(fon,'w')
1.2     ! pearu     161:     ftodo = open('TODO_py.txt','w')
1.1       pearu     162:     fo.write('''#!/usr/bin/env python
                    163: import sys,os
                    164: from distutils import util
                    165: sys.path.insert(0,os.path.abspath(os.path.join("build","lib.%s-%s" % (util.get_platform(),sys.version[0:3]))))
                    166: ''')
                    167:     ex_methods = []
                    168:     for s in wrap_input:
                    169:         f = s + '_py.cpp'
                    170:         fn = os.path.join(wrapper_dir,f)
                    171:         if not os.path.isfile(fn): continue
                    172:         m = dt_match.findall(open(fn,'r').read())
                    173:         if m:
                    174:             fo.write('\nclass test_%s:\n    """\n'%s)
                    175:             fo.write(''.join(m))
                    176:             fo.write('\n"""\n')
                    177:         m = mdt_match.findall(open(fn,'r').read())
                    178:         if m:
                    179:             for l in m:
                    180:                 p,d=l.split('\n',1)
                    181:                 ex_methods.append('''\n    def %s:\n        """%s"""\n'''%(p.strip(),d.strip()))
1.2     ! pearu     182:         m = todo_match.findall(open(fn,'r').read())
        !           183:         if m:
        !           184:             ftodo.write('In file %s:\n'%fn)
        !           185:             ftodo.write('\n'.join(map(lambda s:s.strip(),m))+'\n')
1.1       pearu     186:         m = fdt_match.findall(open(fn,'r').read())
                    187:         if m:
                    188:             for l in m:
                    189:                 p,d=l.split('\n',1)
                    190:                 fo.write('''def %s:\n    """%s"""\n'''%(p.strip(),d.strip()))
                    191:     fo.write('''\
                    192: class ex:
                    193: %s
                    194: def _test():
                    195:     import doctest
                    196:     import __init__ as tt
                    197:     return doctest.testmod(tt)
                    198: if __name__ == "__main__":
                    199:     _test()\n'''%('\n'.join(ex_methods)))
1.2     ! pearu     200:     fo.close()
        !           201:     ftodo.close()
1.1       pearu     202:     if gentest==2:
                    203:         os.system('%s %s -v'%(sys.executable,fon))
                    204:     else:
                    205:         os.system('%s %s'%(sys.executable,fon))
                    206: 
                    207: if len(sys.argv)==1:
                    208:     print "PyGiNaC Version",version
                    209:     sys.exit()
                    210: if rebuild:
1.2     ! pearu     211:     print 'Creating file',os.path.join(wrapper_dir,'ex_py_subs.cpp')
1.1       pearu     212:     f=open(os.path.join(wrapper_dir,'ex_py_subs.cpp'),'w')
                    213:     for n in wrap_input:
                    214:         ff = n + '_py.cpp'
                    215:         fn = os.path.join(wrapper_dir,ff)
                    216:         if n=='ex': continue
                    217:         if not os.path.isfile(fn):
                    218:             print 'File does not exist:',fn,'    Skipping.'
                    219:             continue
                    220:         f.write('#include "%s"\n'%ff)
                    221:     f.write('#undef PYGINAC_DEFS\n#undef PYGINAC_EX_PROTOS\n#undef PYGINAC_PROTOS\n')
                    222:     f.close()
                    223:     os.system('touch wrappers3/ex_py.cpp')
                    224: 
                    225: if 0 and rebuild or not os.path.exists(ginac_cpp):
                    226: 
                    227:     build_ginac_cpp(wrap_input,ginac_cpp,wrapper_dir,onlydoc=0,onlytest=0,
                    228:                     vers=version,credits=__credits__)
                    229: 
                    230: ginac_ext = Extension('ginac._ginac3',
                    231:                       sources=ex_src+bpl_src,
                    232:                       include_dirs=[boost_dir,wrapper_dir],
                    233:                       libraries=['ginac','cln'],
                    234:                       library_dirs=[],
                    235:                       )
                    236: 
                    237: #++++++++++++++++++++ setup +++++++++++++++++++++
                    238: 
                    239: setup (name = "PyGiNaC",
                    240:        version = version,
                    241:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
                    242:        author = "Pearu Peterson",
                    243:        author_email = "pearu@cens.ioc.ee",
                    244:        maintainer = "Pearu Peterson",
                    245:        maintainer_email = "pearu@cens.ioc.ee",
                    246:        licence = "LGPL",
                    247:        long_description= """
                    248: GiNaC is an open framework for symbolic computation within the C++
                    249: programming language (http://www.ginac.de/).
                    250: PyGiNaC is a Python package that provides a transparent interface
                    251: to GiNaC library. Currently the following GiNaC classes are exposed:
                    252:   ex, symbol, numeric, constant, relational, add, mul, power, ncmul,
                    253:   matrix, pseries, function, idx, varidx, tensor, indexed,
                    254:   lst, exvector, expair, exlist, epvector, etc.
                    255: In addition, PyGiNaC provides wrappers for various elementary functions,
                    256: such as sin, factorial, etc.
                    257: """,
                    258:        url = "http://cens.ioc.ee/projects/pyginac/",
                    259:        ext_modules = [ ginac_ext ],
                    260:        packages = ['ginac','ginac.doc'],
1.2     ! pearu     261:        package_dir = {'ginac': lib_dir,
        !           262:                       'ginac.doc':os.path.join(lib_dir,'doc') },
1.1       pearu     263:        )
                    264: 
                    265: print "PyGiNaC Version",version

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>