PipInterface/Pip.py

branch
pypi
changeset 6785
058d63c537a4
parent 6782
390a45748883
child 6792
9dd854f05c83
--- a/PipInterface/Pip.py	Mon Feb 18 19:17:04 2019 +0100
+++ b/PipInterface/Pip.py	Mon Feb 18 19:49:43 2019 +0100
@@ -28,35 +28,30 @@
 
 import Preferences
 import Globals
-
-import UI.PixmapCache
+##
+##import UI.PixmapCache
 
 
 class Pip(QObject):
     """
     Class implementing the pip GUI logic.
     """
-    def __init__(self, plugin, parent=None):
+    def __init__(self, parent=None):
         """
         Constructor
         
-        @param plugin reference to the plugin object
-        @type PipInterfacePlugin
         @param parent parent
         @type QObject
         """
         super(Pip, self).__init__(parent)
         
-        self.__plugin = plugin
-        self.__ui = parent
-        
         self.__virtualenvManager = e5App().getObject("VirtualEnvManager")
-        self.__project = e5App().getObject("Project")
+##        self.__project = e5App().getObject("Project")
         
         self.__menus = {}   # dictionary with references to menus
         
-        self.__plugin.currentEnvironmentChanged.connect(
-            self.__handleTearOffMenu)
+##        self.__plugin.currentEnvironmentChanged.connect(
+##            self.__handleTearOffMenu)
     
     def initActions(self):
         """
@@ -79,57 +74,57 @@
         self.selectEnvironmentAct.triggered.connect(self.__selectPipVirtualenv)
         self.actions.append(self.selectEnvironmentAct)
         
-        ##############################################
-        ## Actions for listing packages
-        ##############################################
-        
-        self.listPackagesAct = E5Action(
-            self.tr('List Installed Packages'),
-            self.tr('&List Installed Packages...'),
-            0, 0,
-            self, 'pip_list_packages')
-        self.listPackagesAct.setStatusTip(self.tr(
-            'List all installed packages with versions'))
-        self.listPackagesAct.setWhatsThis(self.tr(
-            """<b>List Installed Packages</b>"""
-            """<p>This lists all the installed packages together"""
-            """ with their versions.</p>"""
-        ))
-        self.listPackagesAct.triggered.connect(self.__listPackages)
-        self.actions.append(self.listPackagesAct)
-        
-        self.listUptodatePackagesAct = E5Action(
-            self.tr('List Up-to-date Packages'),
-            self.tr('List Up-to-&date Packages...'),
-            0, 0,
-            self, 'pip_list_uptodate_packages')
-        self.listUptodatePackagesAct.setStatusTip(self.tr(
-            'List all installed, up-to-date packages with versions'))
-        self.listUptodatePackagesAct.setWhatsThis(self.tr(
-            """<b>List Up-to-date Packages</b>"""
-            """<p>This lists all the installed, up-to-date packages together"""
-            """ with their versions.</p>"""
-        ))
-        self.listUptodatePackagesAct.triggered.connect(
-            self.__listUptodatePackages)
-        self.actions.append(self.listUptodatePackagesAct)
-        
-        self.listOutdatedPackagesAct = E5Action(
-            self.tr('List Outdated Packages'),
-            self.tr('List &Outdated Packages...'),
-            0, 0,
-            self, 'pip_list_outdated_packages')
-        self.listOutdatedPackagesAct.setStatusTip(self.tr(
-            'List all installed, outdated packages with versions'))
-        self.listOutdatedPackagesAct.setWhatsThis(self.tr(
-            """<b>List Up-to-date Packages</b>"""
-            """<p>This lists all the installed, outdated packages together"""
-            """ with their current and latest versions.</p>"""
-        ))
-        self.listOutdatedPackagesAct.triggered.connect(
-            self.__listOutdatedPackages)
-        self.actions.append(self.listOutdatedPackagesAct)
-        
+##        ##############################################
+##        ## Actions for listing packages
+##        ##############################################
+##        
+##        self.listPackagesAct = E5Action(
+##            self.tr('List Installed Packages'),
+##            self.tr('&List Installed Packages...'),
+##            0, 0,
+##            self, 'pip_list_packages')
+##        self.listPackagesAct.setStatusTip(self.tr(
+##            'List all installed packages with versions'))
+##        self.listPackagesAct.setWhatsThis(self.tr(
+##            """<b>List Installed Packages</b>"""
+##            """<p>This lists all the installed packages together"""
+##            """ with their versions.</p>"""
+##        ))
+##        self.listPackagesAct.triggered.connect(self.__listPackages)
+##        self.actions.append(self.listPackagesAct)
+##        
+##        self.listUptodatePackagesAct = E5Action(
+##            self.tr('List Up-to-date Packages'),
+##            self.tr('List Up-to-&date Packages...'),
+##            0, 0,
+##            self, 'pip_list_uptodate_packages')
+##        self.listUptodatePackagesAct.setStatusTip(self.tr(
+##            'List all installed, up-to-date packages with versions'))
+##        self.listUptodatePackagesAct.setWhatsThis(self.tr(
+##            """<b>List Up-to-date Packages</b>"""
+##            """<p>This lists all the installed, up-to-date packages together"""
+##            """ with their versions.</p>"""
+##        ))
+##        self.listUptodatePackagesAct.triggered.connect(
+##            self.__listUptodatePackages)
+##        self.actions.append(self.listUptodatePackagesAct)
+##        
+##        self.listOutdatedPackagesAct = E5Action(
+##            self.tr('List Outdated Packages'),
+##            self.tr('List &Outdated Packages...'),
+##            0, 0,
+##            self, 'pip_list_outdated_packages')
+##        self.listOutdatedPackagesAct.setStatusTip(self.tr(
+##            'List all installed, outdated packages with versions'))
+##        self.listOutdatedPackagesAct.setWhatsThis(self.tr(
+##            """<b>List Up-to-date Packages</b>"""
+##            """<p>This lists all the installed, outdated packages together"""
+##            """ with their current and latest versions.</p>"""
+##        ))
+##        self.listOutdatedPackagesAct.triggered.connect(
+##            self.__listOutdatedPackages)
+##        self.actions.append(self.listOutdatedPackagesAct)
+##        
         ##############################################
         ## Actions for installing packages
         ##############################################
@@ -367,16 +362,16 @@
         """
         self.__menus = {}   # clear menus references
         
