[Distutils] Wanted: ideas for using distutils with preprocessors/dependencies

Robert Kern rkern at ucsd.edu
Mon Jul 18 10:04:27 CEST 2005


Jack Jansen wrote:
> I'm currently looking at integrating bgen with distutils.

Take a look at scipy_distutils. One thing that you can do is pass in a 
function as the sources argument of Extension. For example, to build the 
C source from a Pyrex source:

     def generate_c_from_pyrex(extension, build_dir):
         name = extension.name.split('.')[-1]
         source = extension.depends[0]
         target = os.path.join(build_dir, name+'.c')

         if newer_group(extension.depends, target):
             options = Main.CompilationOptions(
                 defaults=Main.default_options,
                 output_file=target)
             pyrex_result = Main.compile(source, options=options)
             if pyrex_result.num_errors != 0:
                 raise RuntimeError("%d errors in Pyrex compile" %
                     pyrex_result.num_errors)
         return target

scipy_distutils adds a build_src command that precedes build_ext that 
executes these functions. It's a bit of a hack, and sometimes is a bit 
finicky, but it works.

http://www.scipy.net/cgi-bin/viewcvsx.cgi/scipy_core/scipy_distutils/

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Distutils-SIG mailing list