Annotation of python/pyGiNaC/setup3.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.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: 
        !           132: major_version = 0
        !           133: minor_version = 2
        !           134: try: execfile(os.path.join('tools','get_revision.py'))
        !           135: except: revision_version = 0
        !           136: version='%d.%d.%d'%(major_version,minor_version,revision_version)
        !           137: 
        !           138: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
        !           139: 
        !           140: ginac_cpp = os.path.join('src','_ginac.cpp')
        !           141: wrapper_dir = 'wrappers3'
        !           142: 
        !           143: ex_src = [
        !           144:     os.path.join(wrapper_dir,'ex_py.cpp'),
        !           145:     os.path.join(wrapper_dir,'python_repr.cpp'),
        !           146:     os.path.join(wrapper_dir,'python_str.cpp'),
        !           147:     ]
        !           148: 
        !           149: if gentest:
        !           150:     #names = ['ex','symbol','numeric','lst','add','mul','power']
        !           151:     import re
        !           152:     dt_match = re.compile(r'\s*/[*]DT(?P<text>.*?)[*]/',re.M|re.S)
        !           153:     mdt_match = re.compile(r'\s*/[*]M_DT(?P<text>.*?)[*]/',re.M|re.S)
        !           154:     fdt_match = re.compile(r'\s*/[*]F_DT(?P<text>.*?)[*]/',re.M|re.S)
        !           155:     fon = os.path.join('lib3','doc','__init__.py')
        !           156:     fo = open(fon,'w')
        !           157:     fo.write('''#!/usr/bin/env python
        !           158: import sys,os
        !           159: from distutils import util
        !           160: sys.path.insert(0,os.path.abspath(os.path.join("build","lib.%s-%s" % (util.get_platform(),sys.version[0:3]))))
        !           161: ''')
        !           162:     ex_methods = []
        !           163:     for s in wrap_input:
        !           164:         f = s + '_py.cpp'
        !           165:         fn = os.path.join(wrapper_dir,f)
        !           166:         if not os.path.isfile(fn): continue
        !           167:         m = dt_match.findall(open(fn,'r').read())
        !           168:         if m:
        !           169:             fo.write('\nclass test_%s:\n    """\n'%s)
        !           170:             fo.write(''.join(m))
        !           171:             fo.write('\n"""\n')
        !           172:         m = mdt_match.findall(open(fn,'r').read())
        !           173:         if m:
        !           174:             for l in m:
        !           175:                 p,d=l.split('\n',1)
        !           176:                 ex_methods.append('''\n    def %s:\n        """%s"""\n'''%(p.strip(),d.strip()))
        !           177:         m = fdt_match.findall(open(fn,'r').read())
        !           178:         if m:
        !           179:             for l in m:
        !           180:                 p,d=l.split('\n',1)
        !           181:                 fo.write('''def %s:\n    """%s"""\n'''%(p.strip(),d.strip()))
        !           182:     fo.write('''\
        !           183: class ex:
        !           184: %s
        !           185: def _test():
        !           186:     import doctest
        !           187:     import __init__ as tt
        !           188:     return doctest.testmod(tt)
        !           189: if __name__ == "__main__":
        !           190:     _test()\n'''%('\n'.join(ex_methods)))
        !           191:     fo.close()    
        !           192:     if gentest==2:
        !           193:         os.system('%s %s -v'%(sys.executable,fon))
        !           194:     else:
        !           195:         os.system('%s %s'%(sys.executable,fon))
        !           196: 
        !           197: if len(sys.argv)==1:
        !           198:     print "PyGiNaC Version",version
        !           199:     sys.exit()
        !           200: if rebuild:
        !           201:     f=open(os.path.join(wrapper_dir,'ex_py_subs.cpp'),'w')
        !           202:     for n in wrap_input:
        !           203:         ff = n + '_py.cpp'
        !           204:         fn = os.path.join(wrapper_dir,ff)
        !           205:         if n=='ex': continue
        !           206:         if not os.path.isfile(fn):
        !           207:             print 'File does not exist:',fn,'    Skipping.'
        !           208:             continue
        !           209:         f.write('#include "%s"\n'%ff)
        !           210:     f.write('#undef PYGINAC_DEFS\n#undef PYGINAC_EX_PROTOS\n#undef PYGINAC_PROTOS\n')
        !           211:     f.close()
        !           212:     os.system('touch wrappers3/ex_py.cpp')
        !           213: 
        !           214: if 0 and rebuild or not os.path.exists(ginac_cpp):
        !           215: 
        !           216:     build_ginac_cpp(wrap_input,ginac_cpp,wrapper_dir,onlydoc=0,onlytest=0,
        !           217:                     vers=version,credits=__credits__)
        !           218: 
        !           219: ginac_ext = Extension('ginac._ginac3',
        !           220:                       sources=ex_src+bpl_src,
        !           221:                       include_dirs=[boost_dir,wrapper_dir],
        !           222:                       libraries=['ginac','cln'],
        !           223:                       library_dirs=[],
        !           224:                       )
        !           225: 
        !           226: #++++++++++++++++++++ setup +++++++++++++++++++++
        !           227: 
        !           228: setup (name = "PyGiNaC",
        !           229:        version = version,
        !           230:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
        !           231:        author = "Pearu Peterson",
        !           232:        author_email = "pearu@cens.ioc.ee",
        !           233:        maintainer = "Pearu Peterson",
        !           234:        maintainer_email = "pearu@cens.ioc.ee",
        !           235:        licence = "LGPL",
        !           236:        long_description= """
        !           237: GiNaC is an open framework for symbolic computation within the C++
        !           238: programming language (http://www.ginac.de/).
        !           239: PyGiNaC is a Python package that provides a transparent interface
        !           240: to GiNaC library. Currently the following GiNaC classes are exposed:
        !           241:   ex, symbol, numeric, constant, relational, add, mul, power, ncmul,
        !           242:   matrix, pseries, function, idx, varidx, tensor, indexed,
        !           243:   lst, exvector, expair, exlist, epvector, etc.
        !           244: In addition, PyGiNaC provides wrappers for various elementary functions,
        !           245: such as sin, factorial, etc.
        !           246: """,
        !           247:        url = "http://cens.ioc.ee/projects/pyginac/",
        !           248:        ext_modules = [ ginac_ext ],
        !           249:        packages = ['ginac','ginac.doc'],
        !           250:        package_dir = {'ginac': 'lib3',
        !           251:                       'ginac.doc':os.path.join('lib3','doc') },
        !           252:        )
        !           253: 
        !           254: print "PyGiNaC Version",version

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