PipInterface/Pip.py

branch
pypi
changeset 6793
cca6a35f3ad2
parent 6792
9dd854f05c83
child 6795
6e2ed2aac325
--- a/PipInterface/Pip.py	Tue Feb 19 19:56:24 2019 +0100
+++ b/PipInterface/Pip.py	Wed Feb 20 19:44:13 2019 +0100
@@ -25,7 +25,6 @@
 from E5Gui.E5Application import e5App
 
 from .PipDialog import PipDialog
-from . import DefaultIndexUrlXml
 
 import Preferences
 import Globals
@@ -37,6 +36,10 @@
     """
     Class implementing the pip GUI logic.
     """
+    DefaultPyPiUrl = "https://pypi.org"
+    DefaultIndexUrlXml = DefaultPyPiUrl + "/pypi"
+    DefaultIndexUrlPip = DefaultPyPiUrl + "/simple"
+    
     def __init__(self, parent=None):
         """
         Constructor
@@ -45,12 +48,12 @@
         @type QObject
         """
         super(Pip, self).__init__(parent)
-        
+##        
 ##        self.__virtualenvManager = e5App().getObject("VirtualEnvManager")
 ##        self.__project = e5App().getObject("Project")
-        
-        self.__menus = {}   # dictionary with references to menus
-        
+##        
+##        self.__menus = {}   # dictionary with references to menus
+##        
 ##        self.__plugin.currentEnvironmentChanged.connect(
 ##            self.__handleTearOffMenu)
     
@@ -60,21 +63,21 @@
         """
         self.actions = []
     
-        self.selectEnvironmentAct = E5Action(
-            self.tr('Virtual Environment for pip'),
-            self.tr('&Virtual Environment for pip'),
-            0, 0,
-            self, 'pip_select_environment')
-        self.selectEnvironmentAct.setStatusTip(self.tr(
-            'Selects the virtual environment to be used for pip'))
-        self.selectEnvironmentAct.setWhatsThis(self.tr(
-            """<b>Virtual Environment for pip</b>"""
-            """<p>This selects the virtual environment to be used for pip."""
-            """</p>"""
-        ))
-        self.selectEnvironmentAct.triggered.connect(self.__selectPipVirtualenv)
-        self.actions.append(self.selectEnvironmentAct)
-        
+##        self.selectEnvironmentAct = E5Action(
+##            self.tr('Virtual Environment for pip'),
+##            self.tr('&Virtual Environment for pip'),
+##            0, 0,
+##            self, 'pip_select_environment')
+##        self.selectEnvironmentAct.setStatusTip(self.tr(
+##            'Selects the virtual environment to be used for pip'))
+##        self.selectEnvironmentAct.setWhatsThis(self.tr(
+##            """<b>Virtual Environment for pip</b>"""
+##            """<p>This selects the virtual environment to be used for pip."""
+##            """</p>"""
+##        ))
+##        self.selectEnvironmentAct.triggered.connect(self.__selectPipVirtualenv)
+##        self.actions.append(self.selectEnvironmentAct)
+##        
 ##        ##############################################
 ##        ## Actions for listing packages
 ##        ##############################################
@@ -284,25 +287,25 @@
             self.__generateRequirements)
         self.actions.append(self.generateRequirementsAct)
         
-        ##############################################
-        ## Actions for generating requirements files
-        ##############################################
-        
-        self.searchPyPIAct = E5Action(
-            self.tr('Search PyPI'),
-            self.tr('&Search PyPI...'),
-            0, 0,
-            self, 'pip_search_pypi')
-        self.searchPyPIAct.setStatusTip(self.tr(
-            'Open a dialog to search the Python Package Index'))
-        self.searchPyPIAct.setWhatsThis(self.tr(
-            """<b>Search PyPI</b>"""
-            """<p>This opens a dialog to search the Python Package"""
-            """ Index.</p>"""
-        ))
-        self.searchPyPIAct.triggered.connect(self.__searchPyPI)
-        self.actions.append(self.searchPyPIAct)
-        
+##        ##############################################
+##        ## Actions for generating requirements files
+##        ##############################################
+##        
+##        self.searchPyPIAct = E5Action(
+##            self.tr('Search PyPI'),
+##            self.tr('&Search PyPI...'),
+##            0, 0,
+##            self, 'pip_search_pypi')
+##        self.searchPyPIAct.setStatusTip(self.tr(
+##            'Open a dialog to search the Python Package Index'))
+##        self.searchPyPIAct.setWhatsThis(self.tr(
+##            """<b>Search PyPI</b>"""
+##            """<p>This opens a dialog to search the Python Package"""
+##            """ Index.</p>"""
+##        ))
+##        self.searchPyPIAct.triggered.connect(self.__searchPyPI)
+##        self.actions.append(self.searchPyPIAct)
+##        
         ##############################################
         ## Actions for editing configuration files
         ##############################################
@@ -361,14 +364,14 @@
         @return the menu generated
         @rtype QMenu
         """
