diff --git a/scripts/ezfio_interface/ei_handler.py b/scripts/ezfio_interface/ei_handler.py index 6d18d071..4667478f 100755 --- a/scripts/ezfio_interface/ei_handler.py +++ b/scripts/ezfio_interface/ei_handler.py @@ -62,6 +62,9 @@ import ConfigParser from collections import defaultdict from collections import namedtuple + +from qp_utils import cache + Type = namedtuple('Type', 'fancy ocaml fortran') @@ -78,6 +81,7 @@ def is_bool(str_): raise TypeError +@cache def get_type_dict(): """ This function makes the correspondance between the type of value read in @@ -89,17 +93,7 @@ def get_type_dict(): # ~#~#~#~#~ # # P i c l e # # ~#~#~#~#~ # - - import cPickle as pickle - - from os import listdir - qpackage_root = os.environ['QPACKAGE_ROOT'] - fancy_type_pickle = qpackage_root + "/scripts/ezfio_interface/fancy_type.p" - - if fancy_type_pickle in listdir(os.getcwd()): - fancy_type = pickle.load(open(fancy_type_pickle, "rb")) - return fancy_type # ~#~#~#~ # # I n i t # @@ -148,9 +142,7 @@ def get_type_dict(): b = r.find('let untouched = "') e = r.find(';;', b) - l_un = [ - i for i in r[ - b:e].splitlines() if i.strip().startswith("module")] + l_un = [i for i in r[b:e].splitlines() if i.strip().startswith("module")] # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # # q p _ t y p e s _ g e n e r a t e # @@ -174,9 +166,6 @@ def get_type_dict(): # ~#~#~#~#~#~#~#~ # # F i n a l i z e # # ~#~#~#~#~#~#~#~ # - - pickle.dump(dict(fancy_type), open(fancy_type_pickle, "wb")) - return dict(fancy_type) diff --git a/scripts/module/module_handler.py b/scripts/module/module_handler.py index 3bc1d0e4..a35dbe2c 100755 --- a/scripts/module/module_handler.py +++ b/scripts/module/module_handler.py @@ -24,24 +24,7 @@ from docopt import docopt import os import sys import os.path -from functools import wraps - - -def cache(func): - """ - A decorator for lazy evaluation off true function - """ - saved = {} - - @wraps(func) - def newfunc(*args): - if args in saved: - return saved[args] - - result = func(*args) - saved[args] = result - return result - return newfunc +from qp_utils import cache @cache diff --git a/scripts/qp_utils.py b/scripts/qp_utils.py new file mode 100644 index 00000000..9be4ea2c --- /dev/null +++ b/scripts/qp_utils.py @@ -0,0 +1,17 @@ +from functools import wraps + +def cache(func): + """ + A decorator for lazy evaluation off true function + """ + saved = {} + + @wraps(func) + def newfunc(*args): + if args in saved: + return saved[args] + + result = func(*args) + saved[args] = result + return result + return newfunc diff --git a/src/Makefile b/src/Makefile index 93b5234f..1bb5aa87 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,10 +16,6 @@ default: ezfio veryclean: $(QPACKAGE_ROOT)/scripts/module/clean_modules.sh $(ALL_MODULES) - # Define the dict [type in EZFIO.cfg] = ocaml type , f90 type - # If you change the qptypes_generator.ml, you need to rm this - # For simplicity add this to the veryclean rule - rm -f $(QPACKAGE_ROOT)/scripts/ezfio_interface/fancy_type.p $(ALL_MODULES): ezfio $(QPACKAGE_ROOT)/scripts/module/build_modules.sh $@