Add pyrex_directives dictionary optional attribute of Extension objects to
authorChuck Blake <cb@pdos.csail.mit.edu>
Thu, 22 Jul 2010 22:17:46 +0000 (18:17 -0400)
committerChuck Blake <cb@pdos.csail.mit.edu>
Thu, 22 Jul 2010 22:17:46 +0000 (18:17 -0400)
support distutils/setup.py-based directives setting.

Cython/Distutils/build_ext.py
Cython/Distutils/extension.py

index 1f11ca7f059d5658cb0a20dd675658c67deca375..0f8acf5a9a4c40488466dcff1821f5cb1b3e163b 100644 (file)
@@ -44,6 +44,8 @@ class build_ext(_build_ext.build_ext):
          "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 @@ class build_ext(_build_ext.build_ext):
         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 @@ class build_ext(_build_ext.build_ext):
         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 @@ class build_ext(_build_ext.build_ext):
             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 @@ class build_ext(_build_ext.build_ext):
                 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,
index e781c3e7052a395bf658cf2e629053f957a3ee77..23b54698af636ac5848a8fdc5da0cfa92749a745 100644 (file)
@@ -19,6 +19,8 @@ class Extension(_Extension.Extension):
     """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 @@ class Extension(_Extension.Extension):
             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 @@ class Extension(_Extension.Extension):
             **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