diff -r 2b9bd8f97576 -r 4ac66b6c33a4 eric7/Project/Project.py --- a/eric7/Project/Project.py Mon May 02 15:53:05 2022 +0200 +++ b/eric7/Project/Project.py Wed Jun 01 13:48:49 2022 +0200 @@ -39,6 +39,7 @@ from EricGui.EricAction import EricAction, createActionGroup +import Globals import Preferences import Utilities @@ -524,6 +525,7 @@ }, "EOL": -1, "DOCSTRING": "", + "TESTING_FRAMEWORK": "", } self.__initDebugProperties() @@ -3361,9 +3363,13 @@ """ Public method to return the main script filename. + The normalized name is the name of the main script prepended with + the project path. + @param normalized flag indicating a normalized filename is wanted - (boolean) - @return filename of the projects main script (string) + @type bool + @return filename of the projects main script + @rtype str """ if self.pdata["MAINSCRIPT"]: if normalized: @@ -3371,15 +3377,16 @@ else: return self.pdata["MAINSCRIPT"] else: - return None + return "" def getSources(self, normalized=False): """ Public method to return the source script files. @param normalized flag indicating a normalized filename is wanted - (boolean) - @return list of the projects scripts (list of string) + @type bool + @return list of the projects scripts + @rtype list of str """ return self.getProjectFiles("SOURCES", normalized=normalized) @@ -3704,6 +3711,79 @@ """ return self.pdata["DESCRIPTION"] + def getProjectVenv(self, resolveDebugger=True): + """ + Public method to get the name of the virtual environment used by the + project. + + @param resolveDebugger flag indicating to resolve the virtual + environment name via the debugger settings if none was configured + @type bool + @return name of the project's virtual environment + @rtype str + """ + venvName = self.getDebugProperty("VIRTUALENV") + if ( + not venvName and + resolveDebugger and + self.getProjectLanguage() in ("Python3", "MicroPython", "Cython") + ): + venvName = Preferences.getDebugger("Python3VirtualEnv") + + return venvName + + def getProjectInterpreter(self, resolveGlobal=True): + """ + Public method to get the path of the interpreter used by the project. + + @param resolveGlobal flag indicating to resolve the interpreter using + the global interpreter if no project of debugger specific + environment was configured + @type bool + @return path of the project's interpreter + @rtype str + """ + interpreter = "" + venvName = self.getProjectVenv() + if venvName: + interpreter = ( + ericApp().getObject("VirtualEnvManager") + .getVirtualenvInterpreter(venvName) + ) + if not interpreter and resolveGlobal: + interpreter = Globals.getPythonExecutable() + + return interpreter + + def getProjectExecPath(self): + """ + Public method to get the executable search path prefix of the project. + + @return executable search path prefix + @rtype str + """ + execPath = "" + venvName = self.getProjectVenv() + if venvName: + execPath = ( + ericApp().getObject("VirtualEnvManager") + .getVirtualenvExecPath(venvName) + ) + + return execPath + + def getProjectTestingFramework(self): + """ + Public method to get the testing framework name of the project. + + @return testing framework name of the project + @rtype str + """ + try: + return self.pdata["TESTING_FRAMEWORK"] + except KeyError: + return "" + def __isInPdata(self, fn): """ Private method used to check, if the passed in filename is project @@ -4990,19 +5070,7 @@ " current project. Aborting")) return - tfn = Utilities.getTestFileName(fn) - basename = os.path.splitext(fn)[0] - tbasename = os.path.splitext(tfn)[0] - - # determine name of coverage file to be used - files = [] - f = "{0}.coverage".format(basename) - tf = "{0}.coverage".format(tbasename) - if os.path.isfile(f): - files.append(f) - if os.path.isfile(tf): - files.append(tf) - + files = Utilities.getCoverageFileNames(fn) if files: if len(files) > 1: fn, ok = QInputDialog.getItem( @@ -5040,19 +5108,7 @@ " current project. Aborting")) return - tfn = Utilities.getTestFileName(fn) - basename = os.path.splitext(fn)[0] - tbasename = os.path.splitext(tfn)[0] - - # determine name of profile file to be used - files = [] - f = "{0}.profile".format(basename) - tf = "{0}.profile".format(tbasename) - if os.path.isfile(f): - files.append(f) - if os.path.isfile(tf): - files.append(tf) - + files = Utilities.getProfileFileNames(fn) if files: if len(files) > 1: fn, ok = QInputDialog.getItem( @@ -5078,20 +5134,17 @@ Private slot called before the show menu is shown. """ fn = self.getMainScript(True) - if fn is not None: - tfn = Utilities.getTestFileName(fn) - basename = os.path.splitext(fn)[0] - tbasename = os.path.splitext(tfn)[0] - self.codeProfileAct.setEnabled( - os.path.isfile("{0}.profile".format(basename)) or - os.path.isfile("{0}.profile".format(tbasename))) - self.codeCoverageAct.setEnabled( - self.isPy3Project() and - (os.path.isfile("{0}.coverage".format(basename)) or - os.path.isfile("{0}.coverage".format(tbasename)))) - else: - self.codeProfileAct.setEnabled(False) - self.codeCoverageAct.setEnabled(False) + if not fn: + fn = self.getProjectPath() + + self.codeProfileAct.setEnabled( + self.isPy3Project() and + bool(Utilities.getProfileFileName(fn)) + ) + self.codeCoverageAct.setEnabled( + self.isPy3Project() and + bool(Utilities.getCoverageFileNames(fn)) + ) self.showMenu.emit("Show", self.menuShow)