--- a/ProjectDjango/Project.py Mon Jun 22 19:32:45 2020 +0200 +++ b/ProjectDjango/Project.py Tue Jun 23 17:48:16 2020 +0200 @@ -7,13 +7,6 @@ Module implementing the Django project support. """ -from __future__ import unicode_literals -try: - str = unicode # __IGNORE_WARNING__ -except NameError: - pass - -import sys import os import re import shutil @@ -117,10 +110,7 @@ self.__ui = parent self.__e5project = e5App().getObject("Project") - try: - self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") - except KeyError: - self.__virtualEnvManager = None + self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") self.__hooksInstalled = False self.__menus = {} # dictionary with references to menus @@ -1280,7 +1270,6 @@ return paths - # TODO: eliminate Python2 def supportedPythonVariants(self): """ Public method to get the supported Python variants. @@ -1317,7 +1306,6 @@ return variants - # TODO: eliminate Python2 def __isSuitableForVariant(self, variant, line0): """ Private method to test, if a detected command file is suitable for the @@ -1347,29 +1335,22 @@ """ if not language: language = self.__e5project.getProjectLanguage() - if self.__virtualEnvManager: - if language == "Python3": - venvName = self.__plugin.getPreferences( - "VirtualEnvironmentNamePy3") - else: - venvName = "" - if venvName: - virtEnv = self.__virtualEnvManager.getVirtualenvDirectory( - venvName) - if not virtEnv: - virtEnv = os.path.dirname( - self.__virtualEnvManager.getVirtualenvInterpreter( - venvName)) - if virtEnv.endswith(("Scripts", "bin")): - virtEnv = os.path.dirname(virtEnv) - else: - virtEnv = "" + if language == "Python3": + venvName = self.__plugin.getPreferences( + "VirtualEnvironmentNamePy3") else: - # backward compatibility - if language == "Python3": - virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy3") - else: - virtEnv = "" + venvName = "" + if venvName: + virtEnv = self.__virtualEnvManager.getVirtualenvDirectory( + venvName) + if not virtEnv: + virtEnv = os.path.dirname( + self.__virtualEnvManager.getVirtualenvInterpreter( + venvName)) + if virtEnv.endswith(("Scripts", "bin")): + virtEnv = os.path.dirname(virtEnv) + else: + virtEnv = "" if virtEnv and not os.path.exists(virtEnv): virtEnv = "" return virtEnv @@ -1384,33 +1365,18 @@ """ if not language: language = self.__e5project.getProjectLanguage() - if self.__virtualEnvManager: - debugEnv = self.__getVirtualEnvironment(language) - if not debugEnv: - if language == "Python3": - venvName = Preferences.getDebugger("Python3VirtualEnv") - else: - venvName = "" - - if venvName: - debugEnv = self.__virtualEnvManager.getVirtualenvDirectory( - venvName) - else: - debugEnv = "" - else: - # backward compatibility + debugEnv = self.__getVirtualEnvironment(language) + if not debugEnv: if language == "Python3": - debugEnv = Preferences.getDebugger("Python3Interpreter") - if not debugEnv and sys.version_info[0] >= 3: - debugEnv = sys.executable + venvName = Preferences.getDebugger("Python3VirtualEnv") 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: - debugEnv = sys.exec_prefix - else: - debugEnv = "" + venvName = "" + + if venvName: + debugEnv = self.__virtualEnvManager.getVirtualenvDirectory( + venvName) + else: + debugEnv = "" return debugEnv def __getDjangoAdminCommand(self, language=""): @@ -1488,65 +1454,19 @@ @return python command (string) """ language = self.__e5project.getProjectLanguage() - if self.__virtualEnvManager: - if language == "Python3": - venvName = self.__plugin.getPreferences( - "VirtualEnvironmentNamePy3") - if not venvName: - # if none configured, use the global one - venvName = Preferences.getDebugger("Python3VirtualEnv") - else: - venvName = "" - if venvName: - python = self.__virtualEnvManager.getVirtualenvInterpreter( - venvName) - else: - python = "" + if language == "Python3": + venvName = self.__plugin.getPreferences( + "VirtualEnvironmentNamePy3") + if not venvName: + # if none configured, use the global one + venvName = Preferences.getDebugger("Python3VirtualEnv") 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: - pythonExeList = ["python3", "pypy3"] - 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 = "" + venvName = "" + if venvName: + python = self.__virtualEnvManager.getVirtualenvInterpreter( + venvName) + else: + python = "" return python @@ -2094,23 +2014,12 @@ self.tr('&Current Django project ({0})').format(curSite)) if self.__currentSite is None: - try: - self.__e5project.setTranslationPattern("") - except AttributeError: - # backward compatibility - self.__e5project.pdata["TRANSLATIONPATTERN"] = [] + self.__e5project.setTranslationPattern("") else: - try: - self.__e5project.setTranslationPattern( - os.path.join(site, "locale", "%language%", "LC_MESSAGES", - "django.po") - ) - except AttributeError: - # backward compatibility - self.__e5project.pdata["TRANSLATIONPATTERN"] = [ - os.path.join(site, "locale", "%language%", "LC_MESSAGES", - "django.po") - ] + self.__e5project.setTranslationPattern( + os.path.join(site, "locale", "%language%", "LC_MESSAGES", + "django.po") + ) def __site(self): """