-        menu = QMenu(self.tr('P&ython Package Management'), self.__ui)
-        menu.setTearOffEnabled(True)
-        menu.setIcon(UI.PixmapCache.getIcon("pypi.png"))
+        menu = QMenu()
+##        menu.setTearOffEnabled(True)
+##        menu.setIcon(UI.PixmapCache.getIcon("pypi.png"))
         
         menu.addAction(self.selectEnvironmentAct)
         menu.addSeparator()
-        menu.addAction(self.listPackagesAct)
-        menu.addAction(self.listUptodatePackagesAct)
-        menu.addAction(self.listOutdatedPackagesAct)
-        menu.addSeparator()
+##        menu.addAction(self.listPackagesAct)
+##        menu.addAction(self.listUptodatePackagesAct)
+##        menu.addAction(self.listOutdatedPackagesAct)
+##        menu.addSeparator()
         menu.addAction(self.installPipAct)
         menu.addSeparator()
         menu.addAction(self.installPackagesAct)
@@ -384,15 +379,15 @@
         menu.addAction(self.installRequirementsAct)
         menu.addSeparator()
         menu.addAction(self.upgradePipAct)
-        menu.addAction(self.upgradePackagesAct)
+##        menu.addAction(self.upgradePackagesAct)
         menu.addSeparator()
-        menu.addAction(self.uninstallPackagesAct)
+##        menu.addAction(self.uninstallPackagesAct)
         menu.addAction(self.uninstallRequirementsAct)
         menu.addSeparator()
         menu.addAction(self.generateRequirementsAct)
         menu.addSeparator()
-        menu.addAction(self.searchPyPIAct)
-        menu.addSeparator()
+##        menu.addAction(self.searchPyPIAct)
+##        menu.addSeparator()
         menu.addAction(self.repairPipAct)
         menu.addSeparator()
         menu.addAction(self.editUserConfigAct)
