def setup_application(application, source, datapath, apps): print "Configuring application", application, "...", data = tools.get_application_description(source, application, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: write_no_ok(application) # exits dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: write_no_ok(application) # exits modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) link_py_apps(os.path.join(source, "applications", application)) make_doxygen(application, source, all_modules) make_overview(application, source, apps) write_ok( application, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies, datapath), unfound_dependencies)
def setup_application(application, source, datapath, scons): print "Configuring application", application, "...", data= tools.get_application_description(source, application, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: write_no_ok(application, scons) #exits dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: write_no_ok(application, scons) # exits modules= data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules=tools.get_dependent_modules(modules, datapath) link_py(os.path.join(source, "applications", application)) write_ok(application, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies, datapath), unfound_dependencies)
def setup_module(module, source, datapath): sys.stdout.write("Configuring module %s ..." % module) data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print("Required dependency %s not found" % d) write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print("Required module IMP.%s not available" % d) write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) moddir = os.path.join('IMP', '' if module == 'kernel' else module) swig_includes = [os.path.split(x)[1] for x in tools.get_glob( [os.path.join(source, "modules", module, "pyext", "include", "*.i")])] \ + [os.path.join(moddir, os.path.split(x)[1]) for x in tools.get_glob( [os.path.join("include", moddir, "*_macros.h")])] swig_wrapper_includes = [os.path.join(moddir, "internal", os.path.split(x)[1]) for x in tools.get_glob( [os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def setup_one(module, ordered, build_system, swig): info = tools.get_module_info(module, "/") if not info["ok"]: tools.rewrite("src/%s_swig.deps"%module, "") return includepath = get_dep_merged([module], "includepath", ordered) swigpath = get_dep_merged([module], "swigpath", ordered) depf= open("src/%s_swig.deps.in"%module, "w") cmd= [swig, "-MM", "-Iinclude", "-Iswig", "-ignoremissing"]\ + ["-I"+x for x in swigpath] + ["-I"+x for x in includepath]\ + ["swig/IMP_%s.i"%module] ret = subprocess.call(cmd, stdout=depf) del depf if ret != 0: raise OSError("subprocess failed with return code %d: %s" \ % (ret, str(cmd))) lines= open("src/%s_swig.deps.in"%module, "r").readlines() names= [x[:-2].strip() for x in lines[1:]] final_names=[_fix(x, build_system) for x in names] final_list= "\n".join(final_names) tools.rewrite("src/%s_swig.deps"%module, final_list)
def write_module_swig(m, source, contents, datapath, skip_import=False): info = tools.get_module_info(m, datapath) contents.append("""%%include "IMP/%s/%s_config.h" """ % (m, m)) for macro in info["swig_includes"]: contents.append("%%include \"%s\"" % (macro)) if not skip_import: contents.append("%%import \"IMP_%(module)s.i\"" % {"module": m})
def generate_overview_pages(source): name = os.path.join("doxygen", "generated", "cmdline_tools.dox") contents = [] contents.append("/** ") contents.append("\\page cmdline_tools All IMP command line tools") contents.append(""" IMP modules provide a number of command line tools. These are listed below under their parent module:""") for bs, g in tools.get_modules(source): if tools.get_module_info(bs, '')['ok']: p = pickle.load( open(os.path.join("data", "build_info", "IMP_%s.pck" % bs))) if len(p) > 0: contents.append("- IMP::%s" % bs) apps = sorted([[k] + list(v) for k, v in p.iteritems() if v], key=lambda x: x[3]) for app in apps: contents.append(" - [%s](\\ref %s): %s" % (app[0], app[1], app[2])) contents.append(""" See also the [command line tools provided by RMF](http://integrativemodeling.org/rmf/nightly/doc/executables.html).""" ) contents.append("*/") g = tools.DoxFileGenerator() g.write(name, "\n".join(contents))
def setup_one(module, ordered, build_system, swig): info = tools.get_module_info(module, "/") if not info["ok"]: tools.rewrite("src/%s_swig.deps" % module, "", False) return includepath = get_dep_merged([module], "includepath", ordered) swigpath = get_dep_merged([module], "swigpath", ordered) depf = open("src/%s_swig.deps.in" % module, "w") cmd = [swig, "-MM", "-Iinclude", "-Iswig", "-ignoremissing"]\ + ["-I" + x for x in swigpath] + ["-I" + x for x in includepath]\ + ["swig/IMP_%s.i" % module] lines = tools.run_subprocess(cmd).split("\n") names = [] for x in lines: if x.endswith("\\"): x = x[:-1] x = x.strip() if not x.endswith(".h") and not x.endswith(".i") and not x.endswith(".i-in"): continue names.append(x) final_names = [_fix(x, build_system) for x in names] final_list = "\n".join(final_names) tools.rewrite("src/%s_swig.deps" % module, final_list)
def get_all_components(): comps = {} # If RMF is being built as part of IMP, split out its build (rather than # building it as part of IMP.rmf) special_dep_targets = {"RMF": RMFDependency} for dep, cls in special_dep_targets.items(): i = tools.get_dependency_info(dep, "") if i['ok']: comps[dep] = cls(dep) comps[dep].set_dep_modules(comps, [], [], special_dep_targets) modules = tools.get_sorted_order() for m in modules: comps[m] = Module(m) for m in modules: i = tools.get_module_info(m, "") comps[m].set_dep_modules(comps, i['modules'], i['dependencies'], special_dep_targets) source_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '..') all_modules = [x[0] for x in tools.get_modules(source_dir)] add_disabled_components(modules, all_modules, comps, "module") return comps
def setup_one(module, ordered, build_system, swig): info = tools.get_module_info(module, "/") if not info["ok"]: tools.rewrite("src/%s_swig.deps" % module, "", False) return includepath = get_dep_merged([module], "includepath", ordered) swigpath = get_dep_merged([module], "swigpath", ordered) depf = open("src/%s_swig.deps.in" % module, "w") cmd = [swig, "-MM", "-Iinclude", "-Iswig", "-ignoremissing"]\ + ["-I" + x for x in swigpath] + ["-I" + x for x in includepath]\ + ["swig/IMP_%s.i" % module] lines = tools.run_subprocess(cmd).split("\n") names = [] for x in lines: if x.endswith("\\"): x = x[:-1] x = x.strip() if not x.endswith(".h") and not x.endswith(".i") and not x.endswith( ".i-in"): continue names.append(x) final_names = [_fix(x, build_system) for x in names] final_list = "\n".join(final_names) tools.rewrite("src/%s_swig.deps" % module, final_list)
def get_all_components(): comps = {} # If RMF is being built as part of IMP, split out its build (rather than # building it as part of IMP.rmf) special_dep_targets = {"RMF": RMFDependency} for dep, cls in special_dep_targets.items(): i = tools.get_dependency_info(dep, "") if i['ok'] and internal_dep(dep): comps[dep] = cls(dep) comps[dep].set_dep_modules(comps, [], [], special_dep_targets) modules = tools.get_sorted_order() apps = tools.get_all_configured_applications() for m in modules: comps[m] = Module(m) for a in apps: comps[a] = Application(a) for m in modules: i = tools.get_module_info(m, "") comps[m].set_dep_modules(comps, i['modules'], i['dependencies'], special_dep_targets) for a in apps: i = tools.get_application_info(a, "") comps[a].set_dep_modules(comps, i['modules'], i['dependencies'], special_dep_targets) source_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '..') all_modules= [x[0] for x in tools.get_modules(source_dir)] all_apps= [x[0] for x in tools.get_applications(source_dir)] add_disabled_components(modules, all_modules, comps, "module") add_disabled_components(apps, all_apps, comps, "application") return comps
def setup_module(module, source, datapath): sys.stdout.write("Configuring module %s ..." % module) data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print("Required dependency %s not found" % d) write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print("Required module IMP.%s not available" % d) write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) moddir = os.path.join('IMP', '' if module == 'kernel' else module) swig_includes = [os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + [os.path.join(moddir, os.path.split(x)[1]) for x in tools.get_glob([os.path.join("include", moddir, "*_macros.h")])] swig_wrapper_includes = [os.path.join(moddir, "internal", os.path.split(x)[1]) for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies( all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def setup_module(module, source, datapath): print "Configuring module", module, "...", data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print d, "not found" write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print "IMP." + d, "not found" write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) swig_includes = [os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + ["IMP/" + module + "/" + os.path.split(x)[1] for x in tools.get_glob([os.path.join("include", "IMP", module, "*_macros.h")])] swig_wrapper_includes = ["IMP/" + module + "/internal/" + os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies( all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def write_module_cpp(m, contents, datapath): info = tools.get_module_info(m, datapath) contents.append("""%%{ #include "IMP/%(module)s.h" #include "IMP/%(module)s/%(module)s_config.h" %%} """ % {"module": m}) for macro in info["swig_wrapper_includes"]: contents.append("""%%{ #include <%s> %%}""" % (macro))
def setup_module(module, source, datapath): print "Configuring module", module, "...", data= tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print d, "not found" write_no_ok(module) return False dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print "IMP."+d, "not found" write_no_ok(module) return False modules= data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules=tools.get_dependent_modules(modules, datapath) swig_includes=[os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + ["IMP/"+module+"/"+os.path.split(x)[1] for x in tools.get_glob([os.path.join("include", "IMP", module, "*_macros.h")])] swig_wrapper_includes= ["IMP/"+module+"/internal/"+os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module+"_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies,datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True
def main(): (options, args) = parser.parse_args() info = tools.get_module_info(options.name, "/") if not info["ok"]: tools.rewrite("src/%s_swig.deps"%options.name, "") return cmd = [options.swig, '-MM', '-Iinclude', '-Iswig', '-ignoremissing'] \ + ["-I"+x for x in tools.split(options.swigpath)] \ + ["-I"+x for x in tools.split(options.includepath)] \ + ["swig/IMP_%s.i" % options.name] outfile = open("src/%s_swig.deps.in"%options.name, "w") ret = subprocess.call(cmd, stdout=outfile) outfile.close() if ret != 0: raise OSError("subprocess failed with return code %d: %s" \ % (ret, " ".join(cmd))) lines= open("src/%s_swig.deps.in"%options.name, "r").readlines() names= [x[:-2].strip() for x in lines[1:]] final_names=[_fix(x, options.build_system) for x in names] final_list= "\n".join(final_names) tools.rewrite("src/%s_swig.deps"%options.name, final_list)
def generate_overview_pages(source): name = os.path.join("doxygen", "generated", "cmdline_tools.dox") contents = [] contents.append("/** ") contents.append("\\page cmdline_tools All IMP command line tools") contents.append(""" IMP modules provide a number of command line tools. These are listed below under their parent module:""") for bs, g in tools.get_modules(source): if tools.get_module_info(bs, '')['ok']: p = pickle.load(open(os.path.join("data", "build_info", "IMP_%s.pck" % bs))) if len(p) > 0: contents.append("- IMP::%s" % bs) apps = sorted([[k]+list(v) for k,v in p.iteritems() if v], key=lambda x:x[3]) for app in apps: contents.append(" - [%s](\\ref %s): %s" % (app[0], app[1], app[2])) contents.append(""" See also the [command line tools provided by RMF](http://integrativemodeling.org/rmf/nightly/doc/executables.html).""") contents.append("*/") tools.rewrite(name, "\n".join(contents))
def make_header(options): dir = os.path.join("include", "IMP", options.name) file = os.path.join(dir, "%s_config.h" % options.name) header_template = open( os.path.join(options.source, "tools", "build", "config_templates", "header.h"), "r").read() try: os.makedirs(dir) except: # exists pass data = {} data["name"] = options.name data["filename"] = "IMP/%s/%s_config.h" % (options.name, options.name) data["cppprefix"] = "IMP%s" % options.name.upper().replace("_", "") if data["name"] != "base": data["showable"] = """#if !defined(IMP_DOXYGEN) && !defined(SWIG) #include <IMP/base/Showable.h> #include <IMP/base/hash.h> namespace IMP { namespace %(name)s { using ::IMP::base::Showable; using ::IMP::base::operator<<; using ::IMP::base::hash_value; } } // namespace namespace IMP { namespace %(name)s { namespace internal { using ::IMP::base::Showable; using ::IMP::base::operator<<; using ::IMP::base::hash_value; } } } // namespace #endif // !defined(SWIG) && !defined(IMP_DOXYGEN) """ % data else: data["showable"] = "" cppdefines = [] if options.defines != "": for define in tools.split(options.defines): parts = define.split("=") if len(parts) == 2: cppdefines.append("#define %s %s" % (parts[0], parts[1])) else: cppdefines.append("#define %s" % parts[0]) d = { 'required_modules': "", 'lib_only_required_modules': "", 'required_dependencies': "", 'optional_dependencies': "" } exec( open( os.path.join(options.source, "modules", data["name"], "dependencies.py"), "r").read(), d) info = tools.get_module_info(data["name"], options.datapath) optional_modules = [ x for x in info["modules"] if x not in tools.split(d['required_modules']) and x != "" ] unfound_modules = [x for x in info["unfound_modules"] if x != ""] optional_dependencies = [ x for x in info["dependencies"] if x not in tools.split(d['required_dependencies']) and x != "" ] unfound_dependencies = [x for x in info["unfound_dependencies"] if x != ""] add_list_to_defines(cppdefines, data, "USE", 1, ["imp_" + x for x in optional_modules]) add_list_to_defines(cppdefines, data, "NO", 0, ["imp_" + x for x in unfound_modules]) add_list_to_defines(cppdefines, data, "USE", 1, optional_dependencies) add_list_to_defines(cppdefines, data, "NO", 0, info["unfound_dependencies"]) data["cppdefines"] = "\n".join(cppdefines) tools.rewrite(file, header_template % data)
def build_wrapper(module, module_path, source, sorted, info, target, datapath): info = tools.get_module_info(module, datapath) if not info["ok"]: return contents = [] swig_module_name = "IMP" if module == 'kernel' else "IMP." + module contents.append("""%%module(directors="1", allprotected="1") "%s" %%feature("autodoc", 1); // Warning 314: 'lambda' is a python keyword, renaming to '_lambda' %%warnfilter(321,302,314); %%{ #include <boost/version.hpp> #if BOOST_VERSION > 103600 #if BOOST_VERSION > 103800 #include <boost/exception/all.hpp> #else #include <boost/exception.hpp> #endif #endif #include <boost/type_traits/is_convertible.hpp> #include <boost/utility/enable_if.hpp> #include <exception> #ifdef __cplusplus extern "C" #endif // suppress warning SWIGEXPORT #if PY_VERSION_HEX >= 0x03000000 PyObject* #else void #endif SWIG_init(); %%} """ % swig_module_name) # some of the typemap code ends up before this is swig sees the # typemaps first all_deps = [x for x in tools.get_dependent_modules( [module], datapath) if x != module] for m in reversed(all_deps): write_module_cpp(m, contents, datapath) write_module_cpp(module, contents, datapath) contents.append(""" %implicitconv; %include "std_vector.i" %include "std_string.i" %include "std_pair.i" %pythoncode %{ _value_types=[] _object_types=[] _raii_types=[] _plural_types=[] %} %include "typemaps.i" #ifdef NDEBUG #error "The python wrappers must not be built with NDEBUG" #endif """) for m in reversed(all_deps): write_module_swig(m, source, contents, datapath) write_module_swig(module, source, contents, datapath, True) contents.append("%%include \"IMP_%s.impl.i\"" % module) #contents.append(open(os.path.join(module_path, "pyext", "swig.i-in"), "r").read()) contents.append(""" namespace IMP { %s const std::string get_module_version(); std::string get_example_path(std::string fname); std::string get_data_path(std::string fname); %s } """ % ('' if module == 'kernel' else 'namespace %s {' % module, '' if module == 'kernel' else '}')) contents.append("""%pythoncode %{ from . import _version_check _version_check.check_version(get_module_version()) __version__ = get_module_version() %} """) g = tools.SWIGFileGenerator() g.write(target, "\n".join(contents))
def build_wrapper(module, module_path, source, sorted, info, target, datapath): info = tools.get_module_info(module, datapath) if not info["ok"]: return contents = [] swig_module_name = "IMP." + module contents.append("""%%module(directors="1", allprotected="1") "%s" %%feature("autodoc", 1); // Warning 314: 'lambda' is a python keyword, renaming to '_lambda' %%warnfilter(321,302,314); %%inline %%{ namespace IMP { namespace kernel { } using namespace kernel; } %%} %%{ #include <boost/version.hpp> #if BOOST_VERSION > 103600 #if BOOST_VERSION > 103800 #include <boost/exception/all.hpp> #else #include <boost/exception.hpp> #endif #endif #include <boost/type_traits/is_convertible.hpp> #include <boost/utility/enable_if.hpp> #include <exception> #ifdef __cplusplus extern "C" #endif // suppress warning SWIGEXPORT #if PY_VERSION_HEX >= 0x03000000 PyObject* #else void #endif SWIG_init(); %%} """ % swig_module_name) # some of the typemap code ends up before this is swig sees the # typemaps first all_deps = [ x for x in tools.get_dependent_modules([module], datapath) if x != module ] for m in reversed(all_deps): write_module_cpp(m, contents, datapath) write_module_cpp(module, contents, datapath) contents.append(""" %implicitconv; %include "std_vector.i" %include "std_string.i" %include "std_pair.i" %pythoncode %{ _value_types=[] _object_types=[] _raii_types=[] _plural_types=[] %} %include "typemaps.i" #ifdef NDEBUG #error "The python wrappers must not be built with NDEBUG" #endif """) for m in reversed(all_deps): write_module_swig(m, source, contents, datapath) write_module_swig(module, source, contents, datapath, True) contents.append("%%include \"IMP_%s.impl.i\"" % module) #contents.append(open(os.path.join(module_path, "pyext", "swig.i-in"), "r").read()) contents.append(""" namespace IMP { namespace %s { const std::string get_module_version(); std::string get_example_path(std::string fname); std::string get_data_path(std::string fname); } } """ % module) contents.append("""%pythoncode %{ import _version_check _version_check.check_version(get_module_version()) %} """) tools.rewrite(target, "\n".join(contents))
def make_header(options): dir = os.path.join("include", "IMP", options.name) file = os.path.join(dir, "%s_config.h" % options.name) header_template = open( os.path.join( options.source, "tools", "build", "config_templates", "header.h"), "r").read( ) try: os.makedirs(dir) except: # exists pass data = {} data["name"] = options.name data["filename"] = "IMP/%s/%s_config.h" % (options.name, options.name) data["cppprefix"] = "IMP%s" % options.name.upper().replace("_", "") if data["name"] != "base": data["showable"] = """#if !defined(IMP_DOXYGEN) && !defined(SWIG) #include <IMP/base/Showable.h> #include <IMP/base/hash.h> namespace IMP { namespace %(name)s { using ::IMP::base::Showable; using ::IMP::base::operator<<; using ::IMP::base::hash_value; } } // namespace namespace IMP { namespace %(name)s { namespace internal { using ::IMP::base::Showable; using ::IMP::base::operator<<; using ::IMP::base::hash_value; } } } // namespace #endif // !defined(SWIG) && !defined(IMP_DOXYGEN) """ % data else: data["showable"] = "" cppdefines = [] if options.defines != "": for define in tools.split(options.defines): parts = define.split("=") if len(parts) == 2: cppdefines.append("#define %s %s" % (parts[0], parts[1])) else: cppdefines.append("#define %s" % parts[0]) d = {'required_modules': "", 'lib_only_required_modules': "", 'required_dependencies': "", 'optional_dependencies': ""} exec(open(os.path.join(options.source, "modules", data["name"], "dependencies.py"), "r").read(), d) info = tools.get_module_info(data["name"], options.datapath) optional_modules = [ x for x in info[ "modules"] if x not in tools.split( d['required_modules']) and x != ""] unfound_modules = [x for x in info["unfound_modules"] if x != ""] optional_dependencies = [ x for x in info[ "dependencies"] if x not in tools.split( d['required_dependencies']) and x != ""] unfound_dependencies = [x for x in info["unfound_dependencies"] if x != ""] add_list_to_defines(cppdefines, data, "USE", 1, ["imp_" + x for x in optional_modules]) add_list_to_defines(cppdefines, data, "NO", 0, ["imp_" + x for x in unfound_modules]) add_list_to_defines(cppdefines, data, "USE", 1, optional_dependencies) add_list_to_defines( cppdefines, data, "NO", 0, info["unfound_dependencies"]) data["cppdefines"] = "\n".join(cppdefines) tools.rewrite(file, header_template % data)
def build_wrapper(module, module_path, source, sorted, info, target, datapath): info = tools.get_module_info(module, datapath) if not info["ok"]: return contents=[] swig_module_name="IMP."+module contents.append("""%%module(directors="1", allprotected="1") "%s" %%feature("autodoc", 1); // turn off the warning as it mostly triggers on methods (and lots of them) %%warnfilter(321); %%inline %%{ namespace IMP { namespace kernel { } using namespace kernel; } %%} %%{ #include <boost/version.hpp> #if BOOST_VERSION > 103600 #if BOOST_VERSION > 103800 #include <boost/exception/all.hpp> #else #include <boost/exception.hpp> #endif #endif #include <boost/type_traits/is_convertible.hpp> #include <boost/utility/enable_if.hpp> #include <exception> %%} """%swig_module_name) # some of the typemap code ends up before this is swig sees the typemaps first all_deps = [x for x in tools.get_dependent_modules([module], datapath) if x != module] for m in reversed(all_deps): write_module_cpp(m, contents, datapath) write_module_cpp(module, contents, datapath) contents.append(""" %implicitconv; %include "std_vector.i" %include "std_string.i" %include "std_pair.i" %pythoncode %{ _value_types=[] _object_types=[] _raii_types=[] _plural_types=[] %} %include "typemaps.i" #ifdef NDEBUG #error "The python wrappers must not be built with NDEBUG" #endif """) for m in reversed(all_deps): write_module_swig(m, source, contents, datapath) write_module_swig(module, source, contents, datapath, True) contents.append("%%include \"IMP_%s.impl.i\""%module) #contents.append(open(os.path.join(module_path, "pyext", "swig.i-in"), "r").read()) contents.append(""" namespace IMP { namespace %s { const std::string get_module_version(); std::string get_example_path(std::string fname); std::string get_data_path(std::string fname); } } """%module) contents.append("""%pythoncode %{ import _version_check _version_check.check_version(get_module_version()) %} """) tools.rewrite(target, "\n".join(contents))