def __init__(self, filename, docmark='!', predocmark='', docmark_alt='', predocmark_alt='', fixed=False, length_limit=True, preprocessor=None, macros=[], inc_dirs=[]): self.name = filename # Check that none of the docmarks are the same if docmark == predocmark != '': raise Exception('Error: docmark and predocmark are the same.') if docmark == docmark_alt != '': raise Exception('Error: docmark and docmark_alt are the same.') if docmark == predocmark_alt != '': raise Exception('Error: docmark and predocmark_alt are the same.') if docmark_alt == predocmark != '': raise Exception('Error: docmark_alt and predocmark are the same.') if docmark_alt == predocmark_alt != '': raise Exception( 'Error: docmark_alt and predocmark_alt are the same.') if predocmark == predocmark_alt != '': raise Exception( 'Error: predocmark and predocmark_alt are the same.') if preprocessor: # Populate the macro definition and include directory path from # the input lists. To define a macro we prepend '-D' and for an # include path we prepend '-I'. It's important that we do not # prepend to an empty string as 'cpp ... -D file.F90' doesn't do # what is desired; use filter to remove these. macros = ['-D' + mac.strip() for mac in filter(None, macros)] incdirs = ['-I' + d.strip() for d in filter(None, inc_dirs)] preprocessor = preprocessor + macros + incdirs + [filename] fpp = subprocess.Popen(preprocessor, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (out, err) = fpp.communicate() if len(err) > 0: print('Warning: error preprocessing ' + filename) print(err) self.reader = open(filename, 'r') else: self.reader = StringIO(str(out)) else: self.reader = open(filename, 'r') if fixed: self.reader = convertToFree(self.reader, length_limit) self.fixed = fixed self.length_limit = length_limit self.inc_dirs = inc_dirs self.docbuffer = [] self.pending = [] self.prevdoc = False self.reading_alt = 0 self.docmark = docmark self.doc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark))) self.predocmark = predocmark if len(self.predocmark) != 0: self.predoc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark))) else: self.predoc_re = None self.docmark_alt = docmark_alt if len(self.docmark_alt) != 0: self.doc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark_alt))) else: self.doc_alt_re = None self.predocmark_alt = predocmark_alt if len(self.predocmark_alt) != 0: self.predoc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark_alt))) else: self.predoc_alt_re = None
def __init__(self,filename,docmark='!',predocmark='',docmark_alt='', predocmark_alt='',fixed=False,length_limit=True, preprocessor=None,macros=[],inc_dirs=[]): self.name = filename # Check that none of the docmarks are the same if docmark == predocmark != '': raise Exception('Error: docmark and predocmark are the same.') if docmark == docmark_alt != '': raise Exception('Error: docmark and docmark_alt are the same.') if docmark == predocmark_alt != '': raise Exception('Error: docmark and predocmark_alt are the same.') if docmark_alt == predocmark != '': raise Exception('Error: docmark_alt and predocmark are the same.') if docmark_alt == predocmark_alt != '': raise Exception('Error: docmark_alt and predocmark_alt are the same.') if predocmark == predocmark_alt != '': raise Exception('Error: predocmark and predocmark_alt are the same.') if preprocessor: # Populate the macro definition and include directory path from # the input lists. To define a macro we prepend '-D' and for an # include path we prepend '-I'. It's important that we do not # prepend to an empty string as 'cpp ... -D file.F90' doesn't do # what is desired; use filter to remove these. macros = ['-D' + mac.strip() for mac in filter(None,macros)] incdirs = ['-I' + d.strip() for d in filter(None,inc_dirs)] preprocessor = preprocessor + macros + incdirs + [filename] fpp = subprocess.Popen(preprocessor, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (out, err) = fpp.communicate() if len(err) > 0: print('Warning: error preprocessing '+filename) print(err) self.reader = open(filename,'r') else: self.reader = StringIO(str(out)) else: self.reader = open(filename,'r') if fixed: self.reader = convertToFree(self.reader, length_limit) self.fixed = fixed self.length_limit = length_limit self.inc_dirs = inc_dirs self.docbuffer = [] self.pending = [] self.prevdoc = False self.reading_alt = 0 self.docmark = docmark self.doc_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(docmark))) self.predocmark = predocmark if len(self.predocmark) != 0: self.predoc_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(predocmark))) else: self.predoc_re = None self.docmark_alt = docmark_alt if len(self.docmark_alt) != 0: self.doc_alt_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(docmark_alt))) else: self.doc_alt_re = None self.predocmark_alt = predocmark_alt if len(self.predocmark_alt) != 0: self.predoc_alt_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(predocmark_alt))) else: self.predoc_alt_re = None
def __init__( self, filename, docmark="!", predocmark="", docmark_alt="", predocmark_alt="", fixed=False, length_limit=True, preprocessor=None, macros=[], inc_dirs=[], encoding="utf-8", ): self.name = filename # Check that none of the docmarks are the same if docmark == predocmark != "": raise Exception("Error: docmark and predocmark are the same.") if docmark == docmark_alt != "": raise Exception("Error: docmark and docmark_alt are the same.") if docmark == predocmark_alt != "": raise Exception("Error: docmark and predocmark_alt are the same.") if docmark_alt == predocmark != "": raise Exception("Error: docmark_alt and predocmark are the same.") if docmark_alt == predocmark_alt != "": raise Exception( "Error: docmark_alt and predocmark_alt are the same.") if predocmark == predocmark_alt != "": raise Exception( "Error: predocmark and predocmark_alt are the same.") if preprocessor: # Populate the macro definition and include directory path from # the input lists. To define a macro we prepend '-D' and for an # include path we prepend '-I'. It's important that we do not # prepend to an empty string as 'cpp ... -D file.F90' doesn't do # what is desired; use filter to remove these. macros = ["-D" + mac.strip() for mac in filter(None, macros)] incdirs = [f"-I{d}" for d in inc_dirs] preprocessor = preprocessor + macros + incdirs + [filename] command = " ".join(preprocessor) print(f"Preprocessing {filename}") try: out = subprocess.run(preprocessor, encoding=encoding, check=True, capture_output=True) if out.stderr: print( f"Warning when preprocessing {filename}:\n{command}\n{out.stderr}" ) self.reader = StringIO(out.stdout) except subprocess.CalledProcessError as err: print( f"Warning: error when preprocessing {filename}:\n{command}\n{err.stderr}" ) print("Reverting to unpreprocessed file") self.reader = open(filename, "r", encoding=encoding) else: self.reader = open(filename, "r", encoding=encoding) if fixed: self.reader = convertToFree(self.reader, length_limit) self.fixed = fixed self.length_limit = length_limit self.inc_dirs = inc_dirs self.docbuffer = [] self.pending = [] self.prevdoc = False self.reading_alt = 0 self.docmark = docmark self.doc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark))) self.predocmark = predocmark self.encoding = encoding if len(self.predocmark) != 0: self.predoc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark))) else: self.predoc_re = None self.docmark_alt = docmark_alt if len(self.docmark_alt) != 0: self.doc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark_alt))) else: self.doc_alt_re = None self.predocmark_alt = predocmark_alt if len(self.predocmark_alt) != 0: self.predoc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark_alt))) else: self.predoc_alt_re = None self.line_number = 0
def __init__(self,filename,docmark='!',predocmark='',docmark_alt='', predocmark_alt='',fixed=False,preprocessor=None,macros=[], inc_dirs=[]): self.name = filename # Check that none of the docmarks are the same if docmark == predocmark != '': raise Exception('Error: docmark and predocmark are the same.') if docmark == docmark_alt != '': raise Exception('Error: docmark and docmark_alt are the same.') if docmark == predocmark_alt != '': raise Exception('Error: docmark and predocmark_alt are the same.') if docmark_alt == predocmark != '': raise Exception('Error: docmark_alt and predocmark are the same.') if docmark_alt == predocmark_alt != '': raise Exception('Error: docmark_alt and predocmark_alt are the same.') if predocmark == predocmark_alt != '': raise Exception('Error: predocmark and predocmark_alt are the same.') if preprocessor: macros = ['-D' + mac.strip() for mac in macros] incdirs = ['-I' + d.strip() for d in inc_dirs] preprocessor = preprocessor + macros + incdirs + [filename] fpp = subprocess.Popen(preprocessor, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (out, err) = fpp.communicate() if len(err) > 0: print('Warning: error preprocessing '+filename) print(err) self.reader = open(filename,'r') else: self.reader = StringIO(str(out)) else: self.reader = open(filename,'r') if fixed: self.reader = convertToFree(self.reader) self.fixed = fixed self.inc_dirs = inc_dirs self.docbuffer = [] self.pending = [] self.prevdoc = False self.reading_alt = 0 self.docmark = docmark self.doc_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(docmark))) self.predocmark = predocmark if len(self.predocmark) != 0: self.predoc_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(predocmark))) else: self.predoc_re = None self.docmark_alt = docmark_alt if len(self.docmark_alt) != 0: self.doc_alt_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(docmark_alt))) else: self.doc_alt_re = None self.predocmark_alt = predocmark_alt if len(self.predocmark_alt) != 0: self.predoc_alt_re = re.compile("^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format(re.escape(predocmark_alt))) else: self.predoc_alt_re = None
def __init__(self, filename, docmark='!', predocmark='', docmark_alt='', predocmark_alt='', fixed=False, preprocessor=None, macros=[], inc_dirs=[]): self.name = filename # Check that none of the docmarks are the same if docmark == predocmark != '': raise Exception('Error: docmark and predocmark are the same.') if docmark == docmark_alt != '': raise Exception('Error: docmark and docmark_alt are the same.') if docmark == predocmark_alt != '': raise Exception('Error: docmark and predocmark_alt are the same.') if docmark_alt == predocmark != '': raise Exception('Error: docmark_alt and predocmark are the same.') if docmark_alt == predocmark_alt != '': raise Exception( 'Error: docmark_alt and predocmark_alt are the same.') if predocmark == predocmark_alt != '': raise Exception( 'Error: predocmark and predocmark_alt are the same.') if preprocessor: macros = ['-D' + mac.strip() for mac in macros] incdirs = ['-I' + d.strip() for d in inc_dirs] preprocessor = preprocessor + macros + incdirs + [filename] fpp = subprocess.Popen(preprocessor, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (out, err) = fpp.communicate() if len(err) > 0: print('Warning: error preprocessing ' + filename) print(err) self.reader = open(filename, 'r') else: self.reader = StringIO(str(out)) else: self.reader = open(filename, 'r') if fixed: self.reader = convertToFree(self.reader) self.fixed = fixed self.inc_dirs = inc_dirs self.docbuffer = [] self.pending = [] self.prevdoc = False self.reading_alt = 0 self.docmark = docmark self.doc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark))) self.predocmark = predocmark if len(self.predocmark) != 0: self.predoc_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark))) else: self.predoc_re = None self.docmark_alt = docmark_alt if len(self.docmark_alt) != 0: self.doc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(docmark_alt))) else: self.doc_alt_re = None self.predocmark_alt = predocmark_alt if len(self.predocmark_alt) != 0: self.predoc_alt_re = re.compile( "^([^\"'!]|('[^']*')|(\"[^\"]*\"))*(!{}.*)$".format( re.escape(predocmark_alt))) else: self.predoc_alt_re = None