It would be nice to be able to support the new command line
compiler directives in distutils-based setup.py build scripts.
E.g., something like this

    extens = [ Extension(...), Extension(...), ... ]
    for x in extens:
        x.pyrex_directives = { "infer_types.verbose": True,
                               "embedsignature": True }

The attached hg export format patch (against the current
cython-closures tip) accomplishes this.  I've run this
and tested it on my own setup.py's and it has worked fine.
Thoughts?
# HG changeset patch
# User Chuck Blake <[email protected]>
# Date 1279837066 14400
# Node ID f3ce2586682a874544a1ceb2318ab388fbc81f3e
# Parent  f04cdb0edf515ebe1baa348959ad17d7dbf40a73
Add pyrex_directives dictionary optional attribute of Extension objects to
support distutils/setup.py-based directives setting.

diff -r f04cdb0edf51 -r f3ce2586682a Cython/Distutils/build_ext.py
--- a/Cython/Distutils/build_ext.py     Wed Jul 21 00:50:00 2010 +0200
+++ b/Cython/Distutils/build_ext.py     Thu Jul 22 18:17:46 2010 -0400
@@ -44,6 +44,8 @@
          "put generated C files in temp directory"),
         ('pyrex-gen-pxi', None,
             "generate .pxi file for public declarations"),
+        ('pyrex-directives=', None,
+            "compiler directive overrides"),
         ])
 
     boolean_options.extend([
@@ -56,6 +58,7 @@
         self.pyrex_create_listing = 0
         self.pyrex_line_directives = 0
         self.pyrex_include_dirs = None
+        self.pyrex_directives = None
         self.pyrex_c_in_temp = 0
         self.pyrex_gen_pxi = 0
 
@@ -66,6 +69,8 @@
         elif type(self.pyrex_include_dirs) is StringType:
             self.pyrex_include_dirs = \
                 self.pyrex_include_dirs.split(os.pathsep)
+        if self.pyrex_directives is None:
+            self.pyrex_directives = {}
     # finalize_options ()
 
     def build_extensions(self):
@@ -139,6 +144,13 @@
             if not i in includes:
                 includes.append(i)
 
+        # Set up Cython compiler directives:
+        #    1. Start with the command line option.
+        #    2. Add in any (unique) entries from the extension
+        #         pyrex_directives (if Cython.Distutils.extension is used).
+        directives = self.pyrex_directives
+        directives.update(extension.pyrex_directives)
+
         # Set the target_ext to '.c'.  Cython will change this to '.cpp' if
         # needed.
         if cplus:
@@ -189,6 +201,7 @@
                 options = CompilationOptions(pyrex_default_options, 
                     use_listing_file = create_listing,
                     include_path = includes,
+                    compiler_directives = directives,
                     output_file = target,
                     cplus = cplus,
                     emit_linenums = line_directives,
diff -r f04cdb0edf51 -r f3ce2586682a Cython/Distutils/extension.py
--- a/Cython/Distutils/extension.py     Wed Jul 21 00:50:00 2010 +0200
+++ b/Cython/Distutils/extension.py     Thu Jul 22 18:17:46 2010 -0400
@@ -19,6 +19,8 @@
     """pyrex_include_dirs : [string]
         list of directories to search for Pyrex header files (.pxd) (in
         Unix form for portability)
+    pyrex_directives : {string:value}
+        dict of compiler directives
     pyrex_create_listing_file : boolean
         write pyrex error messages to a listing (.lis) file.
     pyrex_line_directivess : boolean
@@ -48,6 +50,7 @@
             depends = None,
             language = None,
             pyrex_include_dirs = None,
+            pyrex_directives = None,
             pyrex_create_listing = 0,
             pyrex_line_directives = 0,
             pyrex_cplus = 0,
@@ -72,6 +75,7 @@
             **kw)
 
         self.pyrex_include_dirs = pyrex_include_dirs or []
+        self.pyrex_directives = pyrex_directives or {}
         self.pyrex_create_listing = pyrex_create_listing
         self.pyrex_line_directives = pyrex_line_directives
         self.pyrex_cplus = pyrex_cplus
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to