Annotation of python/pyGiNaC/setup4.py, revision 1.1

1.1     ! pearu       1: #!/usr/bin/env python
        !             2: #
        !             3: #   Setup file for building/installing PyGiNaC
        !             4: #
        !             5: # Requirements:
        !             6: #   Python 2.1 or higher (http://www.python.org/)
        !             7: #   GiNaC 0.9.2 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 doctests.
        !            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: # 23 April 2001
        !            33: # 11 August 2001
        !            34: 
        !            35: __credits__ = """\
        !            36: GiNaC group (www.ginac.de), for the GiNaC library.
        !            37: Boost.Python group (www.boost.org), for BPL that considerably
        !            38: simplified in exposing GiNaC C++ classes to Python.
        !            39: """
        !            40: 
        !            41: import sys,os,string,time
        !            42: 
        !            43: __today__ = time.asctime(time.localtime())
        !            44: __author__ = 'Pearu Peterson <pearu@cens.ioc.ee>'
        !            45: 
        !            46: #++++++++++++++ Require Python 2.x +++++++++++++
        !            47: 
        !            48: if eval(sys.version[0])<2:
        !            49:     print "You'll need Python 2.0 or higher to build PyGiNaC"
        !            50:     sys.exit()
        !            51: print 'Python Version',sys.version.split()[0]
        !            52: 
        !            53: #++++++++++++++ Rebuild ++++++++++++++++++++++++
        !            54: rebuild = 0
        !            55: gendoc = 0
        !            56: gentest = 0
        !            57: disable_opt = 1 # set 0 for final compilation
        !            58: 
        !            59: if 'test' in sys.argv:
        !            60:     i = sys.argv.index('test')
        !            61:     gentest = 1
        !            62:     if len(sys.argv)>i+1 and sys.argv[i+1]=='-v':
        !            63:         gentest = 2
        !            64:         del sys.argv[i+1]
        !            65:     del sys.argv[i]
        !            66: if 'doc' in sys.argv:
        !            67:     del sys.argv[sys.argv.index('doc')]
        !            68:     gendoc = 1
        !            69: 
        !            70: if 'rebuild' in sys.argv:
        !            71:     sys.argv[sys.argv.index('rebuild')] = 'build'
        !            72:     rebuild = 1
        !            73: if 'reinstall' in sys.argv:
        !            74:     sys.argv[sys.argv.index('reinstall')] = 'install'
        !            75:     rebuild = 1
        !            76: 
        !            77: wrap_input = ['symbol','numeric','constant','relational',
        !            78:               'lst','idx','varidx','power','add','mul',
        !            79:               'ncmul','pseries','matrix','function','inifcns',
        !            80:               'function','flags','exvector',
        !            81:               'indexed','color','clifford','tensor']
        !            82: 
        !            83: wrap_input = ['symbol','numeric','constant','relational',
        !            84:               'lst','power','add','mul',
        !            85:               'ncmul','pseries','matrix','function','inifcns',
        !            86:               'function',
        !            87:               'flags','exvector']
        !            88: 
        !            89: #wrap_input += ['indexed','color','clifford','tensor']
        !            90: 
        !            91: #wrap_input = ['function','inifcns']
        !            92: #wrap_input = ['add','mul','power','lst','pseries','relational','matrix','numeric','constant','symbol','varidx']
        !            93: #wrap_input = ['symbol','function']
        !            94: #wrap_input = ['symbol','tensor']
        !            95: #wrap_input = ['symbol','add','mul','lst','numeric','power']
        !            96: 
        !            97: wrap_input = ['ex','symbol','numeric','lst','add','mul','power',
        !            98:               'inifcns','function','relational','seq',
        !            99:               'constant','matrix','pseries','ncmul']
        !           100: 
        !           101: wrap_input = ['symbol']
        !           102: 
        !           103: #++++++++++++++++ Parameters ++++++++++++++++
        !           104: #nof_lst_params = 10   # max 15 for ginac, max 10 for boost.python, min 1
        !           105: #nof_ncmul_params = 6  # max 6
        !           106: nof_function_params = 12 # max 12 for ginac (depends also on the code in function_py.cpp)
        !           107: 
        !           108: #++++++++++++++++++++ boost.python +++++++++++++++++++++
        !           109: 
        !           110: boost_dir = '/usr/local/share/boost'
        !           111: 
        !           112: if not os.path.isdir(boost_dir):
        !           113:     print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
        !           114:     print '  Get Boost from http://www.boost.org/'
        !           115:     print '  Fix its path in setup.py'
        !           116:     sys.exit()
        !           117: 
        !           118: bpl_dir = os.path.join(boost_dir,'libs','python','src')
        !           119: bpl_src = map(lambda f:os.path.join(bpl_dir,f),
        !           120:               ['classes.cpp',
        !           121:                'conversions.cpp',
        !           122:                'extension_class.cpp',
        !           123:                #'cross_module.cpp',
        !           124:                'functions.cpp',
        !           125:                'init_function.cpp',
        !           126:                'module_builder.cpp',
        !           127:                'objects.cpp','types.cpp'])
        !           128: 
        !           129: #++++++++++++++++++++++++++++++++++++++++++++++++
        !           130: from distutils.core import setup, Extension
        !           131: 
        !           132: #+++HACK: replace linker gcc with g++ +++++++++++
        !           133: #+++      turn off optimization       +++++++++++
        !           134: from distutils import sysconfig
        !           135: save_init_posix = sysconfig._init_posix
        !           136: def my_init_posix():
        !           137:     save_init_posix()
        !           138:     g = sysconfig._config_vars
        !           139:     if g['LDSHARED'][:3]=='gcc':
        !           140:         print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
        !           141:         g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
        !           142:         print 'to',`g['LDSHARED']`
        !           143:     if disable_opt and g['OPT'][:6]=='-g -O2':
        !           144:         print 'my_init_posix: changing OPT =',`g['OPT']`,
        !           145:         g['OPT'] = '-g'+g['OPT'][6:]
        !           146:         print 'to',`g['OPT']`
        !           147: sysconfig._init_posix = my_init_posix
        !           148: 
        !           149: #+++++++++++++++++ PyGiNaC version ++++++++++++++
        !           150: 
        !           151: edition = 4
        !           152: wrapper_dir = 'wrappers%d'%edition
        !           153: lib_dir = 'lib%d'%edition
        !           154: src_dir = 'src%d'%edition
        !           155: 
        !           156: major_version = 0
        !           157: minor_version = 6
        !           158: try: execfile(os.path.join('tools','get_revision.py'))
        !           159: except: revision_version = 0
        !           160: version='%d.%d.%d'%(major_version,minor_version,revision_version)
        !           161: version_info = (major_version,minor_version,revision_version,'proto',edition)
        !           162: 
        !           163: print 'Creating <lib>/__version__.py'
        !           164: f = open(os.path.join(lib_dir,'__version__.py'),'w')
        !           165: f.write('__version__ = "%s"\n'%(version))
        !           166: f.close()
        !           167: 
        !           168: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
        !           169: 
        !           170: ginac_cpp = os.path.join(src_dir,'_ginac.cpp')
        !           171: 
        !           172: ex_src = [
        !           173:     os.path.join(wrapper_dir,'ginac_enhancements.cpp'),
        !           174:     os.path.join(wrapper_dir,'ex_py.cpp'),
        !           175:     os.path.join(wrapper_dir,'python_repr.cpp'),
        !           176:     os.path.join(wrapper_dir,'python_str.cpp'),
        !           177:     os.path.join(wrapper_dir,'python_csrc.cpp'),
        !           178:     os.path.join(wrapper_dir,'pyfunc.cpp'),
        !           179:     os.path.join(wrapper_dir,'slice.c'),
        !           180:     ]
        !           181: 
        !           182: ex_src = []
        !           183: for n in ['ex_py.cpp']:
        !           184:     ex_src.append(os.path.join(wrapper_dir,'ex_py.cpp'))
        !           185: 
        !           186: if 0 and (gentest or gendoc):
        !           187:     import re
        !           188:     dt_match = re.compile(r'\s*/[*]DT(?P<text>.*?)[*]/',re.M|re.S)
        !           189:     mdt_match = re.compile(r'\s*/[*]M_DT(?P<text>.*?)[*]/',re.M|re.S)
        !           190:     fdt_match = re.compile(r'\s*/[*]F_DT(?P<text>.*?)[*]/',re.M|re.S)
        !           191:     todo_match = re.compile(r'\s*/[*]\s*TODO(?P<text>.*?)[*]/',re.M|re.S)
        !           192:     fon = os.path.join(lib_dir,'doc','__init__.py')
        !           193:     fo = open(fon,'w')
        !           194:     ftodo = open('TODO_py.txt','w')
        !           195:     
        !           196:     fo.write('#!/usr/bin/env python\n')
        !           197:     fo.write('"""PyGiNaC class documentation."""\n')
        !           198:     fo.write('__version__ = '+`version`+'\n')
        !           199:     fo.write('__date__ = '+`__today__`+'\n')
        !           200:     fo.write('__author__ = '+`__author__`+'\n')
        !           201:     fo.write('__credits__ = '+`__credits__`+'\n')
        !           202:     fo.write('''\
        !           203: # This file (ginac/doc/.__init__.py) is auto-generated with
        !           204: # a command "cd pyGiNaC && ./setup.py test"
        !           205: # Website: http://cens.ioc.ee/projects/pyginac/\n''')
        !           206:     fo.write('''\
        !           207: if __name__ == "__main__":
        !           208:     import sys,os
        !           209:     from distutils import util
        !           210:     sys.path.insert(0,os.path.abspath(os.path.join("build","lib.%s-%s" % (util.get_platform(),sys.version[0:3]))))\n''')
        !           211:     ex_methods = []
        !           212:     i = 0
        !           213:     for s in wrap_input:
        !           214:         i += 1
        !           215:         f = s + '_py.cpp'
        !           216:         fn = os.path.join(wrapper_dir,f)
        !           217:         if not os.path.isfile(fn): continue
        !           218:         m = dt_match.findall(open(fn,'r').read())
        !           219:         if m:
        !           220:             fo.write('\nclass test_%.2i_%s:\n    """\n'%(i,s))
        !           221:             fo.write(''.join(m))
        !           222:             fo.write('\n"""\n')
        !           223:         m = mdt_match.findall(open(fn,'r').read())
        !           224:         if m:
        !           225:             for l in m:
        !           226:                 p,d=l.split('\n',1)
        !           227:                 ex_methods.append('''\n    def %s:\n        """%s"""\n'''%(p.strip(),d.strip()))
        !           228:         m = todo_match.findall(open(fn,'r').read())
        !           229:         if m:
        !           230:             ftodo.write('In %s:\n'%fn)
        !           231:             ftodo.write('\n'.join(map(lambda s:'\t'+s.strip(),m))+'\n')
        !           232:         m = fdt_match.findall(open(fn,'r').read())
        !           233:         if m:
        !           234:             for l in m:
        !           235:                 p,d=l.split('\n',1)
        !           236:                 fo.write('''def %s:\n    """%s"""\n'''%(p.strip(),d.strip()))
        !           237:     fo.write('''\
        !           238: class ex:
        !           239: %s
        !           240: if __name__ == "__main__":
        !           241:     import doctest
        !           242:     import __init__
        !           243:     tt = __init__
        !           244:     doctest.testmod(tt)\n'''%('\n'.join(ex_methods)))
        !           245:     fo.close()
        !           246:     ftodo.close()
        !           247:     if gentest==2:
        !           248:         os.system('%s %s -v'%(sys.executable,fon))
        !           249:     elif gentest==1:
        !           250:         os.system('%s %s'%(sys.executable,fon))
        !           251:     if gendoc:
        !           252:         #os.system('cd doc && pydoc -w ginac.html ginac')
        !           253:         os.system('cd doc && pydoc -w ginac.doc.html ginac.doc')
        !           254: if len(sys.argv)==1:
        !           255:     print "PyGiNaC Version",version
        !           256:     sys.exit()
        !           257: 
        !           258: if 0 and rebuild:
        !           259:     print 'Creating file',os.path.join(wrapper_dir,'ex_py_subs.cpp')
        !           260:     f=open(os.path.join(wrapper_dir,'ex_py_subs.cpp'),'w')
        !           261:     for n in wrap_input:
        !           262:         ff = n + '_py.cpp'
        !           263:         fn = os.path.join(wrapper_dir,ff)
        !           264:         if n=='ex': continue
        !           265:         if not os.path.isfile(fn):
        !           266:             print 'File does not exist:',fn,'    Skipping.'
        !           267:             continue
        !           268:         f.write('#include "%s"\n'%ff)
        !           269:     f.write('#undef PYGINAC_DEFS\n#undef PYGINAC_EX_PROTOS\n#undef PYGINAC_PROTOS\n')
        !           270:     f.close()
        !           271:     os.system('touch wrappers%d/ex_py.cpp'%edition)
        !           272:     print 'Creating file',os.path.join(wrapper_dir,'function_py_subs.cpp')
        !           273:     f=open(os.path.join(wrapper_dir,'function_py_subs.cpp'),'w')
        !           274:     protos,impl = [],[]
        !           275:     for k in ['eval','evalf']:
        !           276:         for i in range(nof_function_params+1):
        !           277:             a1 = ['const GiNaC::ex & a'+`j` for j in range(i)]+['const GiNaC::ex & ser']
        !           278:             a2 = ['args.set_item(%s,a%s);'%(j,j) for j in range(i)]
        !           279:             impl.append('PYGINAC_CB_FUNC(%s,%s,(%s),%s,%s)\n'%(k,i,', '.join(a1),i,' '.join(a2)))
        !           280:             protos.append('PYGINAC_CB_FUNC_PROTO(%s,%s,(%s));\n'%(k,i,', '.join(a1)))
        !           281:     if 1:
        !           282:         k = 'derivative'
        !           283:         for i in range(nof_function_params+1):
        !           284:             a1 = ['const GiNaC::ex & a'+`j` for j in range(i)]
        !           285:             a1 += ['const GiNaC::ex & ser','unsigned n']
        !           286:             a2 = ['args.set_item(%s,a%s);'%(j,j) for j in range(i)]
        !           287:             a2 += ['args.set_item(%s,n);'%i]
        !           288:             impl.append('PYGINAC_CB_FUNC(%s,%s,(%s),%s,%s)\n'%(k,i,', '.join(a1),i+1,' '.join(a2)))
        !           289:             protos.append('PYGINAC_CB_FUNC_PROTO(%s,%s,(%s));\n'%(k,i,', '.join(a1)))
        !           290:     if 1:
        !           291:         k = 'series'
        !           292:         for i in range(nof_function_params+1):
        !           293:             a1 = ['const GiNaC::ex & a'+`j` for j in range(i)]
        !           294:             a1 += ['const GiNaC::ex & ser']
        !           295:             a1 += ['const GiNaC::relational & rel']
        !           296:             a1 += ['int order']
        !           297:             a1 += ['unsigned opt']
        !           298:             a2 = ['args.set_item(%s,a%s);'%(j,j) for j in range(i)]
        !           299:             a2+= ['args.set_item(%s,rel);'%i]
        !           300:             a2+= ['args.set_item(%s,order);'%(i+1)]
        !           301:             a2+= ['args.set_item(%s,opt);'%(i+2)]
        !           302:             impl.append('PYGINAC_CB_FUNC(%s,%s,(%s),%s,%s)\n'%(k,i,', '.join(a1),i+3,' '.join(a2)))
        !           303:             protos.append('PYGINAC_CB_FUNC_PROTO(%s,%s,(%s));\n'%(k,i,', '.join(a1)))
        !           304:     f.write('#ifdef PYGINAC_PROTOS\n')
        !           305:     f.write('\n'.join(protos))
        !           306:     f.write('#else\n')
        !           307:     f.write('\n'.join(impl))
        !           308:     f.write('#endif\n')
        !           309:     f.close() 
        !           310:            
        !           311: ginac_ext = Extension('ginac._ginac',
        !           312:                       sources=ex_src+bpl_src,
        !           313:                       include_dirs=[boost_dir,wrapper_dir],
        !           314:                       libraries=['ginac','cln'],
        !           315:                       library_dirs=[],
        !           316:                       )
        !           317: 
        !           318: ex_ext = Extension('ginac._ex',
        !           319:                       sources=ex_src+bpl_src,
        !           320:                       include_dirs=[boost_dir,wrapper_dir],
        !           321:                       libraries=['ginac','cln'],
        !           322:                       library_dirs=[],
        !           323:                       )
        !           324: 
        !           325: ext_modules = [ex_ext]
        !           326: 
        !           327: #++++++++++++++++++++ setup +++++++++++++++++++++
        !           328: 
        !           329: setup (name = "PyGiNaC",
        !           330:        version = version,
        !           331:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
        !           332:        author = "Pearu Peterson",
        !           333:        author_email = "pearu@cens.ioc.ee",
        !           334:        maintainer = "Pearu Peterson",
        !           335:        maintainer_email = "pearu@cens.ioc.ee",
        !           336:        licence = "LGPL",
        !           337:        long_description= """
        !           338: GiNaC is an open framework for symbolic computation within the C++
        !           339: programming language (http://www.ginac.de/).
        !           340: PyGiNaC is a Python extension package that implements a complete
        !           341: and transparent interface to the GiNaC library.
        !           342: """,
        !           343:        url = "http://cens.ioc.ee/projects/pyginac/",
        !           344:        ext_modules = ext_modules,
        !           345:        packages = ['ginac'],
        !           346:        package_dir = {'ginac': lib_dir},
        !           347:                       #'ginac.doc':os.path.join(lib_dir,'doc') },
        !           348:        )
        !           349: 
        !           350: print "PyGiNaC Version",version

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