@@ -410,7 +405,7 @@
         """
         Private slot to set the action enabled status.
         """
-        enable = bool(self.__plugin.getPreferences("CurrentEnvironment"))
+        enable = bool(Preferences.getPip("CurrentEnvironment"))
         for act in self.actions:
             if act not in [self.selectEnvironmentAct,
                            self.installPipAct,
@@ -546,17 +541,22 @@
         try:
             venvDirectory = os.environ["VIRTUAL_ENV"]
         except KeyError:
-            venvName = self.__plugin.getPreferences("CurrentEnvironment")
+            venvName = Preferences.getPip("CurrentEnvironment")
             if not venvName:
                 self.__selectPipVirtualenv()
-                venvName = self.__plugin.getPreferences("CurrentEnvironment")
+                venvName = Preferences.getPip("CurrentEnvironment")
             if self.__virtualenvManager.isGlobalEnvironment(venvName):
                 venvDirectory = self.__getUserConfig()
             else:
                 venvDirectory = \
                     self.__virtualenvManager.getVirtualenvDirectory(venvName)
         
-        return os.path.join(venvDirectory, pip)
+        if venvDirectory:
+            config = os.path.join(venvDirectory, pip)
+        else:
+            config = ""
+        
+        return config
     
     def getDefaultEnvironmentString(self):
         """
@@ -574,7 +574,7 @@
         @return string for the project environment
         @rtype str
         """
-        if self.__project.isOpen():
+        if e5App().getObject("Project").isOpen():
             return self.tr("<project>")
         else:
             return ""
@@ -589,12 +589,12 @@
         @rtype str
         """
         if venvName == self.getDefaultEnvironmentString():
-            venvName = self.__plugin.getPreferences("CurrentEnvironment")
+            venvName = Preferences.getPip("CurrentEnvironment")
         elif venvName == self.getProjectEnvironmentString():
-            venvName = self.__project.getDebugProperty("VIRTUALENV")
+            venvName = e5App().getObject("Project").getDebugProperty("VIRTUALENV")
             if not venvName:
                 # fall back to standard if not defined
-                venvName = self.__plugin.getPreferences("CurrentEnvironment")
+                venvName = Preferences.getPip("CurrentEnvironment")
         
         interpreter = self.__virtualenvManager.getVirtualenvInterpreter(
             venvName)
@@ -626,8 +626,7 @@
         """
         environments = self.getVirtualenvNames()
         if environments:
-            currentEnvironment = self.__plugin.getPreferences(
-                "CurrentEnvironment")
+            currentEnvironment = Preferences.getPip("CurrentEnvironment")
             try:
                 index = environments.index(currentEnvironment)
             except ValueError:
@@ -639,8 +638,7 @@
                 environments, index, False)
             
             if ok and environment:
-                self.__plugin.setPreferences("CurrentEnvironment",
-                                             environment)
+                Preferences.getPip("CurrentEnvironment", environment)
         else:
             E5MessageBox.warning(
                 None,
@@ -648,13 +646,14 @@
                 self.tr("""No virtual environments have been configured yet."""
                         """ Please use the Virtualenv Manager to do that."""))
     
+    # TODO: move these three to the widget
     def __listPackages(self):
         """
         Private slot to list all installed packages.
         """
         from .PipListDialog import PipListDialog
         self.__listDialog = PipListDialog(
-            self, "list", self.__plugin.getPreferences("PipSearchIndex"),
+            self, "list", Preferences.getPip("PipSearchIndex"),
             self.tr("Installed Packages"))
         self.__listDialog.show()
         self.__listDialog.start()
@@ -665,7 +664,7 @@
         """
         from .PipListDialog import PipListDialog
         self.__listUptodateDialog = PipListDialog(
-            self, "uptodate", self.__plugin.getPreferences("PipSearchIndex"),
+            self, "uptodate", Preferences.getPip("PipSearchIndex"),
             self.tr("Up-to-date Packages"))
         self.__listUptodateDialog.show()
         self.__listUptodateDialog.start()
@@ -676,7 +675,7 @@
         """
         from .PipListDialog import PipListDialog
         self.__listOutdatedDialog = PipListDialog(
-            self, "outdated", self.__plugin.getPreferences("PipSearchIndex"),
+            self, "outdated", Preferences.getPip("PipSearchIndex"),
             self.tr("Outdated Packages"))
         self.__listOutdatedDialog.show()
         self.__listOutdatedDialog.start()
