if not os.path.exists(fpp): warn("preprocessed sources not found for file %s, skipping" % src) continue f90doc_file = base + '.f90doc' if os.path.exists(f90doc_file): (programs, modules, functs, subts) = pickle.load(open(f90doc_file)) else: programs = None modules = None functs = None subrts = None if newer(src, f90doc_file): new_programs, new_modules, new_functs, new_subts = f90doc.read_files([fpp]) if (new_programs != programs or new_modules != modules or new_functs != functs or new_subts != subts): programs = new_programs modules = new_modules functs = new_functs subts = new_subts pickle.dump((programs, modules, functs, subts), open(f90doc_file, 'w')) mod_define[src] = [] mod_uses[src] = [] for mod,filename in modules: name = mod.name.lower() mod_define[src].append(name) filename_from_mod[name] = base+ext
def func(extension, build_dir): # first ensure libraries are up to date for (dir, target) in targets: command = "cd %s && make %s" % (dir, target) print 'Rebuilding target %s with command "%s"' % (target, command) if os.system(command) != 0: raise SystemExit('Command "%s" failed' % command) # Have any of wrap_sources changed since we last scanned source files? f90doc_file = os.path.join(build_dir, '../../%s.f90doc' % modname) if newer_group(wrap_sources, f90doc_file): # Rebuild .f90doc file containing interfaces of wrapped routines tmp_wrap_sources = [] cpp_opt = ' '.join(gen_preprocess_options(macros, include_dirs)) for src in wrap_sources: tmp_file = os.path.join(build_dir.replace('src', 'temp'), os.path.basename(src)) if not os.path.exists(os.path.dirname(tmp_file)): os.makedirs(os.path.dirname(tmp_file)) command = "%s %s %s | grep -v '^#' > %s" % ( ' '.join(cpp), cpp_opt, src, tmp_file) print 'Executing command %s' % command os.system(command) if os.path.exists(src[:-4] + '.s'): os.remove(src[:-4] + '.s') tmp_wrap_sources.append(tmp_file) programs, modules, functs, subts = f90doc.read_files( tmp_wrap_sources) cPickle.dump((programs, modules, functs, subts), open(f90doc_file, 'w')) else: # Read previous .f90doc file (programs, modules, functs, subts) = cPickle.load(open(f90doc_file)) # Update map from type names to module in which they are defined for mod, name in modules: for n in [t.name for t in mod.types]: type_map[n.lower()] = mod.name for item in dep_type_maps: if hasattr(item, '__getitem__') and hasattr(item, 'keys'): # dictionary type_map.update(item) else: # assume it's a string type_map.update(cPickle.load(open('%s.type' % item))) # Try to load previous .spec file res = [] fortran_spec = {} spec_file = os.path.join(build_dir, '../../%s.spec' % modname) if os.path.exists(spec_file): fortran_spec = cPickle.load(open(spec_file)) # Write new wrapper files and update .spec file wrap_modules = [] for file in wrap_sources: for mod, name in modules: if os.path.basename(name) == os.path.basename(file): break else: raise ValueError( "Can't find Fortran module corresponding to file %s" % file) wrap_mod_name = mod.name.lower()[:-7] rel_filename = file[len(quip_root):] if rel_filename.startswith('/'): rel_filename = rel_filename[1:] wrap_modules.append((wrap_mod_name, rel_filename)) wrapper = '%s/%s_%s_wrap.f90' % (build_dir, modname, wrap_mod_name) if not newer(name, wrapper): res.append(wrapper) continue public_symbols = f2py_wrapper_gen.find_public_symbols(file) print 'public_symbols = ', public_symbols tmpf = StringIO.StringIO() new_spec = f2py_wrapper_gen.wrap_mod( mod, type_map, tmpf, kindlines=kindlines, initlines=initlines, filtertypes=filtertypes, prefix=prefix, callback_routines=callback_routines, public_symbols=public_symbols, sizeof_fortran_t=sizeof_fortran_t) if (not os.path.exists(wrapper) or new_spec[wrap_mod_name] != fortran_spec.get( wrap_mod_name, None)): # (not f2py_wrapper_gen.cmp_nested_dict(new_spec[wrap_mod_name], # fortran_spec.get(wrap_mod_name, None)))): print 'Interface for module %s has changed. Rewriting wrapper file' % mod.name wrapperf = open(wrapper, 'w') wrapperf.write(tmpf.getvalue()) wrapperf.close() else: print 'Interface for module %s unchanged' % mod.name fortran_spec.update(new_spec) tmpf.close() res.append(wrapper) fortran_spec['wrap_modules'] = wrap_modules fortran_spec['short_names'] = short_names fortran_spec['quip_root'] = quip_root fortran_spec['quip_arch'] = quip_arch fortran_spec['quip_makefile'] = makefile cPickle.dump( fortran_spec, open(os.path.join(build_dir, '../../%s.spec' % modname), 'w')) import pprint spec_py_name = '%s/spec.py' % build_dir spec_py = open(spec_py_name, 'w') spec_py.write('spec = %s\n' % pprint.pformat(fortran_spec)) spec_py.close() res.append(spec_py_name) return res
from python import * in_files = [ "read_dummy.f90" ] header_output_file = "test.h" python_output_file = "read_dummy.i" python_name = "read_dummy" header_fh = open(header_output_file, "w") python_fh = open(python_output_file, "w") header_write_header(header_fh) python_write_header(python_fh, python_name) python_write_c_include(python_fh, header_output_file) programs, modules, functs, subts = f90doc.read_files(in_files) for mod, name in modules: print "Module %s (file '%s'):" % (mod.name, name) if len(mod.elements) > 0: print " Elements:" for element in mod.elements: print " Element '%s': type '%s'" % (element.name, element.type) f_type = element.type.lower() header_write_type(header_fh, "%s *%s;\n", f_type, element.name, pointer = "*", stub_format = "// STUB: %s %s\n") #python_write_type(python_fh, "%s *%s;\n", f_type, element.name, pointer = "*", stub_format = "// STUB: %s %s\n") header_write_seperator(header_fh) #python_write_seperator(python_fh) if len(mod.types) > 0: print " Types:" header_write_pre_derived_type(header_fh)