eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 9111
4ac66b6c33a4
parent 8881
54e42bc2437a
child 9192
a763d57e23bc
equal deleted inserted replaced
9049:2b9bd8f97576 9111:4ac66b6c33a4
520 520
521 # set the autosave flag 521 # set the autosave flag
522 self.autosaveEnabled = Preferences.getEditor("AutosaveInterval") > 0 522 self.autosaveEnabled = Preferences.getEditor("AutosaveInterval") > 0
523 self.autosaveManuallyDisabled = False 523 self.autosaveManuallyDisabled = False
524 524
525 # code coverage related attributes
526 self.__coverageFile = ""
527
525 self.__initContextMenu() 528 self.__initContextMenu()
526 self.__initContextMenuMargins() 529 self.__initContextMenuMargins()
527 530
528 self.__checkEol() 531 self.__checkEol()
529 if editor is None: 532 if editor is None:
5627 self.project.isOpen() and 5630 self.project.isOpen() and
5628 self.project.isProjectSource(self.fileName) 5631 self.project.isProjectSource(self.fileName)
5629 ): 5632 ):
5630 fn = self.project.getMainScript(True) 5633 fn = self.project.getMainScript(True)
5631 if fn is not None: 5634 if fn is not None:
5632 tfn = Utilities.getTestFileName(fn)
5633 basename = os.path.splitext(fn)[0]
5634 tbasename = os.path.splitext(tfn)[0]
5635 prEnable = ( 5635 prEnable = (
5636 prEnable or 5636 self.project.isPy3Project() and
5637 os.path.isfile("{0}.profile".format(basename)) or 5637 bool(Utilities.getProfileFileNames(fn))
5638 os.path.isfile("{0}.profile".format(tbasename))
5639 ) 5638 )
5640 coEnable = ( 5639 coEnable = (
5641 (coEnable or 5640 self.project.isPy3Project() and
5642 os.path.isfile("{0}.coverage".format(basename)) or 5641 bool(Utilities.getCoverageFileNames(fn))
5643 os.path.isfile("{0}.coverage".format(tbasename))) and
5644 self.project.isPy3Project()
5645 ) 5642 )
5646 5643
5647 # now check ourselves 5644 # now check ourselves
5648 fn = self.getFileName() 5645 fn = self.getFileName()
5649 if fn is not None: 5646 if fn is not None:
5650 tfn = Utilities.getTestFileName(fn) 5647 prEnable |= (
5651 basename = os.path.splitext(fn)[0] 5648 self.project.isPy3Project() and
5652 tbasename = os.path.splitext(tfn)[0] 5649 bool(Utilities.getProfileFileName(fn))
5653 prEnable = (
5654 prEnable or
5655 os.path.isfile("{0}.profile".format(basename)) or
5656 os.path.isfile("{0}.profile".format(tbasename))
5657 ) 5650 )
5658 coEnable = ( 5651 coEnable |= (
5659 (coEnable or 5652 self.project.isPy3Project() and
5660 os.path.isfile("{0}.coverage".format(basename)) or 5653 bool(Utilities.getCoverageFileName(fn))
5661 os.path.isfile("{0}.coverage".format(tbasename))) and
5662 self.isPyFile()
5663 ) 5654 )
5655
5656 coEnable |= bool(self.__coverageFile)
5664 5657
5665 # now check for syntax errors 5658 # now check for syntax errors
5666 if self.hasSyntaxErrors(): 5659 if self.hasSyntaxErrors():
5667 coEnable = False 5660 coEnable = False
5668 5661
6046 def __getCodeCoverageFile(self): 6039 def __getCodeCoverageFile(self):
6047 """ 6040 """
6048 Private method to get the file name of the file containing coverage 6041 Private method to get the file name of the file containing coverage
6049 info. 6042 info.
6050 6043
6051 @return file name of the coverage file (string) 6044 @return file name of the coverage file
6052 """ 6045 @rtype str
6053 files = [] 6046 """
6047 files = set()
6048
6049 if bool(self.__coverageFile):
6050 # return the path of a previously used coverage file
6051 return self.__coverageFile
6054 6052
6055 # first check if the file belongs to a project and there is 6053 # first check if the file belongs to a project and there is
6056 # a project coverage file 6054 # a project coverage file
6057 if ( 6055 if (
6058 self.project.isOpen() and 6056 self.project.isOpen() and
6059 self.project.isProjectSource(self.fileName) 6057 self.project.isProjectSource(self.fileName)
6060 ): 6058 ):
6061 fn = self.project.getMainScript(True) 6059 pfn = self.project.getMainScript(True)
6062 if fn is not None: 6060 if pfn is not None:
6063 tfn = Utilities.getTestFileName(fn) 6061 files |= set(Utilities.getCoverageFileNames(pfn))
6064 basename = os.path.splitext(fn)[0]
6065 tbasename = os.path.splitext(tfn)[0]
6066
6067 f = "{0}.coverage".format(basename)
6068 tf = "{0}.coverage".format(tbasename)
6069 if os.path.isfile(f):
6070 files.append(f)
6071 if os.path.isfile(tf):
6072 files.append(tf)
6073 6062
6074 # now check, if there are coverage files belonging to ourselves 6063 # now check, if there are coverage files belonging to ourselves
6075 fn = self.getFileName() 6064 fn = self.getFileName()
6076 if fn is not None: 6065 if fn is not None:
6077 tfn = Utilities.getTestFileName(fn) 6066 files |= set(Utilities.getCoverageFileNames(fn))
6078 basename = os.path.splitext(fn)[0] 6067
6079 tbasename = os.path.splitext(tfn)[0] 6068 files = list(files)
6080
6081 f = "{0}.coverage".format(basename)
6082 tf = "{0}.coverage".format(tbasename)
6083 if os.path.isfile(f) and f not in files:
6084 files.append(f)
6085 if os.path.isfile(tf) and tf not in files:
6086 files.append(tf)
6087
6088 if files: 6069 if files:
6089 if len(files) > 1: 6070 if len(files) > 1:
6090 fn, ok = QInputDialog.getItem( 6071 cfn, ok = QInputDialog.getItem(
6091 self, 6072 self,
6092 self.tr("Code Coverage"), 6073 self.tr("Code Coverage"),
6093 self.tr("Please select a coverage file"), 6074 self.tr("Please select a coverage file"),
6094 files, 6075 files,
6095 0, False) 6076 0, False)
6096 if not ok: 6077 if not ok:
6097 return "" 6078 return ""
6098 else: 6079 else:
6099 fn = files[0] 6080 cfn = files[0]
6100 else: 6081 else:
6101 fn = None 6082 cfn = None
6102 6083
6103 return fn 6084 return cfn
6104 6085
6105 def __showCodeCoverage(self): 6086 def __showCodeCoverage(self):
6106 """ 6087 """
6107 Private method to handle the code coverage context menu action. 6088 Private method to handle the code coverage context menu action.
6108 """ 6089 """
6109 fn = self.__getCodeCoverageFile() 6090 fn = self.__getCodeCoverageFile()
6091 self.__coverageFile = fn
6110 if fn: 6092 if fn:
6111 from DataViews.PyCoverageDialog import PyCoverageDialog 6093 from DataViews.PyCoverageDialog import PyCoverageDialog
6112 self.codecoverage = PyCoverageDialog() 6094 self.codecoverage = PyCoverageDialog()
6113 self.codecoverage.show() 6095 self.codecoverage.show()
6114 self.codecoverage.start(fn, self.fileName) 6096 self.codecoverage.start(fn, self.fileName)
6118 Public method to refresh the code coverage annotations. 6100 Public method to refresh the code coverage annotations.
6119 """ 6101 """
6120 if self.showingNotcoveredMarkers: 6102 if self.showingNotcoveredMarkers:
6121 self.codeCoverageShowAnnotations(silent=True) 6103 self.codeCoverageShowAnnotations(silent=True)
6122 6104
6123 def codeCoverageShowAnnotations(self, silent=False): 6105 def codeCoverageShowAnnotations(self, silent=False, coverageFile=None):
6124 """ 6106 """
6125 Public method to handle the show code coverage annotations context 6107 Public method to handle the show code coverage annotations context
6126 menu action. 6108 menu action.
6127 6109
6128 @param silent flag indicating to not show any dialog (boolean) 6110 @param silent flag indicating to not show any dialog (defaults to
6111 False)
6112 @type bool (optional)
6113 @param coverageFile path of the file containing the code coverage data
6114 (defaults to None)
6115 @type str (optional)
6129 """ 6116 """
6130 self.__codeCoverageHideAnnotations() 6117 self.__codeCoverageHideAnnotations()
6131 6118
6132 fn = self.__getCodeCoverageFile() 6119 fn = (
6120 coverageFile
6121 if bool(coverageFile) else
6122 self.__getCodeCoverageFile()
6123 )
6124 self.__coverageFile = fn
6125
6133 if fn: 6126 if fn:
6134 from coverage import Coverage 6127 from coverage import Coverage
6135 cover = Coverage(data_file=fn) 6128 cover = Coverage(data_file=fn)
6136 cover.load() 6129 cover.load()
6137 missing = cover.analysis2(self.fileName)[3] 6130 missing = cover.analysis2(self.fileName)[3]
6228 6221
6229 def __showProfileData(self): 6222 def __showProfileData(self):
6230 """ 6223 """
6231 Private method to handle the show profile data context menu action. 6224 Private method to handle the show profile data context menu action.
6232 """ 6225 """
6233 files = [] 6226 files = set()
6234 6227
6235 # first check if the file belongs to a project and there is 6228 # first check if the file belongs to a project and there is
6236 # a project profile file 6229 # a project profile file
6237 if ( 6230 if (
6238 self.project.isOpen() and 6231 self.project.isOpen() and
6239 self.project.isProjectSource(self.fileName) 6232 self.project.isProjectSource(self.fileName)
6240 ): 6233 ):
6241 fn = self.project.getMainScript(True) 6234 fn = self.project.getMainScript(True)
6242 if fn is not None: 6235 if fn is not None:
6243 tfn = Utilities.getTestFileName(fn) 6236 files |= set(Utilities.getProfileFileNames(fn))
6244 basename = os.path.splitext(fn)[0]
6245 tbasename = os.path.splitext(tfn)[0]
6246
6247 f = "{0}.profile".format(basename)
6248 tf = "{0}.profile".format(tbasename)
6249 if os.path.isfile(f):
6250 files.append(f)
6251 if os.path.isfile(tf):
6252 files.append(tf)
6253 6237
6254 # now check, if there are profile files belonging to ourselves 6238 # now check, if there are profile files belonging to ourselves
6255 fn = self.getFileName() 6239 fn = self.getFileName()
6256 if fn is not None: 6240 if fn is not None:
6257 tfn = Utilities.getTestFileName(fn) 6241 files |= set(Utilities.getProfileFileNames(fn))
6258 basename = os.path.splitext(fn)[0] 6242
6259 tbasename = os.path.splitext(tfn)[0] 6243 files = list(files)
6260
6261 f = "{0}.profile".format(basename)
6262 tf = "{0}.profile".format(tbasename)
6263 if os.path.isfile(f) and f not in files:
6264 files.append(f)
6265 if os.path.isfile(tf) and tf not in files:
6266 files.append(tf)
6267
6268 if files: 6244 if files:
6269 if len(files) > 1: 6245 if len(files) > 1:
6270 fn, ok = QInputDialog.getItem( 6246 fn, ok = QInputDialog.getItem(
6271 self, 6247 self,
6272 self.tr("Profile Data"), 6248 self.tr("Profile Data"),

eric ide

mercurial