From 083cceb6b12721daf789bd6d33216a2d3a39e9ad Mon Sep 17 00:00:00 2001 From: Chuck Blake Date: Thu, 22 Jul 2010 18:17:46 -0400 Subject: [PATCH] Add pyrex_directives dictionary optional attribute of Extension objects to support distutils/setup.py-based directives setting. --- Cython/Distutils/build_ext.py | 13 +++++++++++++ Cython/Distutils/extension.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Cython/Distutils/build_ext.py b/Cython/Distutils/build_ext.py index 1f11ca7f..0f8acf5a 100644 --- a/Cython/Distutils/build_ext.py +++ b/Cython/Distutils/build_ext.py @@ -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, diff --git a/Cython/Distutils/extension.py b/Cython/Distutils/extension.py index e781c3e7..23b54698 100644 --- a/Cython/Distutils/extension.py +++ b/Cython/Distutils/extension.py @@ -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 -- 2.26.2