-        self.__menus = {}   # clear menus references
-        
+##        self.__menus = {}   # clear menus references
+##        
         menu = QMenu()
 ##        menu.setTearOffEnabled(True)
 ##        menu.setIcon(UI.PixmapCache.getIcon("pypi.png"))
-        
-        menu.addAction(self.selectEnvironmentAct)
-        menu.addSeparator()
+##        
+##        menu.addAction(self.selectEnvironmentAct)
+##        menu.addSeparator()
 ##        menu.addAction(self.listPackagesAct)
 ##        menu.addAction(self.listUptodatePackagesAct)
 ##        menu.addAction(self.listOutdatedPackagesAct)
@@ -396,8 +399,8 @@
         menu.addSeparator()
         menu.addAction(self.pipConfigAct)
         
-        self.__menus["main"] = menu
-        
+##        self.__menus["main"] = menu
+##        
         menu.aboutToShow.connect(self.__aboutToShowMenu)
         
         return menu
@@ -414,44 +417,44 @@
                            self.editVirtualenvConfigAct,
                            self.pipConfigAct]:
                 act.setEnabled(enable)
-    
-    def getMenu(self, name):
-        """
-        Public method to get a reference to the requested menu.
-        
-        @param name name of the menu
-        @type str
-        @return reference to the menu or None, if no
-            menu with the given name exists
-        @rtype QMenu or None
-        """
-        if name in self.__menus:
-            return self.__menus[name]
-        else:
-            return None
-    
-    def getMenuNames(self):
-        """
-        Public method to get the names of all menus.
-        
-        @return menu names
-        @rtype list of str
-        """
-        return list(self.__menus.keys())
-    
-    def __handleTearOffMenu(self, venvName):
-        """
-        Private slot to handle a change of the selected virtual environment.
-        
-        @param venvName logical name of the virtual environment
-        @type str
-        """
-        if self.__menus["main"].isTearOffMenuVisible():
-            # determine, if torn off menu needs to be refreshed
-            enabled = self.listPackagesAct.isEnabled()
-            if ((bool(venvName) and not enabled) or
-                    (not bool(venvName) and enabled)):
-                self.__menus["main"].hideTearOffMenu()
+##    
+##    def getMenu(self, name):
+##        """
+##        Public method to get a reference to the requested menu.
+##        
+##        @param name name of the menu
+##        @type str
+##        @return reference to the menu or None, if no
+##            menu with the given name exists
+##        @rtype QMenu or None
+##        """
+##        if name in self.__menus:
+##            return self.__menus[name]
+##        else:
+##            return None
+##    
+##    def getMenuNames(self):
+##        """
+##        Public method to get the names of all menus.
+##        
+##        @return menu names
+##        @rtype list of str
+##        """
+##        return list(self.__menus.keys())
+##    
+##    def __handleTearOffMenu(self, venvName):
+##        """
+##        Private slot to handle a change of the selected virtual environment.
+##        
+##        @param venvName logical name of the virtual environment
+##        @type str
+##        """
+##        if self.__menus["main"].isTearOffMenuVisible():
+##            # determine, if torn off menu needs to be refreshed
+##            enabled = self.listPackagesAct.isEnabled()
+##            if ((bool(venvName) and not enabled) or
+##                    (not bool(venvName) and enabled)):
+##                self.__menus["main"].hideTearOffMenu()
     
     ##########################################################################
     ## Methods below implement some utility functions
