summaryrefslogtreecommitdiff
path: root/weave/ext_tools.py
diff options
context:
space:
mode:
authorEric Jones <eric@enthought.com>2003-03-25 10:41:21 +0000
committerEric Jones <eric@enthought.com>2003-03-25 10:41:21 +0000
commitd419e6c49b96ff03ff67c7af439da3c94345e903 (patch)
tree2592165c45919c3c9f0fbfc6b8d366a19b881c14 /weave/ext_tools.py
parentaba4027dd43ebb2e3c839595d8690bc0dfb70706 (diff)
downloadnumpy-d419e6c49b96ff03ff67c7af439da3c94345e903.tar.gz
added setup_extension() method to ext_module to return
distutils.core.Extension object for a weave generated extension. This is helpful in using weave extensions within setup.py files. added logic inside ext_module.generate_module to check whether the new extension module code is different from the code that may already exist in a previously generated extension module file. If the code is the same, the file is not overwritten. This prevents setup.py from thinking the module is always out of date and must be recompiled.
Diffstat (limited to 'weave/ext_tools.py')
-rw-r--r--weave/ext_tools.py56
1 files changed, 38 insertions, 18 deletions
diff --git a/weave/ext_tools.py b/weave/ext_tools.py
index 6d21e11ef..241e98d6e 100644
--- a/weave/ext_tools.py
+++ b/weave/ext_tools.py
@@ -283,19 +283,8 @@ class ext_module:
for i in self.functions:
i.set_compiler(compiler)
self.compiler = compiler
-
- def compile(self,location='.',compiler=None, verbose = 0, **kw):
-
- if compiler is not None:
- self.compiler = compiler
-
- # !! removed -- we don't have any compiler dependent code
- # currently in spec or info classes
- # hmm. Is there a cleaner way to do this? Seems like
- # choosing the compiler spagettis around a little.
- #compiler = build_tools.choose_compiler(self.compiler)
- #self.set_compiler(compiler)
-
+
+ def build_kw_and_file(self,location,kw):
arg_specs = self.arg_specs()
info = self.build_information()
_source_files = info.sources()
@@ -316,8 +305,28 @@ class ext_module:
info.extra_compile_args()
kw['extra_link_args'] = kw.get('extra_link_args',[]) + \
info.extra_link_args()
-
+ kw['sources'] = kw.get('sources',[]) + source_files
file = self.generate_file(location=location)
+ return kw,file
+
+ def setup_extension(self,location='.',**kw):
+ kw,file = self.build_kw_and_file(location,kw)
+ return build_tools.create_extension(file, **kw)
+
+ def compile(self,location='.',compiler=None, verbose = 0, **kw):
+
+ if compiler is not None:
+ self.compiler = compiler
+
+ # !! removed -- we don't have any compiler dependent code
+ # currently in spec or info classes
+ # hmm. Is there a cleaner way to do this? Seems like
+ # choosing the compiler spagettis around a little.
+ #compiler = build_tools.choose_compiler(self.compiler)
+ #self.set_compiler(compiler)
+
+ kw,file = self.build_kw_and_file(location,kw)
+
# This is needed so that files build correctly even when different
# versions of Python are running around.
# Imported at beginning of file now to help with test paths.
@@ -327,7 +336,6 @@ class ext_module:
temp = catalog.intermediate_dir()
success = build_tools.build_extension(file, temp_dir = temp,
- sources = source_files,
compiler_name = compiler,
verbose = verbose, **kw)
if not success:
@@ -338,9 +346,21 @@ def generate_file_name(module_name,module_location):
return os.path.abspath(module_file)
def generate_module(module_string, module_file):
- f =open(module_file,'w')
- f.write(module_string)
- f.close()
+ """ generate the source code file. Only overwrite
+ the existing file if the actual source has changed.
+ """
+ file_changed = 1
+ if os.path.exists(module_file):
+ f =open(module_file,'r')
+ old_string = f.read()
+ f.close()
+ if old_string == module_string:
+ file_changed = 0
+ if file_changed:
+ print 'file changed'
+ f =open(module_file,'w')
+ f.write(module_string)
+ f.close()
return module_file
def assign_variable_types(variables,local_dict = {}, global_dict = {},