def write_unit(self, fct_name, mode, part, s): def test_immutable(p): s = '\n'.join(read(p)) return s.find('//COMMENTED') != -1 nfp = Nt2_fct_props(self.tb_name, fct_name, mode) p = nfp.get_fct_unit_path(mode, part) if exist(os.path.split(p)[0]): if self.verbose: print('path = %s' % p) print("---%s" % exist(p)) if exist(p) and test_immutable(p): print("%s has been marked as immutable" % p) return if self.backup_on_write and exist(p): if self.verbose: print("backing up %s" % fct_name) i = 1 while True: pi = p + '.' + str(i) + '.bak' if not (exist(pi)): break i += 1 if self.verbose: print("to %s" % pi) shutil.copy(p, pi) elif self.verbose: print "writing to %s" % p write(p, s, self.check_on_write) p1 = os.path.join(os.path.split(p)[0], 'CMakeLists.txt') addline = Add_line(p1, fct_name) addline.update_file("SET\( *SOURCES") elif self.verbose: print("%s directory\n does not exist " % os.path.split(p)[0])
def write(self,p,name,txt) : if self.show : show(txt) self.p =p self.name = name self.txt = txt if isinstance(p,str) and exist(self.p) : ## if self.verbose : print ('path = %s'%self.p) tp = os.path.join(self.p,self.name) if exist(tp) : if not self.write_files : return False if self.backup_on_write and exist(tp) : if self.verbose : print("backing up %s" %name) i = 1; while True : tpi = tp+'.'+str(i)+'.bak' if not(exist(tpi)) : break i += 1 if self.verbose : print("to %s"% tpi) shutil.copy(tp,tpi) elif not self.write_files : print "%s is not written"%tp return False if self.verbose : print "writing to %s"%tp if write(tp,self.txt,self.check_on_write) : print "%s is written"%tp return True; elif self.verbose and isinstance(p,str) : print("%s directory\n does not exist " %os.path.split(p)[0]) else : print("no path found") return False
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 write_file(self, p, txt, show=True, wr=False, check=True, backup=True): txt = txt.split('\n') just = "Just" if wr: just = "Also" if backup and exist(p): i = 1 while True: pi = p + '.' + str(i) + '.bak' if not (exist(pi)): break i += 1 print("backing to %s" % pi) shutil.copy(p, pi) print "writing to %s" % p write(p, txt, check) if p[-4:] == '.cpp': p1 = os.path.join(os.path.split(p)[0], 'CMakeLists.txt') addline = Add_line(p1, self.name) addline.update_file("SET\( *SOURCES") if show: print("%s showing text of %s for %s-test" % (just, os.path.split(p)[1], self.mode)) print("<" + "=" * 40) PrettyPrinter().pprint(txt) print("=" * 40 + ">")
def write_file(self,p,txt, show=True, wr=False, check=True, backup=True) : txt = txt.split('\n') just ="Just" if wr : just = "Also" if backup and exist(p) : i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 print("backing to %s"% pi) shutil.copy(p,pi) print "writing to %s"%p write(p,txt,check) if p[-4:]=='.cpp' : p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,self.name) addline.update_file("SET\( *SOURCES") if show : print("%s showing text of %s for %s-test"% (just,os.path.split(p)[1],self.mode)) print("<"+"="*40) PrettyPrinter().pprint(txt) print("="*40+">")
def who_is_missing(self, fct_name, verbose=False): """returns what files are potentially missing for a functor in a module""" tb_name = self.get_tb_name() head = False mes = "for the '%s' module and functor '%s' \nthe following files are not defined:" % ( tb_name, fct_name) r = [] for f in self.get_rel_tb_fcts_files(tb_name, fct_name): if re.match("doc|bench|unit", f): if not exist(os.path.join(self.get_md_path(), f)): r += os.path.abspath(os.path.join(self.get_md_path(), f)) if verbose: head = self.__print_cond(head, mes) print(" %s" % os.path.abspath( os.path.join(self.get_md_path(), f))) else: if not exist(os.path.join(self.get_tb_path(), f)): r += os.path.abspath(os.path.join(self.get_tb_path(), f)) if verbose: head = self.__print_cond(head, mes) print(" %s" % os.path.abspath( os.path.join(self.get_tb_path(), f))) if (not head) and verbose: print( "for the '%s' module and functor '%s', no files are missing" % (tb_name, fct_name))
def who_is_here(self, fct_name, verbose=False): """returns the files already present for a functor in a module""" tb_name = self.get_tb_name() head = False mes = ( "for the '%s' module and functor '%s' \nthe following files exist:" % (tb_name, fct_name)) r = [] for f in self.get_rel_tb_fcts_files(tb_name, fct_name): if re.match("doc|bench|unit", f): if exist(os.path.join(self.get_md_path(), f)): r += os.path.abspath(os.path.join(self.get_md_path(), f)) if verbose: head = self.__print_cond(head, mes) print(" %s" % os.path.abspath( os.path.join(self.get_md_path(), f))) else: if exist(os.path.join(self.get_tb_path(), f)): r += os.path.abspath(os.path.join(self.get_tb_path(), f)) if verbose: head = self.__print_cond(head, mes) print(" %s" % os.path.abspath( os.path.join(self.get_tb_path(), f))) if (not head) and verbose: print( "for the '%s' module and functor '%s', no files are defined" % (tb_name, fct_name))
def write_unit(self, fct_name, mode, part, s) : def test_immutable(p) : s= '\n'.join(read(p)) return s.find('//COMMENTED') != -1 nfp = Nt2_fct_props(self.tb_name,fct_name,mode) p = nfp.get_fct_unit_path(mode,part) if exist(os.path.split(p)[0]) : if self.verbose : print ('path = %s'%p) print("---%s"%exist(p)) if exist(p) and test_immutable(p) : print("%s has been marked as immutable"%p ) return if self.backup_on_write and exist(p) : if self.verbose : print("backing up %s" %fct_name) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 if self.verbose : print("to %s"% pi) shutil.copy(p,pi) elif self.verbose : print "writing to %s"%p write(p,s,self.check_on_write) p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,fct_name) addline.update_file("SET\( *SOURCES") elif self.verbose : print("%s directory\n does not exist " %os.path.split(p)[0])
def get_property_value(self,arity) : name = self.get_fct_name() p = os.path.join(self.get_nt2_path(),'nt2','include','functions',name+'.hpp') print("exist(p) %s"%exist(p)) print("==============================%s"%p) patch = "" if exist(p) else "boost_math::" call_param = ','.join([ "a%d" % i for i in xrange(0, arity) ]) value = "nt2::%s%s(%s)"% (patch,name,call_param) return "{'default' : ['%s'],}" % value
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 remove_files(self): for f in self.fct_files: p = os.path.join(self.get_tb_path(), f) if exist(p) and p[-2:] != 'py': self.delete(p) for f in self.unique_files: p = os.path.join(self.get_tb_path(), f) if exist(p): [ignore, fname] = os.path.split(p) ## print(fname) ## print("%s exists is %s"%(p,exist(p))) if fname == 'CMakeLists.txt': self.suppresslinein(p, self.get_fct_name() + '.cpp') elif fname == self.get_tb_name() + '.hpp': self.suppresslinein(p, self.get_fct_name() + '.hpp') else: print(fname)
def write_bench(tb_name, fct_name, mode, s, check=False, backup=True): nfp = Nt2_fct_props(tb_name, fct_name, mode) print("mode %s" % mode) p = nfp.get_fct_bench_path(mode) ## print ('p = %s'%p) if backup and exist(p): ## print("p=%s" %p) i = 1 while True: pi = p + '.' + str(i) + '.bak' if not (exist(pi)): break i += 1 print("backing to %s" % pi) shutil.copy(p, pi) print "writing to %s" % p write(p, s, check)
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 get_included(self): name = self.get_fct_name() p = os.path.join(self.get_nt2_path(), "nt2", "include", "functions", name + ".hpp") if exist(p): return "['#include <nt2/include/functions/%s.hpp>']" % name else: return "[]"
def remove_files(self) : for f in self.fct_files : p = os.path.join(self.get_tb_path(),f) if exist(p) and p[-2:]!='py' : self.delete(p) for f in self.unique_files : p = os.path.join(self.get_tb_path(),f) if exist(p) : [ignore, fname] = os.path.split(p) ## print(fname) ## print("%s exists is %s"%(p,exist(p))) if fname == 'CMakeLists.txt' : self.suppresslinein(p,self.get_fct_name()+'.cpp') elif fname == self.get_tb_name()+'.hpp': self.suppresslinein(p,self.get_fct_name()+'.hpp') else : print(fname)
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 __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 write_bench(tb_name,fct_name,mode,s,check=False,backup=True) : nfp = Nt2_fct_props(tb_name,fct_name,mode) print("mode %s"%mode) p = nfp.get_fct_bench_path(mode) print ('p = %s'%p) if backup and exist(p) : ## print("p=%s" %p) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 print("backing to %s"% pi) shutil.copy(p,pi) print "writing to %s"%p write(p,s,check)
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 __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 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 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_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 get_included(self) : name = self.get_fct_name() p = os.path.join(self.get_nt2_path(),'nt2','include','functions',name+'.hpp') if exist(p) : return "['#include <nt2/include/functions/%s.hpp>']"%name else : return "[]"
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 __find_implanted_scalar_archis(self): rel = os.path.join("arithmetic", "include", "nt2", "toolbox", "arithmetic", "function") return [ s for s in Nt2_archis_struct.get_supported_archis_tags() if exist(os.path.join(self.get_toolboxes_path(), rel, s)) ]
def get_file_location(self) : self.p = self.nfp.get_def_path() self.fich = os.path.join(self.p,self.fct+'.hpp') if not exist(self.fich) : print("file: %s does not exist"%self.fich) self.p = self.nfp.get_redef_path() self.fich = os.path.join(self.nfp.get_redef_path(),self.fct+'.hpp') if not exist(self.fich) : print("and file: %s neither exist"%self.fich) self.p = self.nfp.get_const_path() self.fich = os.path.join(self.p,self.fct+'.hpp') if not exist(self.fich) : print("and file: %s neither exist"%self.fich) self.p=None else : print("but file: %s exists"%self.fich)
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 __mk_toolbox_list(self): l = [] p = self.get_toolboxes_path() for name in os.listdir(p): p1 = os.path.join(p, name) if os.path.isdir(p1) and exist(os.path.join(p1, 'py_data.py')): h = name l.append(h) return l
def __mk_toolbox_list(self) : l = [] p = self.get_toolboxes_path() for name in os.listdir(p) : p1 = os.path.join(p,name) if os.path.isdir(p1) and exist(os.path.join(p1,'py_data.py')): h = name l.append(h) return l
def write_exhaustive(tb_name,fct_name,mode,s,check=False,backup=True) : nfp = Nt2_fct_props(tb_name,fct_name,mode) print("mode %s"%mode) p = nfp.get_fct_exhaustive_path(mode) print ('p = %s'%p) if backup and exist(p) : ## print("p=%s" %p) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 print("backing to %s"% pi) shutil.copy(p,pi) print "writing to %s"%p write(p,s,check) p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,fct_name) addline.update_file("SET\( *SOURCES")
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_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 finalize(self,path,txt,option) : verbose = False print("======================") if option == "create" : if exist(path) : if verbose : print("file\n %s\n exists"%path) else : if verbose : print("file\n %s\nwill be created"%path) self.create(path,txt) if verbose : print("file\n %s\nis now created"%path) elif option == "update" : if exist(path) : if verbose : print("file\n %s\nwill be updated") self.update(path,txt) if verbose : print("file\n %s\nis now updated"%path) else : if verbose : print("file\n %s\n does not exist"%path) else : if verbose : print("I do not know what to do with: \n %s\nplease help me!"%path) print("----------------------")
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 who_is_missing(self,fct_name,verbose=False) : """returns what files are potentially missing for a functor in a module""" tb_name = self.get_tb_name() head = False mes = "for the '%s' module and functor '%s' \nthe following files are not defined:"% (tb_name,fct_name) r = [] for f in self.get_rel_tb_fcts_files(tb_name,fct_name) : if re.match("doc|bench|unit",f) : if not exist(os.path.join(self.get_md_path(),f)) : r += os.path.abspath(os.path.join(self.get_md_path(),f)) if verbose : head = self.__print_cond(head,mes) print(" %s"% os.path.abspath(os.path.join(self.get_md_path(),f))) else : if not exist(os.path.join(self.get_tb_path(),f)) : r += os.path.abspath(os.path.join(self.get_tb_path(),f)) if verbose : head = self.__print_cond(head,mes) print(" %s"% os.path.abspath(os.path.join(self.get_tb_path(),f))) if (not head) and verbose : print("for the '%s' module and functor '%s', no files are missing"% (tb_name,fct_name))
def finalize(self,path,new_txt,option) : verbose = False print("======================") if option == "remove" : if not exist(path) : if verbose : print("file\n %s\n does not exist"%path) else : if verbose : print("file\n %s\nwill be removed"%path) self.remove(path) if verbose : print("file\n %s\nis now created"%path) elif option == "update" : if exist(path) : if verbose : print("file\n %s\nwill be regressed") self.regress(path,new_txt) if verbose : print("file\n %s\nis now regressed"%path) else : if verbose : print("file\n %s\n does not exist"%path) else : if verbose : print("I do not know what to do with: \n %s\nplease help me!"%path) print("----------------------")
def who_is_here(self,fct_name,verbose=False) : """returns the files already present for a functor in a module""" tb_name = self.get_tb_name() head = False mes = ("for the '%s' module and functor '%s' \nthe following files exist:"% (tb_name,fct_name)) r = [] for f in self.get_rel_tb_fcts_files(tb_name,fct_name) : if re.match("doc|bench|unit",f) : if exist(os.path.join(self.get_md_path(),f)) : r += os.path.abspath(os.path.join(self.get_md_path(),f)) if verbose : head = self.__print_cond(head,mes) print(" %s"% os.path.abspath(os.path.join(self.get_md_path(),f))) else : if exist(os.path.join(self.get_tb_path(),f)) : r += os.path.abspath(os.path.join(self.get_tb_path(),f)) if verbose : head = self.__print_cond(head,mes) print(" %s"% os.path.abspath(os.path.join(self.get_tb_path(),f))) if (not head) and verbose : print("for the '%s' module and functor '%s', no files are defined"% (tb_name,fct_name))
def create_fct_pydoc_file(self, force=False,error='warn') : p = self.get_fct_doc_path() if not exist(p) or force: s = self.mk_doc_from_existing_fct() PrettyPrinter().pprint(s) # write(p,s) print("creating properties dictionnary file from template") print("please edit the template before using it") print("to create the functors files") if error == 'exit' : raise SystemExit else : print("file exist")
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 update_file(self,token) : txt_orig = read(self.path_to) txt = "%s.cpp"%self.name done, new_txt = self.insert_after(token,txt_orig,txt) if not done : print("Warning : line\n %s\nis already in CMakelists.txt file"%txt ) 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_arities(self) : p = self.get_fct_def_path() arities = [] if exist(p) : s = read(p) # PrettyPrinter().pprint(s) for l in s : m = re.search('\s*NT2_.*FUNCTION_IMPLEMENTATION',l) if m : m = re.search('([0-9]+)\)',l) if m : arities.append(int(m.groups()[0])) return arities
def finalize(self, path, txt, option): verbose = False print("======================") if option == "create": if exist(path): if verbose: print("file\n %s\n exists" % path) else: if verbose: print("file\n %s\nwill be created" % path) self.create(path, txt) if verbose: print("file\n %s\nis now created" % path) elif option == "update": if exist(path): if verbose: print("file\n %s\nwill be updated") self.update(path, txt) if verbose: print("file\n %s\nis now updated" % path) else: if verbose: print("file\n %s\n does not exist" % path) else: if verbose: print( "I do not know what to do with: \n %s\nplease help me!" % path) print("----------------------")
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 finalize(self, path, new_txt, option): verbose = False print("======================") if option == "remove": if not exist(path): if verbose: print("file\n %s\n does not exist" % path) else: if verbose: print("file\n %s\nwill be removed" % path) self.remove(path) if verbose: print("file\n %s\nis now created" % path) elif option == "update": if exist(path): if verbose: print("file\n %s\nwill be regressed") self.regress(path, new_txt) if verbose: print("file\n %s\nis now regressed" % path) else: if verbose: print("file\n %s\n does not exist" % path) else: if verbose: print( "I do not know what to do with: \n %s\nplease help me!" % path) print("----------------------")
def __read_fct_info_dict(self,verbose = False) : p = self.get_fct_doc_path() print("p = %s" % p) print("self.get_doc_path() %s" % self.get_doc_path()) 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 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_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_includes(self, idds, specifics=False): Aliases = { 'lt': 'is_less', 'gt': 'is_greater', 'le': 'is_less_equal', 'ge': 'is_greater_equal', 'eq': 'is_equal', 'neq': 'is_not_equal', 'b_and': 'bitwise_and', 'b_xor': 'bitwise_xor', 'b_or': 'bitwise_or', 'b_andnot': 'bitwise_andnot', 'b_notand': 'bitwise_notand', 'b_ornot': 'bitwise_ornot', 'b_notor': 'bitwise_notor', 'if_nan_else': 'if_allbits_else', 'assert_all': 'assert_utils', 'single_constant': 'Real_splat', 'double_constant': 'Real_splat', 'l_or': 'logical_or', 'l_and': 'logical_and', 'l_andnot': 'logical_andnot', 'l_notand': 'logical_notand', 'l_ornot': 'logical_ornot', 'l_notor': 'logical_notor', "shri": 'shr', "shl": 'shift_left' } root = self.root sdk = ['as_logical', 'cardinal_of', 'scalar_of', 'as_floating'] kernels = ['tanh_kernel', 'sinh_kernel', 'sinhc_kernel'] s = [] # pprint(idds) # pprint(self.textorig) ids = [] for idd in idds: idd = self.translate(idd) if idd in Aliases.keys(): idd = Aliases[idd] ids.append(idd) ids = set(ids) # pprint(ids) for idd in ids: if (idd == 'powf'): s.append('#include <cmath>') elif (idd == 'horner'): s.append( '#include <nt2/polynomials/functions/scalar/impl/horner.hpp>' ) elif (idd[0] == idd[0].upper()): f = self.base + 'include/constants/' + idd.lower() + '.hpp' if exist(root + f): s.append('#include <' + f + '>') else: pprint(root + f + " does not exist") elif idd in sdk: f = self.base + 'sdk/meta/' + idd + '.hpp' s.append('#include <' + f + '>') elif idd in kernels: s.append('#include <nt2/' + self.module + 'functions/details/' + idd + '.hpp>') else: if self.unspecif: f = self.base + 'include/functions/' + idd + '.hpp' else: f = self.base + 'include/functions/' + self.modestr + idd + '.hpp' ## pprint("========================================================") ## pprint(root) ## pprint(f) ## pprint(exist(root+f)) ## pprint("********************************************************") if exist(root + f): s.append('#include <' + f + '>') else: incs = self.get_include_in_orig(idd) if incs: ## pprint("found in orig file ") ## pprint(incs) s.extend(incs) #TODO verif something on that else: pprint("nothing found in orig file for " + idd) ## pprint("========================================================") if specifics: s = self.add_specifics(s) return sorted(set(s))
def cond_mkdir(p): if not exist(p): mkdir(p) print(p)