@@ -559,15 +562,15 @@
         
         return config
     
-    def getDefaultEnvironmentString(self):
-        """
-        Public method to get the string for the default environment.
-        
-        @return string for the default environment
-        @rtype str
-        """
-        return self.tr("<standard>")
-    
+##    def getDefaultEnvironmentString(self):
+##        """
+##        Public method to get the string for the default environment.
+##        
+##        @return string for the default environment
+##        @rtype str
+##        """
+##        return self.tr("<standard>")
+##    
     def getProjectEnvironmentString(self):
         """
         Public method to get the string for the project environment.
@@ -589,14 +592,16 @@
         @return interpreter path
         @rtype str
         """
-        if venvName == self.getDefaultEnvironmentString():
-            venvName = Preferences.getPip("CurrentEnvironment")
-        elif venvName == self.getProjectEnvironmentString():
+##        if venvName == self.getDefaultEnvironmentString():
+##            venvName = Preferences.getPip("CurrentEnvironment")
+        if venvName == self.getProjectEnvironmentString():
             venvName = \
                 e5App().getObject("Project").getDebugProperty("VIRTUALENV")
             if not venvName:
-                # fall back to standard if not defined
-                venvName = Preferences.getPip("CurrentEnvironment")
+                # fall back to interpreter used to run eric6
+                return sys.executable
+##                # fall back to standard if not defined
+##                venvName = Preferences.getPip("CurrentEnvironment")
         
         interpreter = \
             e5App().getObject("VirtualEnvManager").getVirtualenvInterpreter(
@@ -624,66 +629,65 @@
     ## Methods below implement the individual menu entries
     ##########################################################################
     
-    def __selectPipVirtualenv(self):
-        """
-        Private method to select the virtual environment to be used.
-        """
-        environments = self.getVirtualenvNames()
-        if environments:
-            currentEnvironment = Preferences.getPip("CurrentEnvironment")
-            try:
-                index = environments.index(currentEnvironment)
-            except ValueError:
-                index = 0
-            environment, ok = QInputDialog.getItem(
-                None,
-                self.tr("Virtual Environment for pip"),
-                self.tr("Select the virtual environment to be used:"),
-                environments, index, False)
-            
-            if ok and environment:
-                Preferences.getPip("CurrentEnvironment", environment)
-        else:
-            E5MessageBox.warning(
-                None,
-                self.tr("Virtual Environment for pip"),
-                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", Preferences.getPip("PipSearchIndex"),
-            self.tr("Installed Packages"))
-        self.__listDialog.show()
-        self.__listDialog.start()
-    
-    def __listUptodatePackages(self):
-        """
-        Private slot to list all installed, up-to-date packages.
-        """
-        from .PipListDialog import PipListDialog
-        self.__listUptodateDialog = PipListDialog(
-            self, "uptodate", Preferences.getPip("PipSearchIndex"),
-            self.tr("Up-to-date Packages"))
-        self.__listUptodateDialog.show()
-        self.__listUptodateDialog.start()
-    
-    def __listOutdatedPackages(self):
-        """
-        Private slot to list all installed, up-to-date packages.
-        """
-        from .PipListDialog import PipListDialog
-        self.__listOutdatedDialog = PipListDialog(
-            self, "outdated", Preferences.getPip("PipSearchIndex"),
-            self.tr("Outdated Packages"))
-        self.__listOutdatedDialog.show()
-        self.__listOutdatedDialog.start()
-    
+##    def __selectPipVirtualenv(self):
+##        """
+##        Private method to select the virtual environment to be used.
+##        """
+##        environments = self.getVirtualenvNames()
+##        if environments:
+##            currentEnvironment = Preferences.getPip("CurrentEnvironment")
+##            try:
+##                index = environments.index(currentEnvironment)
+##            except ValueError:
+##                index = 0
+##            environment, ok = QInputDialog.getItem(
+##                None,
+##                self.tr("Virtual Environment for pip"),
+##                self.tr("Select the virtual environment to be used:"),
+##                environments, index, False)
+##            
+##            if ok and environment:
+##                Preferences.getPip("CurrentEnvironment", environment)
+##        else:
+##            E5MessageBox.warning(
+##                None,
+##                self.tr("Virtual Environment for pip"),
+##                self.tr("""No virtual environments have been configured yet."""
+##                        """ Please use the Virtualenv Manager to do that."""))
+##    
+##    def __listPackages(self):
+##        """
+##        Private slot to list all installed packages.
+##        """
+##        from .PipListDialog import PipListDialog
+##        self.__listDialog = PipListDialog(
+##            self, "list", Preferences.getPip("PipSearchIndex"),
+##            self.tr("Installed Packages"))
+##        self.__listDialog.show()
+##        self.__listDialog.start()
+##    
+##    def __listUptodatePackages(self):
+##        """
+##        Private slot to list all installed, up-to-date packages.
+##        """
+##        from .PipListDialog import PipListDialog
+##        self.__listUptodateDialog = PipListDialog(
+##            self, "uptodate", Preferences.getPip("PipSearchIndex"),
+##            self.tr("Up-to-date Packages"))
+##        self.__listUptodateDialog.show()
+##        self.__listUptodateDialog.start()
+##    
+##    def __listOutdatedPackages(self):
+##        """
+##        Private slot to list all installed, up-to-date packages.
+##        """
+##        from .PipListDialog import PipListDialog
+##        self.__listOutdatedDialog = PipListDialog(
+##            self, "outdated", Preferences.getPip("PipSearchIndex"),
+##            self.tr("Outdated Packages"))
+##        self.__listOutdatedDialog.show()
+##        self.__listOutdatedDialog.start()
+##    
     def __editUserConfiguration(self):
         """
         Private slot to edit the user configuration.
@@ -1120,19 +1124,47 @@
         self.__freezeDialog.show()
         self.__freezeDialog.start()
     
-    def __searchPyPI(self):
+##    def __searchPyPI(self):
+##        """
+##        Private slot to search the Python Package Index.
+##        """
+##        from .PipSearchDialog import PipSearchDialog
+##        
+##        if Preferences.getPip("PipSearchIndex"):
+##            indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
+##        else:
+##            indexUrl = DefaultIndexUrlXml
+##        
+##        self.__searchDialog = PipSearchDialog(self, indexUrl)
+##        self.__searchDialog.show()
+##    
+    def getIndexUrl(self):
         """
-        Private slot to search the Python Package Index.
+        Public method to get the index URL for PyPI.
+        
+        @return index URL for PyPI
+        @rtype str
         """
-        from .PipSearchDialog import PipSearchDialog
+        if Preferences.getPip("PipSearchIndex"):
+            indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
+        else:
+            indexUrl = Pip.DefaultIndexUrlPip
         
+        return indexUrl
+    
+    def getIndexUrlXml(self):
+        """
+        Public method to get the index URL for XML RPC calls.
+        
+        @return index URL for XML RPC calls
+        @rtype str
+        """
         if Preferences.getPip("PipSearchIndex"):
             indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
         else:
-            indexUrl = DefaultIndexUrlXml
+            indexUrl = Pip.DefaultIndexUrlXml
         
-        self.__searchDialog = PipSearchDialog(self, indexUrl)
-        self.__searchDialog.show()
+        return indexUrl
     
     def getInstalledPackages(self, envName, localPackages=True,
                              notRequired=False, usersite=False):

eric ide

mercurial