diff --git a/scripts/compilation/create_ninja_build.py b/scripts/compilation/create_ninja_build.py index ce39a322..249c76ad 100755 --- a/scripts/compilation/create_ninja_build.py +++ b/scripts/compilation/create_ninja_build.py @@ -41,11 +41,25 @@ def ninja_makefile_depend_build(l_all_needed_molule, path_module): return l_string - +import glob # _ __ _ ___ _ _ # |_ / |_ | / \ _ _|_ _ # |_ /_ | _|_ \_/ o (_ | (_| # _| + + +def get_module_with_ezfio_cfg(): + from os import listdir + from os.path import isfile, join + qp_src = qpackage_root_src + + return [join(qp_src, m) for m in listdir(qp_src) if isfile(join(qp_src, m, "EZFIO.cfg")) ] + + +def get_ezfio_config(): + return glob.glob("{0}/*/*.ezfio_config".format(qpackage_root_src)) + + def get_l_ezfio_irp(l_all_needed_molule, path_module): l_module_abs = [join(qpackage_root_src, m) for m in l_all_needed_molule] @@ -66,24 +80,35 @@ def get_l_ezfio_irp(l_all_needed_molule, path_module): def ninja_ezfio_cfg_rule(): # Rule l_string = ["rule build_ezfio_interface"] - l_string += [ - " command = cd $sub_module ; ei_handler.py ; cd -"] + l_string += [" command = ei_handler.py --path_module $sub_module --irpf90"] l_string += [""] return l_string -def ninja_ezfio_cfg_build(): +def ninja_ezfio_interface_config_rule(): + # Rule + l_string = ["rule build_ezfio_interface_config"] + l_string += [" command = ei_handler.py --path_module $sub_module --ezfio_config"] + l_string += [""] + + return l_string + + +def ninja_ezfio_config_rule(): + # Rule + l_string = ["rule build_ezfio_config"] + l_string += [" command = cp $in $out"] + l_string += [""] + + return l_string + + +def ninja_ezfio_cfg_build(l_module_with_ezfio_cfg): # Build l_string = [] - from os import listdir - from os.path import isfile, join - qp_src = qpackage_root_src - - l = [join(qp_src, m) for m in listdir(qp_src) if isfile(join(qp_src, m, "EZFIO.cfg")) ] - - for m in l: + for m in l_module_with_ezfio_cfg: ez_interface = join(m, "ezfio_interface.irp.f") ez_cfg = join(m, "EZFIO.cfg") @@ -95,6 +120,55 @@ def ninja_ezfio_cfg_build(): return l_string +def ninja_ezfio_config_build(l_module_with_ezfio_cfg,l_ezfio_config): + # Build + l_string = [] + l_file_create = [] + + ezfio_folder = join(qpackage_root, "EZFIO/config") + + for m in l_module_with_ezfio_cfg: + file_source = join(m, "EZFIO.cfg") + name = "{0}.ezfio_interface_config".format(os.path.split(m)[1].lower()) + file_create = join(ezfio_folder, name) + + l_file_create.append(file_create) + l_string += ["build {0}: build_ezfio_interface_config {1}".format(file_create, file_source)] + l_string += [" sub_module = {0}".format(m)] + l_string += [""] + + for m in l_ezfio_config: + file_source = m + name = os.path.split(m)[1].lower() + file_create = join(ezfio_folder, name) + + l_file_create.append(file_create) + l_string += ["build {0}: build_ezfio_config {1}".format(file_create, file_source)] + l_string += [""] + + return l_string, l_file_create + + +def ninja_ezfio_rule(): + # Rule + l_string = ["rule build_ezfio"] + ezfio_folder = join(qpackage_root, "EZFIO") + l_string += [" command = cd {0}; make ; cd -".format(ezfio_folder)] + + return l_string + + +def ninja_ezfio_build(l_file_create): + # Rule + ezfio_lib = join(qpackage_root, "EZFIO", "lib", "libezfio.a") + str_ = " ".join(l_file_create) + + l_string = ["build {0}: build_ezfio {1}".format(ezfio_lib, str_)] + l_string += [""] + + return l_string + + # __ # (_ ._ _ | o ._ | # __) \/ | | | | | | | |< @@ -137,7 +211,7 @@ def ninja_symlink_build(l_source, l_destination): # | def ninja_irpf90_make_rule(): # Rule - l_string = ["pool irp_pool"] + l_string = ["pool irp_pool"] l_string += [" depth = 1"] l_string += [""] @@ -187,8 +261,9 @@ def get_program(path_module): import subprocess try: + fnull = open(os.devnull, 'w') cmd = 'grep -l "program" {0}/*.irp.f'.format(path_module.abs) - p = subprocess.check_output([cmd], shell=True) + p = subprocess.check_output([cmd], shell=True, stderr=fnull) except subprocess.CalledProcessError: return [] else: @@ -209,13 +284,15 @@ def ninja_binary_build(l_bin, path_module): # Build irpf90mk_path = join(path_module.abs, "irpf90.make") + ezfio_lib = join(qpackage_root, "EZFIO", "lib", "libezfio.a") l_abs_bin = [join(path_module.abs, binary) for binary in l_bin] l_string = [] for path, abs_path in zip(l_bin, l_abs_bin): - l_string += ["build {0}: build_binary {1}".format(abs_path, - irpf90mk_path)] + l_string += ["build {0}: build_binary {1} {2}".format(abs_path, + ezfio_lib, + irpf90mk_path)] l_string += [" module = {0}".format(path_module.abs)] l_string += [" binary = {0}".format(path)] @@ -250,6 +327,9 @@ if __name__ == "__main__": l_string += ninja_symlink_rule() l_string += ninja_irpf90_make_rule() l_string += ninja_binary_rule() + l_string += ninja_ezfio_interface_config_rule() + l_string += ninja_ezfio_config_rule() + l_string += ninja_ezfio_rule() from collections import namedtuple @@ -286,7 +366,18 @@ if __name__ == "__main__": l_binary = get_program(path_module) l_string += ninja_binary_build(l_binary, path_module) - l_string += ninja_ezfio_cfg_build() + l_module = get_module_with_ezfio_cfg() + + l_string += ninja_ezfio_cfg_build(l_module) + + l_ezfio_config = get_ezfio_config() + + l_string_dump, l_file_create = ninja_ezfio_config_build(l_module_with_ezfio_cfg=l_module, + l_ezfio_config=l_ezfio_config) + l_string += l_string_dump l_string += ninja_all_binary_build(l_module_to_compile) + + l_string += ninja_ezfio_build(l_file_create) + print "\n".join(l_string) diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 8b28f41f..659dd9f5 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -5,7 +5,11 @@ Welcom the ei_handler. We will create all the ezfio related stuff from a EZFIO.cfg file. Usage: - ei_handler.py [--recursif] [--irpf90] [--ezfio_config] [--ocaml] [--ezfio_default] + ei_handler.py [--path_module=] + [--irpf90] + [--ezfio_config] + [--ocaml] + [--ezfio_default] ei_handler.py ocaml_global By default all the option are executed. @@ -67,7 +71,7 @@ from cache import cache from os import listdir -from os.path import isdir, join, exists, islink +from os.path import isdir, join, exists Type = namedtuple('Type', 'fancy ocaml fortran') @@ -176,12 +180,12 @@ def get_type_dict(): type_dict = get_type_dict() -def get_dict_config_file(config_file_path, module_lower): +def get_dict_config_file(module_obj): """ Input: - config_file_path is the config file path + module_obj.path is the config file (for example FULL_PATH/EZFIO.cfg) - module_lower is the MODULE name lowered + module_obj.lower is the MODULE name lowered (Ex fullci) Return a dict d[provider_name] = {type, @@ -208,7 +212,6 @@ def get_dict_config_file(config_file_path, module_lower): # ~#~#~#~ # # I n i t # # ~#~#~#~ # - d = defaultdict(dict) l_info_required = ["doc", "interface"] l_info_optional = ["ezfio_dir", "ezfio_name", "size"] @@ -218,14 +221,14 @@ def get_dict_config_file(config_file_path, module_lower): # ~#~#~#~#~#~#~#~#~#~#~ # config_file = ConfigParser.ConfigParser() - config_file.readfp(open(config_file_path)) + config_file.readfp(open(module_obj.path)) # ~#~#~#~#~#~#~#~#~ # # F i l l _ d i c t # # ~#~#~#~#~#~#~#~#~ # def error(o, p, c): - "o option ; p provider_name ;c config_file_path" + "o option ; p provider_name ;c module_obj.path" print "You need a {0} for {1} in {2}".format(o, p, c) for section in config_file.sections(): @@ -234,7 +237,7 @@ def get_dict_config_file(config_file_path, module_lower): # Create the dictionary who containt the value per default d_default = {"ezfio_name": pvd, - "ezfio_dir": module_lower, + "ezfio_dir": module_obj.lower, "size": "1"} # Check if type if avalaible @@ -251,7 +254,7 @@ def get_dict_config_file(config_file_path, module_lower): try: d[pvd][option] = config_file.get(section, option) except ConfigParser.NoOptionError: - error(option, pvd, config_file_path) + error(option, pvd, module_obj.path) sys.exit(1) # Fill the dict with OPTIONAL information @@ -267,7 +270,7 @@ def get_dict_config_file(config_file_path, module_lower): try: default_raw = config_file.get(section, "default") except ConfigParser.NoOptionError: - error("default", pvd, config_file_path) + error("default", pvd, module_obj.path) sys.exit(1) try: @@ -322,14 +325,6 @@ def save_ezfio_provider(path_head, dict_code_provider): path = "{0}/ezfio_interface.irp.f".format(path_head) - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - l_output = ["! DO NOT MODIFY BY HAND", "! Created by $QPACKAGE_ROOT/scripts/ezfio_interface.py", "! from file {0}/EZFIO.cfg".format(path_head), @@ -339,9 +334,8 @@ def save_ezfio_provider(path_head, dict_code_provider): output = "\n".join(l_output) - if output != old_output: - with open(path, "w+") as f: - f.write(output) + with open(path, "w+") as f: + f.write(output) def create_ezfio_stuff(dict_ezfio_cfg, config_or_default="config"): @@ -462,17 +456,8 @@ def save_ezfio_config(module_lower, str_ezfio_config): path = "{0}/config/{1}.ezfio_interface_config".format(root_ezfio, module_lower) - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - - if str_ezfio_config != old_output: - with open(path, "w+") as f: - f.write(str_ezfio_config) + with open(path, "w+") as f: + f.write(str_ezfio_config) def create_ezfio_default(dict_ezfio_cfg): @@ -490,18 +475,8 @@ def save_ezfio_default(module_lower, str_ezfio_default): os.environ['QPACKAGE_ROOT']) path = "{0}/{1}.ezfio_interface_default".format(root_ezfio_default, module_lower) - - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - - if str_ezfio_default != old_output: - with open(path, "w+") as f: - f.write(str_ezfio_default) + with open(path, "w+") as f: + f.write(str_ezfio_default) def create_ocaml_input(dict_ezfio_cfg, module_lower): @@ -607,17 +582,8 @@ def save_ocaml_input(module_lower, str_ocaml_input): path = "{0}/ocaml/Input_{1}.ml".format(os.environ['QPACKAGE_ROOT'], module_lower) - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - - if str_ocaml_input != old_output: - with open(path, "w+") as f: - f.write(str_ocaml_input) + with open(path, "w+") as f: + f.write(str_ocaml_input) def get_l_module_lower(): @@ -705,14 +671,6 @@ def save_ocaml_input_auto(str_ocaml_input_global): path = "{0}/ocaml/Input_auto_generated.ml".format(os.environ['QPACKAGE_ROOT']) - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - if str_ocaml_input_global != old_output: with open(path, "w+") as f: f.write(str_ocaml_input_global) @@ -726,14 +684,6 @@ def save_ocaml_qp_edit(str_ocaml_qp_edit): path = "{0}/ocaml/qp_edit.ml".format(os.environ['QPACKAGE_ROOT']) - try: - f = open(path, "r") - except IOError: - old_output = "" - else: - old_output = f.read() - f.close() - if str_ocaml_qp_edit != old_output: with open(path, "w+") as f: f.write(str_ocaml_qp_edit) @@ -809,26 +759,18 @@ if __name__ == "__main__": # G e t _ m o d u l e _ d i r # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # - path_dirname = os.getcwd() - root_module = [i for i in path_dirname.split("/") if i][-1] + if arguments["--path_module"]: + path_dirname = os.path.abspath(arguments["--path_module"]) + else: + path_dirname = os.getcwd() + root_module = os.path.split(path_dirname)[1] + + l_module = [root_module] # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # G e t _ l _ d i c t _ e z f i o _ c f g # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # - if arguments["--recursif"]: - def true_link(f): - return islink(join(path_dirname, f)) - - l_symlink = [f for f in listdir(path_dirname) if true_link(f)] - else: - l_symlink = [] - - l_module = [root_module] + l_symlink - - def check_ezfio(f): - return exists() - qpackage_root_src = join(os.environ['QPACKAGE_ROOT'], "src") l_module_with_ezfio = [] @@ -840,12 +782,12 @@ if __name__ == "__main__": if exists(path): l_module_with_ezfio.append(Module(path, f.lower())) - l_dict_ezfio_cfg = [(get_dict_config_file(m.path, m.lower), m) for m in l_module_with_ezfio] + l_dict_ezfio_cfg = [(m, get_dict_config_file(m)) for m in l_module_with_ezfio] # _ # / _ _| _ _ _ ._ _ ._ _. _|_ o _ ._ # \_ (_) (_| (/_ (_| (/_ | | (/_ | (_| |_ | (_) | | # _| - for (dict_ezfio_cfg, m) in l_dict_ezfio_cfg: + for (m, dict_ezfio_cfg) in l_dict_ezfio_cfg: code_generation(arguments, dict_ezfio_cfg, m) diff --git a/src/q_package.ezfio_config b/src/Integrals_Bielec/q_package.ezfio_config similarity index 100% rename from src/q_package.ezfio_config rename to src/Integrals_Bielec/q_package.ezfio_config diff --git a/src/Integrals_Monoelec/var_pt2_ratio.irp.f b/src/Integrals_Monoelec/var_pt2_ratio.irp.f new file mode 100644 index 00000000..e69de29b