ProjectFlask/Project.py

changeset 30
76c86fe13f36
parent 29
a8817ea36587
child 32
80fc8deac8fe
diff -r a8817ea36587 -r 76c86fe13f36 ProjectFlask/Project.py
--- a/ProjectFlask/Project.py	Tue Nov 24 19:23:28 2020 +0100
+++ b/ProjectFlask/Project.py	Tue Nov 24 19:37:56 2020 +0100
@@ -351,7 +351,73 @@
                 self.__formsBrowser.sourceFile.emit(fname)
     
     ##################################################################
-    ## slots below implement general functionality
+    ## methods below implement virtual environment handling
+    ##################################################################
+    
+    def getVirtualEnvironment(self):
+        """
+        Private method to get the path of the virtual environment.
+        
+        @return path of the virtual environment
+        @rtype str
+        """
+        language = self.__e5project.getProjectLanguage()
+        if language == "Python3":
+            venvName = self.__plugin.getPreferences(
+                "VirtualEnvironmentNamePy3")
+        else:
+            venvName = ""
+        if venvName:
+            virtEnv = self.__virtualEnvManager.getVirtualenvDirectory(
+                venvName)
+        else:
+            virtEnv = ""
+        
+        if virtEnv and not os.path.exists(virtEnv):
+            virtEnv = ""
+        
+        return virtEnv      # __IGNORE_WARNING_M834__
+    
+    def getVirtualenvInterpreter(self):
+        """
+        Public method to get the path of the Python interpreter to be used
+        with the current project.
+        
+        @return path of the Python interpreter
+        @rtype str
+        """
+        return self.getFullCommand("python")
+    
+    def getFullCommand(self, command):
+        """
+        Public method to get the full command for a given command name.
+        
+        @param command command name
+        @type str
+        @return full command
+        @rtype str
+        """
+        virtualEnv = self.getVirtualEnvironment()
+        if isWindowsPlatform():
+            fullCmds = [
+                os.path.join(virtualEnv, "Scripts", command + '.exe'),
+                os.path.join(virtualEnv, "bin", command + '.exe'),
+                command     # fall back to just cmd
+            ]
+        else:
+            fullCmds = [
+                os.path.join(virtualEnv, "bin", command),
+                os.path.join(virtualEnv, "local", "bin", command),
+                Utilities.getExecutablePath(command),
+                command     # fall back to just cmd
+            ]
+        for command in fullCmds:
+            if os.path.exists(command):
+                break
+        return command
+    
+    ##################################################################
+    ## methods below implement general functionality
     ##################################################################
     
     def projectClosed(self):
@@ -371,7 +437,7 @@
         """
         variants = []
         
-        virtEnv = self.__getVirtualEnvironment()
+        virtEnv = self.getVirtualEnvironment()
         if virtEnv:
             fullCmd = self.getFlaskCommand()
             if fullCmd:
@@ -414,30 +480,6 @@
         
         return ok
     
-    def __getVirtualEnvironment(self):
-        """
-        Private method to get the path of the virtual environment.
-        
-        @return path of the virtual environment
-        @rtype str
-        """
-        language = self.__e5project.getProjectLanguage()
-        if language == "Python3":
-            venvName = self.__plugin.getPreferences(
-                "VirtualEnvironmentNamePy3")
-        else:
-            venvName = ""
-        if venvName:
-            virtEnv = self.__virtualEnvManager.getVirtualenvDirectory(
-                venvName)
-        else:
-            virtEnv = ""
-        
-        if virtEnv and not os.path.exists(virtEnv):
-            virtEnv = ""
-        
-        return virtEnv      # __IGNORE_WARNING_M834__
-    
     def getFlaskCommand(self):
         """
         Public method to build the Flask command.
@@ -447,34 +489,6 @@
         """
         return self.getFullCommand("flask")
     
-    def getFullCommand(self, command):
-        """
-        Public method to get the full command for a given command name.
-        
-        @param command command name
-        @type str
-        @return full command
-        @rtype str
-        """
-        virtualEnv = self.__getVirtualEnvironment()
-        if isWindowsPlatform():
-            fullCmds = [
-                os.path.join(virtualEnv, "Scripts", command + '.exe'),
-                os.path.join(virtualEnv, "bin", command + '.exe'),
-                command     # fall back to just cmd
-            ]
-        else:
-            fullCmds = [
-                os.path.join(virtualEnv, "bin", command),
-                os.path.join(virtualEnv, "local", "bin", command),
-                Utilities.getExecutablePath(command),
-                command     # fall back to just cmd
-            ]
-        for command in fullCmds:
-            if os.path.exists(command):
-                break
-        return command
-    
     @pyqtSlot()
     def __flaskInfo(self):
         """

eric ide

mercurial