[Pyrex] simple script for compiling

Brian Blais bblais at bryant.edu
Thu May 10 14:26:15 UTC 2007


Hello,

Can someone tell me if there is something like this already written?  I am planning a 
seminar on using Python as a Matlab replacement, and part of it uses Pyrex as a 
replacement for the cmex.  Windows users are not generally too keen on commandlines, 
especially DOS commandlines, so I wrote a little script to handle the writing of a 
basic setup.py, and calling the python -setup command.  That way, from the python 
shell one can do:

from pyrex_compile import *
compile('myfile.pyx')


It is still very rough, but is there something out there already for this?


		thanks,

			Brian Blais


-- 
-----------------

              bblais at bryant.edu
              http://web.bryant.edu/~bblais



def compile(fname):

     import os
     import sys
     import subprocess
     parts=os.path.splitext(fname)

     fid=open('setup_pyrex.py','w')
     fid.write("""from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext

setup(
   name = 'Blah',
   ext_modules=[
     Extension("%s",       ["%s"])
     ],
   cmdclass = {'build_ext': build_ext}
)
""" % (parts[0],fname))

     fid.close()

     if sys.platform=='win32':
         cmdlist='c:/python25/python setup_pyrex.py build_ext --inplace'.split()
         output=subprocess.Popen(
             cmdlist,stdin=subprocess.PIPE,
             stdout=subprocess.PIPE,stderr=subprocess.PIPE)
         S=''.join(output.stdout.readlines())+''.join(output.stderr.readlines())

         print S
     else:
         cmd='python setup_pyrex.py build_ext --inplace'
         os.system(cmd)





More information about the Pyrex mailing list