def __get_modules_list(self,styles=None, p=None,l=None) : if styles is None : styles = ['sys','usr'] if isinstance(styles, str) : styles = [styles] if l is None : l = [] if p is None : p = self.get_toolboxes_path() for name in os.listdir(p) : p1 = os.path.join(p,name) if os.path.isdir(p1) : filename = os.path.join(p1,'py_data.py') if exist(filename) : s = '\n'.join(read(filename)) exec(s) prefix = datas.get('prefix',[]) if ((datas.get('style','usr') in styles) or ((datas.get('has_submodules',False)) )): if (datas.get('has_submodules',False)) : p2 = p for pr in prefix : p2=os.path.join(p2,pr) self.__get_modules_list(styles,p2,l) else : h = '' for pr in prefix : h +=pr+'.' h += name l.append(h) return l
def __init__(self, fname,mode,name,d) : self.debug= True self.name = name self.mode = mode self.base = d['base'] self.root = d['binarybase'] self.module = d['module'] self.fname = fname self.fnamedirect = d['fnamedirect'] self.modeloc = "simd/common" if self.mode =="simd" else self.mode if not exist(fname) : pprint('Warning') pprint('File: '+ fname) pprint('does not exist') self.textorig = read(fname) if d['save'] : pprint("saving to: "+fname+'_') write(fname+'_',self.textorig,False) if d['show_source'] : pprint('Original file for '+self.name) pprint('=orig===============================================') pprint(self.textorig) pprint('===============================================orig=') self.ids = {} self.includes = [] self.uncommented = self.suppress_comments_and_includes() self.anomaly= False self.anomaly_msg='' self.modestr = "simd/" if (self.mode == "generic/" and d['add'] != "complex/") else self.mode self.modestr = "" if (d['add'] == "complex/") else self.modestr self.unspecif = self.unspecified_present() self.write = d["write"];
def modify_unit(self,tryonly='tryonly') : """ text is always modified from old one""" style = self.get_tb_style() tb_name = self.get_tb_name() fct_name = self.get_fct_name() print("modifying fct for %s with style %s"% (self.get_fct_name(),style)) new = self.get_fct_unit_path('scalar') old = new+'.old' if not exist(new) : print("%s does not exist" % new) return if not exist(old) : self.duplicate_unit() oldtxt = read(old) newtxt = self.replacements(oldtxt,'\t',' ') pattern = ('nt2::functors' if style =='sys' else 'nt2::'+tb_name) rep = ('nt2::tag' if style =='sys' else pattern+'::tag') pattern = pattern+'::'+fct_name+'_' rep = rep + '::'+fct_name+'_' newtxt = self.replacements(newtxt,pattern,rep) ## newtxt = self.replacements(oldtxt,'\sNT2_CALL_RETURN_TYPE\(',' NT2_RETURN_TYPE(') if tryonly != 'tryonly' : write(new,newtxt,False) else : print("===============") PrettyPrinter().pprint(newtxt) print("===============")
def regress_benches_and_units(self,option="update") : """ the files to be modified are: ./bench/scalar/CMakeLists.txt ./bench/simd/CMakeLists.txt ./unit/scalar/CMakeLists.txt ./unit/simd/CMakeLists.txt ./bench/CMakeLists.txt and ./unit/CMakeLists.txt, are not to be modified after creation TO DO add action for "create" """ name = self.get_fct_name() tb_name = self.get_tb_name() l = [os.path.join("bench","scalar"), os.path.join("bench","simd"), os.path.join("unit","scalar"), os.path.join("unit","simd")] for p in l : path = os.path.join(self.get_tb_path(),os.path.join(p,'CMakeLists.txt')) txt_orig = read(path) txt = " %s.cpp"%fct_name done, new_txt = self.remove_line(txt_orig,txt) if not done : print("Warning : line\n %s\nws not found in CMakelist.txt file"%txt ) else : self.finalize(path,new_txt,"update")
def __read_ret_arity(self) : p = self.get_fct_impl_path('scalar') if exist(p) : s = '/n'.join(read(p)) return '2' if re.search('boost::fusion',s) else '0' else : return '0'
def modify_fct(self,tryonly='tryonly') : """ text is always modified from old one""" style = self.get_tb_style() fct_name = self.get_fct_name() print("modifying fct for %s with style %s"% (fct_name,style)) new = self.get_fct_impl_path('scalar') old = new+'.old' if self.manual(new) : print("file \n %s\nwas manually modified: skipping" % new) return if not exist(old) : self.duplicate_fct() oldtxt = read(old) (beg,end)=Nt2_fct_internals.get_header_indices(oldtxt) newtxt=oldtxt[beg:end] newtxt += Nt2_fct_internals.get_extern_C(oldtxt) calls = Nt2_fct_internals.get_calls(oldtxt) for c in calls.keys() : newtxt += [l.expandtabs(6) for l in self.mk_nw_call(c,calls[c])] newtxt += ["","#endif"] newtxt += ['// modified by %s the %s' % (self.get_author(), datetime.now().strftime("%d/%m/%Y"))] newtxt = self.replacements(newtxt,'\sNT2_CALL_RETURN_TYPE\(',' NT2_RETURN_TYPE(') newtxt = self.replacements(newtxt,'long double_','long_double_') newtxt = self.replace('(?i)gsl_specfun::',fct_name,fct_name.lower(),newtxt) if tryonly != 'tryonly' : write(new,newtxt,False) else : print("---------------") PrettyPrinter().pprint(oldtxt) print("===============") PrettyPrinter().pprint(newtxt) print("===============")
def read_pydoc(self) : p = os.path.join(self.get_doc_path(),self.get_fct_name()+'.py') if not exist(p) : print("%s \n does not exist, please create and edit it "%p) raise SystemExit else : return read(p)
def doxyfy(self) : self.get_file_location() if self.p is None : self.save =False return else : self.txt_list = read(self.fich) self.txt ='\n'.join(self.txt_list) if self.is_immutable(self.txt) : print("%s has been marked as immutable"%self.txt ) self.save = False return if self.txt.find('/*!') != -1 : print("%s file was already oxygenated"%self.fct) if not self.strip : return else : self.txt_list = self.strip_old() self.txt_list = self.make_functor_ox() self.txt = '\n'.join(self.txt_list) self.txt_list = self.make_tag_ox() self.txt = '\n'.join(self.txt_list) self.txt_list =self.suppress_double_blank(self.txt_list) self.txt_list = self.make_file_ox() self.txt = '\n'.join(self.txt_list) return self.txt_list
def is_empty(self,*modes) : path = self.get_fct_impl_path(list(modes)) if not exist(path) : return True for s in read(path) : if (len(s) != 0 and s[0] != "#") : return False if (len(s)>1 and (s[0]!="/" or s[1]!="/") ) : return False return True
def modify_def(self, tryonly='tryonly') : """ text is always modified from old one""" style = self.get_tb_style() fct_name = self.get_fct_name() print("modifying def for %s with style %s"% (fct_name,style)) new = self.get_fct_def_path() old = new+'.old' if not exist(old) : self.duplicate_def() oldtxt = read(old) # PrettyPrinter().pprint(oldtxt) s = '\n'.join(oldtxt) s = re.sub('\t',' ',s) if style == 'sys' : s = re.sub('functors','tag',s) else : pattern = 'namespace %s' % self.get_tb_name() s = re.sub(pattern,pattern+' { namespace tag',s) pattern = '%s::'%self.get_tb_name() s = re.sub(pattern,pattern+'tag::',s) s = re.sub("(}\s*})","}\n } }",s) # print("===========================") newtxt = s.split('\n') if self.get_tb_style()=='usr' : newtxt = self.deplace("\s*NT2_FUNCTION_IMPLEMENTATION.*",newtxt) newtxt = self.deplace("\s*NT2_CRLIBM_FUNCTION_IMPLEMENTATION.*",newtxt) newtxt = self.replace('(?i)(:| )',fct_name,fct_name.lower(),newtxt) newtxt += ['// modified by %s the %s' % (self.get_author(), datetime.now().strftime("%d/%m/%Y"))] if tryonly != 'tryonly' : write(new,newtxt,False) else : print("---------------------------") PrettyPrinter().pprint(oldtxt) print("===========================") PrettyPrinter().pprint(newtxt) print("===========================")
def get_module_style(self,tb_name) : dirname = os.path.join(self.get_modules_path(),tb_name) filename = os.path.join(dirname,"include","nt2","toolbox",tb_name+'.hpp') if exist(filename) : s = read(filename) pattern = re.compile("^// This toolbox is of (.*) type") for l in s : d1 = re.match(pattern,l) if d1 : return d1.groups()[0] filename = os.path.join(dirname,'py_data.py') if exist(filename) : if re.search("'usr'",' '.join(read(filename))) : return 'usr' else : return 'sys' return 'usr'
def is_subsidiary(self) : s = ' '.join(read(self.get_fct_path())) if re.match("#include <nt2/toolbox/"+ self.tbi.get_tb_name() + '/function/simd/.*'+ self.get_fct_filename()+'.hpp> *',s) : return True else : return False
def __read_fct_info_dict(self) : p = self.get_fct_doc_path() ## print("p = %s" % p) if not exist(p) : print("%s does not exist: please create it before use" % p ) raise SystemExit ## self.__create_fct_info_dict(p,error='warn') s = '\n'.join(read(p)) exec("d = "+s) return d
def write_pydoc(self,other_name=None,force=False,backup=True) : name = self.get_fct_name()+'.py' if other_name==None else other_name p = os.path.join(self.get_doc_path(),name) if backup and exist(p) : shutil.copy(p,p+'~') if exist(p) and not force : s = '\n'.join(read(p)) if re.search("manually",s) : print("%s \n was manually modified, skipping"%p) return write(p,str(self),check=False,verbose=True)
def __read_style(self) : dirname = self.get_tb_path() filename = dirname+'.hpp' if exist(filename) : s = read(filename) pattern = re.compile("^// This toolbox is of (.*) type") for l in s : d1 = re.match(pattern,l) if d1 : return d1.groups()[0] filename = os.path.join(dirname,'py_data.py') if exist(filename) : if re.search("'usr'",' '.join(read(filename))) : return 'usr' else : return 'sys' self.__tb_style = 'usr' return 'usr'
def __read_arities(self) : p = self.get_fct_def_path() arities = [] if exist(p) : s = read(p) for l in s : m = re.search(' NT2_*.FUNCTION_IMPLEMENTATION',l) if m : m = re.search('([0-9]+)\)',l) if m : arities.append(int(m.groups()[0])) return arities
def update_file(self,token,txt) : txt_orig = read(self.path_to) done, new_txt = self.insert_after(token,txt_orig,txt) if not done : print("Warning : line\n %s\nis already in %s file"% (txt,self.path_to)) else : if exist(self.path_to) : if self.verbose : print("file\n %s\nwill be updated"%self.path_to) write(self.path_to,new_txt,False) if self.verbose : print("file\n %s\nis now updated"%self.path_to) else : if self.verbose : print("file\n %s\n does not exist"%self.path_to)
def read_fct_info_dict(self,verbose = False) : p = self.get_fct_doc_path() if not exist(p) : print("%s does not exist: please create it before use" % p ) raise SystemExit ## self.__create_fct_info_dict(p,error='warn') s = '\n'.join(read(p)) if verbose : print("py doc file for %s is:" % self.get_fct_name()) print("=============================================") print(s) print("=============================================") exec("d = "+s) return d
def regress_global_includes(self,option="update") : """ the files to be updated is: ./$tb_name$.hpp ../$tb_name$.hpp' and ./include.hpp, are not to be modified after creation TO DO add action for "create" """ name = self.get_fct_name() tb_name = self.get_tb_name() path = os.path.join(self.get_tb_path(),tb_name+'.hpp') txt_orig = read(path) txt = "#include <nt2/toolbox/%s/include/%s.hpp>"%(tb_name,fct_name) done, new_txt = self.remove_line(txt_orig,txt) if not done : print("Warning : line\n %s\nis not found in include file"%txt ) else : self.finalize(path,new_txt,"update")
def __read_fct_info_dict(self,verbose = False) : p = self.get_fct_doc_path() ## print("p = %s" % p) if not exist(p) : print('FATAL ERROR') print("%s does not exist: please create it before use" % p ) print("You can use existing py doc files as model") raise SystemExit ## self.__create_fct_info_dict(p,error='warn') s = '\n'.join(read(p)) if verbose : print("py doc file for %s is:" % self.get_fct_name()) print("=============================================") print(s) print("=============================================") exec("d = "+s) return d
def __read_arity(self) : p = os.path.join(self.tbi.get_def_path(),self.get_fct_filename()+'.hpp') s = read(p) for l in s : m = re.search(' NT2_FUNCTION_IMPLEMENTATION',l) if m : m = re.search('([0-9]+)\)',l) if m : return int(m.groups()[0]) else : m = re.search(' NT2_CRLIBM_FUNCTION_IMPLEMENTATION_TPL',l) if m : m = re.search('([0-9]+)\)',l) if m : return int(m.groups()[0]) return None
def get_module_style(self,tb_name) : dirname = self.get_modules_path() for p in tb_name.split('.') : dirname = os.path.join(dirname,p) dirname = os.path.join(self.get_modules_path(),dirname) filename = os.path.join(dirname,"include","nt2","toolbox",tb_name+'.hpp') ## if exist(filename) : ## s = read(filename) ## pattern = re.compile("^// This toolbox is of (.*) type") ## for l in s : ## d1 = re.match(pattern,l) ## if d1 : return d1.groups()[0] filename = os.path.join(dirname,'py_data.py') if exist(filename) : s = '\n'.join(read(filename)) exec(s) return datas.get('style','usr') return 'usr'
def is_unimplemented(self) : s = ' '.join(read(self.get_fct_def_path())) return bool(re.search('/// Still unimplemented',s))
def is_subsidiary(self,*modes) : path = self.get_fct_impl_path(list(modes)) if not exist(path) : return True s = ' '.join(read(path)) pattern = "#include *<nt2/toolbox/%s/function/simd/.*%s\.hpp> *" return bool(re.match(pattern %(self.get_tb_name(),self.get_fct_name()),s))
def get_fct_def_text(self) : return read(self.get_fct_def_path()) def get_fct_dict_list(self,verbose=False) :
def get_fct_text(self) : return read(self.get_fct_impl_path(self.__mode)) ## submode must be also used here def get_fct_def_text(self) : return read(self.get_fct_def_path())
def is_already_revised(self) : s = ' '.join(read(self.get_fct_def_path())) return bool(re.search('/// Revised by ',s))
def __read_old_unit_txt(self) : p = os.path.join(tbi.get_unit_path(),"scalar",fct+'.cpp') r = read(p) return r
def change_units(self) : p = os.path.join(tbi.get_unit_path(),"scalar",fct+'.cpp') # shutil.move(p,re.sub('.cpp','.bak',p)) s = read(p) # show(s[:-2]) write(p,s[:-2],False)
def __read_old_def_txt(self) : p = os.path.join(tbi.get_def_path(),fct+'.hpp') r = read(p) return r
def suppresslinein(self, p, token): txt = read(p) txt = [re.sub('\s*' + token, '', t) for t in txt] write(p, txt, check=False)