@@ -704,6 +703,8 @@
         from QScintilla.MiniEditor import MiniEditor
         if virtualenv:
             cfgFile = self.__getVirtualenvConfig()
+            if not cfgFile:
+                return
         else:
             cfgFile = self.__getUserConfig()
         cfgDir = os.path.dirname(cfgFile)
@@ -770,9 +771,8 @@
             commands = [(interpreter, ["-m", "ensurepip", "--user"])]
         else:
             commands = [(interpreter, ["-m", "ensurepip"])]
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = \
-                self.__plugin.getPreferences("PipSearchIndex") + "/simple"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl,
                     "--upgrade"]
         else:
@@ -814,9 +814,8 @@
         if not interpreter:
             return
         
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = \
-                self.__plugin.getPreferences("PipSearchIndex") + "/simple"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl,
                     "--upgrade"]
         else:
@@ -850,9 +849,8 @@
             return
         
         # python -m pip install --ignore-installed pip
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = \
-                self.__plugin.getPreferences("PipSearchIndex") + "/simple"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl,
                     "--ignore-installed"]
         else:
@@ -910,14 +908,13 @@
             return False
         
         if not venvName:
-            venvName = self.__plugin.getPreferences("CurrentEnvironment")
+            venvName = Preferences.getPip("CurrentEnvironment")
         interpreter = self.getVirtualenvInterpreter(venvName)
         if not interpreter:
             return
         
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = \
-                self.__plugin.getPreferences("PipSearchIndex") + "/simple"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl,
                     "--upgrade"]
         else:
@@ -956,14 +953,13 @@
         @type bool
         """
         if not venvName:
-            venvName = self.__plugin.getPreferences("CurrentEnvironment")
+            venvName = Preferences.getPip("CurrentEnvironment")
         interpreter = self.getVirtualenvInterpreter(venvName)
         if not interpreter:
             return
         
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = \
-                self.__plugin.getPreferences("PipSearchIndex") + "/simple"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
             args = ["-m", "pip", "install", "--index-url", indexUrl]
         else:
             args = ["-m", "pip", "install"]
@@ -1012,9 +1008,8 @@
                 interpreter = self.getVirtualenvInterpreter(venvName)
                 if not interpreter:
                     return
-                if self.__plugin.getPreferences("PipSearchIndex"):
-                    indexUrl = \
-                        self.__plugin.getPreferences("PipSearchIndex") + \
+                if Preferences.getPip("PipSearchIndex"):
+                    indexUrl = Preferences.getPip("PipSearchIndex") + \
                         "/simple"
                     args = ["-m", "pip", "install", "--index-url", indexUrl]
                 else:
@@ -1050,8 +1045,7 @@
                 packages)
             if dlg.exec_() == QDialog.Accepted:
                 if not venvName:
-                    venvName = self.__plugin.getPreferences(
-                        "CurrentEnvironment")
+                    venvName = Preferences.getPip("CurrentEnvironment")
                 interpreter = self.getVirtualenvInterpreter(venvName)
                 if not interpreter:
                     return
@@ -1101,8 +1095,7 @@
                     reqs)
                 if dlg.exec_() == QDialog.Accepted:
                     if not venvName:
-                        venvName = self.__plugin.getPreferences(
-                            "CurrentEnvironment")
+                        venvName = Preferences.getPip("CurrentEnvironment")
                     interpreter = self.getVirtualenvInterpreter(venvName)
                     if not interpreter:
                         return
@@ -1129,8 +1122,8 @@
         """
         from .PipSearchDialog import PipSearchDialog
         
-        if self.__plugin.getPreferences("PipSearchIndex"):
-            indexUrl = self.__plugin.getPreferences("PipSearchIndex") + "/pypi"
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
         else:
             indexUrl = DefaultIndexUrlXml
         

eric ide

mercurial