diff -r be24be92ed0f -r 72ebb74aa42d ProjectPyramid/Project.py --- a/ProjectPyramid/Project.py Thu Apr 09 18:34:09 2020 +0200 +++ b/ProjectPyramid/Project.py Tue Jun 23 18:14:14 2020 +0200 @@ -7,17 +7,9 @@ Module implementing the Pyramid project support. """ -from __future__ import unicode_literals - -try: - import configparser -except ImportError: - str = unicode # __IGNORE_WARNING__ - import ConfigParser as configparser # __IGNORE_WARNING__ - import os import re -import sys +import configparser from PyQt5.QtCore import QObject, QFileInfo, QTimer, QUrl from PyQt5.QtGui import QDesktopServices @@ -453,16 +445,17 @@ Public method to add our hook methods. """ if self.__e5project.getProjectType() == "Pyramid": - self.__formsBrowser = \ - e5App().getObject("ProjectBrowser").getProjectBrowser("forms") + self.__formsBrowser = ( + e5App().getObject("ProjectBrowser") + .getProjectBrowser("forms")) self.__formsBrowser.addHookMethodAndMenuEntry( "newForm", self.newForm, self.tr("New template...")) self.__e5project.projectLanguageAddedByCode.connect( self.__projectLanguageAdded) - self.__translationsBrowser = \ - e5App().getObject("ProjectBrowser")\ - .getProjectBrowser("translations") + self.__translationsBrowser = ( + e5App().getObject("ProjectBrowser") + .getProjectBrowser("translations")) self.__translationsBrowser.addHookMethodAndMenuEntry( "extractMessages", self.extractMessages, self.tr("Extract Messages")) @@ -620,7 +613,7 @@ variants = [] cmd = "pcreate" - for variant in 'Python2', 'Python3': + for variant in ['Python3']: virtEnv = self.__getVirtualEnvironment(variant) if virtEnv: fullCmd = self.getPyramidCommand(cmd, variant) @@ -656,23 +649,16 @@ given Python variant. @param variant Python variant to test for - @type str (one of Python2 or Python3) + @type str @param line0 first line of the executable @type str @return flag indicating a suitable command @rtype bool """ - assert variant in ("Python2", "Python3") - l0 = line0.lower() ok = (variant.lower() in l0 or "{0}.".format(variant[-1]) in l0) - if variant == "Python2": - ok |= "python3" not in l0 and "python" in l0 - ok |= "pypy2" in l0 - ok |= "pypy3" not in l0 and "pypy" in l0 - else: - ok |= "pypy3" in l0 + ok |= "pypy3" in l0 return ok @@ -681,7 +667,7 @@ Private method to get the path of the virtual environment. @param language Python variant to get the virtual environment - for (string, one of '', 'Python2' or 'Python3') + for (string, one of '' or 'Python3') @return path of the virtual environment (string) """ if not language: @@ -690,9 +676,6 @@ if language == "Python3": venvName = self.__plugin.getPreferences( "VirtualEnvironmentNamePy3") - elif language == "Python2": - venvName = self.__plugin.getPreferences( - "VirtualEnvironmentNamePy2") else: venvName = "" if venvName: @@ -706,24 +689,17 @@ virtEnv = os.path.dirname(virtEnv) else: virtEnv = "" - else: - # backward compatibility - if language == "Python3": - virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy3") - elif language == "Python2": - virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy2") - else: - virtEnv = "" + if virtEnv and not os.path.exists(virtEnv): virtEnv = "" - return virtEnv + return virtEnv # __IGNORE_WARNING_M834__ def __getDebugEnvironment(self, language=""): """ Private method to get the path of the debugger environment. @param language Python variant to get the debugger environment - for (string, one of '', 'Python2' or 'Python3') + for (string, one of '' or 'Python3') @return path of the debugger environment (string) """ if not language: @@ -733,36 +709,14 @@ if not debugEnv: if language == "Python3": venvName = Preferences.getDebugger("Python3VirtualEnv") - elif language == "Python2": - venvName = Preferences.getDebugger("Python2VirtualEnv") else: venvName = "" if venvName: - debugEnv = self.__virtualEnvManager.getVirtualenvDirectory( + return self.__virtualEnvManager.getVirtualenvDirectory( venvName) - else: - debugEnv = "" - else: - # backward compatibility - if language == "Python3": - debugEnv = Preferences.getDebugger("Python3Interpreter") - if not debugEnv and sys.version_info[0] == 3: - debugEnv = sys.executable - elif language == "Python2": - debugEnv = Preferences.getDebugger("PythonInterpreter") - if not debugEnv and sys.version_info[0] == 2: - debugEnv = sys.executable - else: - debugEnv = sys.executable - debugEnv = os.path.dirname(debugEnv) - if debugEnv and not os.path.exists(debugEnv): - if (language == "Python3" and sys.version_info[0] == 3) or \ - (language == "Python2" and sys.version_info[0] == 2): - debugEnv = sys.exec_prefix - else: - debugEnv = "" - return debugEnv + + return "" def getPyramidCommand(self, cmd, language=""): """ @@ -770,7 +724,7 @@ @param cmd command (string) @param language Python variant to get the virtual environment - for (string, one of '', 'Python2' or 'Python3') + for (string, one of '' or 'Python3') @return full pyramid command (string) """ if not language: @@ -814,69 +768,13 @@ if not venvName: # if none configured, use the global one venvName = Preferences.getDebugger("Python3VirtualEnv") - elif language == "Python2": - venvName = self.__plugin.getPreferences( - "VirtualEnvironmentNamePy2") - if not venvName: - # if none configured, use the global one - venvName = Preferences.getDebugger("Python2VirtualEnv") else: venvName = "" if venvName: - python = self.__virtualEnvManager.getVirtualenvInterpreter( + return self.__virtualEnvManager.getVirtualenvInterpreter( venvName) - else: - python = "" - else: - # backward compatibility - virtualEnv = self.__getVirtualEnvironment() - if isWindowsPlatform(): - pythonExeList = ["python.exe", "pypy.exe"] - if not virtualEnv: - virtualEnv = self.__getDebugEnvironment(language) - for pythonExe in pythonExeList: - for python in [ - os.path.join(virtualEnv, "Scripts", pythonExe), - os.path.join(virtualEnv, "bin", pythonExe), - os.path.join(virtualEnv, pythonExe) - ]: - if os.path.exists(python): - break - else: - python = "" - - if python: - break - else: - python = "" - else: - if language == "Python3": - pythonExeList = ["python3", "pypy3"] - elif language == "Python2": - pythonExeList = ["python2", "pypy2"] - if not virtualEnv: - virtualEnv = self.__getDebugEnvironment(language) - - for pythonExe in pythonExeList: - for python in [ - os.path.join(virtualEnv, "bin", pythonExe), - # omit the version character - os.path.join(virtualEnv, "bin", pythonExe)[:-1], - os.path.join(virtualEnv, pythonExe), - # omit the version character - os.path.join(virtualEnv, pythonExe)[:-1], - ]: - if os.path.exists(python): - break - else: - python = "" - - if python: - break - else: - python = "" - return python + return "" def __pyramidInfo(self): """ @@ -923,7 +821,7 @@ f.close() for line in lines: if line.startswith("__requires__"): - # sample: __requires__ = 'pyramid==1.4' + ## sample: __requires__ = 'pyramid==1.4' vers = line.strip().split()[-1][1:-1].split("==")[1] self.__pyramidVersion = vers except (IOError, OSError): @@ -1042,8 +940,10 @@ projects = [] ppath = self.__e5project.getProjectPath() for entry in os.listdir(ppath): - if entry[0] not in "._" and \ - os.path.isdir(os.path.join(ppath, entry)): + if ( + entry[0] not in "._" and + os.path.isdir(os.path.join(ppath, entry)) + ): projects.append(entry) return projects @@ -1193,8 +1093,8 @@ args.append(os.path.join(projectPath, "development.ini")) if isWindowsPlatform(): - serverProcStarted, pid = \ - QProcess.startDetached(args[0], args[1:], projectPath) + serverProcStarted, pid = QProcess.startDetached( + args[0], args[1:], projectPath) else: if self.__serverProc is not None: self.__serverProcFinished() @@ -1220,8 +1120,10 @@ """ Private slot connected to the finished signal. """ - if self.__serverProc is not None and \ - self.__serverProc.state() != QProcess.NotRunning: + if ( + self.__serverProc is not None and + self.__serverProc.state() != QProcess.NotRunning + ): self.__serverProc.terminate() QTimer.singleShot(2000, self.__serverProc.kill) self.__serverProc.waitForFinished(3000) @@ -1279,13 +1181,7 @@ args = Utilities.parseOptionString(consoleCmd) args[0] = Utilities.getExecutablePath(args[0]) args.append(self.getPyramidCommand("pshell")) - language = self.__e5project.getProjectLanguage() - if language == "Python2": - consoleType = self.__plugin.getPreferences( - "Python2ConsoleType") - else: - consoleType = self.__plugin.getPreferences( - "Python3ConsoleType") + consoleType = self.__plugin.getPreferences("Python3ConsoleType") args.append("--python-shell={0}".format(consoleType)) args.append(os.path.join(projectPath, "development.ini")) @@ -1354,8 +1250,9 @@ ' project created yet. Aborting...')) return - from .DistributionTypeSelectionDialog import \ + from .DistributionTypeSelectionDialog import ( DistributionTypeSelectionDialog + ) dlg = DistributionTypeSelectionDialog(self, projectPath, self.__ui) if dlg.exec_() == QDialog.Accepted: @@ -1538,14 +1435,9 @@ pattern = pattern.replace('\\', '\\\\') match = re.search(pattern, filename) if match is not None: - loc = match.group(1) - return loc - else: - loc = None - else: - loc = None + return match.group(1) - return loc + return None def __normalizeList(self, filenames): """ @@ -1636,8 +1528,8 @@ @param code language code of the new language (string) """ - title = self.tr("Initializing message catalog for '{0}'")\ - .format(code) + title = self.tr( + "Initializing message catalog for '{0}'").format(code) try: projectPath = self.__projectPath() except PyramidNoProjectSelectedException: @@ -1663,8 +1555,8 @@ if res: dia.exec_() - langFile = self.__e5project.getTranslationPattern()\ - .replace("%language%", code) + langFile = self.__e5project.getTranslationPattern().replace( + "%language%", code) self.__e5project.appendFile(langFile) def compileCatalogs(self, filenames):