PipInterface/Pip.py

branch
pypi
changeset 6793
cca6a35f3ad2
parent 6792
9dd854f05c83
child 6795
6e2ed2aac325
equal deleted inserted replaced
6792:9dd854f05c83 6793:cca6a35f3ad2
23 from E5Gui import E5MessageBox 23 from E5Gui import E5MessageBox
24 from E5Gui.E5Action import E5Action 24 from E5Gui.E5Action import E5Action
25 from E5Gui.E5Application import e5App 25 from E5Gui.E5Application import e5App
26 26
27 from .PipDialog import PipDialog 27 from .PipDialog import PipDialog
28 from . import DefaultIndexUrlXml
29 28
30 import Preferences 29 import Preferences
31 import Globals 30 import Globals
32 ## 31 ##
33 ##import UI.PixmapCache 32 ##import UI.PixmapCache
35 34
36 class Pip(QObject): 35 class Pip(QObject):
37 """ 36 """
38 Class implementing the pip GUI logic. 37 Class implementing the pip GUI logic.
39 """ 38 """
39 DefaultPyPiUrl = "https://pypi.org"
40 DefaultIndexUrlXml = DefaultPyPiUrl + "/pypi"
41 DefaultIndexUrlPip = DefaultPyPiUrl + "/simple"
42
40 def __init__(self, parent=None): 43 def __init__(self, parent=None):
41 """ 44 """
42 Constructor 45 Constructor
43 46
44 @param parent parent 47 @param parent parent
45 @type QObject 48 @type QObject
46 """ 49 """
47 super(Pip, self).__init__(parent) 50 super(Pip, self).__init__(parent)
48 51 ##
49 ## self.__virtualenvManager = e5App().getObject("VirtualEnvManager") 52 ## self.__virtualenvManager = e5App().getObject("VirtualEnvManager")
50 ## self.__project = e5App().getObject("Project") 53 ## self.__project = e5App().getObject("Project")
51 54 ##
52 self.__menus = {} # dictionary with references to menus 55 ## self.__menus = {} # dictionary with references to menus
53 56 ##
54 ## self.__plugin.currentEnvironmentChanged.connect( 57 ## self.__plugin.currentEnvironmentChanged.connect(
55 ## self.__handleTearOffMenu) 58 ## self.__handleTearOffMenu)
56 59
57 def initActions(self): 60 def initActions(self):
58 """ 61 """
59 Public method to define the actions. 62 Public method to define the actions.
60 """ 63 """
61 self.actions = [] 64 self.actions = []
62 65
63 self.selectEnvironmentAct = E5Action( 66 ## self.selectEnvironmentAct = E5Action(
64 self.tr('Virtual Environment for pip'), 67 ## self.tr('Virtual Environment for pip'),
65 self.tr('&Virtual Environment for pip'), 68 ## self.tr('&Virtual Environment for pip'),
66 0, 0, 69 ## 0, 0,
67 self, 'pip_select_environment') 70 ## self, 'pip_select_environment')
68 self.selectEnvironmentAct.setStatusTip(self.tr( 71 ## self.selectEnvironmentAct.setStatusTip(self.tr(
69 'Selects the virtual environment to be used for pip')) 72 ## 'Selects the virtual environment to be used for pip'))
70 self.selectEnvironmentAct.setWhatsThis(self.tr( 73 ## self.selectEnvironmentAct.setWhatsThis(self.tr(
71 """<b>Virtual Environment for pip</b>""" 74 ## """<b>Virtual Environment for pip</b>"""
72 """<p>This selects the virtual environment to be used for pip.""" 75 ## """<p>This selects the virtual environment to be used for pip."""
73 """</p>""" 76 ## """</p>"""
74 )) 77 ## ))
75 self.selectEnvironmentAct.triggered.connect(self.__selectPipVirtualenv) 78 ## self.selectEnvironmentAct.triggered.connect(self.__selectPipVirtualenv)
76 self.actions.append(self.selectEnvironmentAct) 79 ## self.actions.append(self.selectEnvironmentAct)
77 80 ##
78 ## ############################################## 81 ## ##############################################
79 ## ## Actions for listing packages 82 ## ## Actions for listing packages
80 ## ############################################## 83 ## ##############################################
81 ## 84 ##
82 ## self.listPackagesAct = E5Action( 85 ## self.listPackagesAct = E5Action(
282 )) 285 ))
283 self.generateRequirementsAct.triggered.connect( 286 self.generateRequirementsAct.triggered.connect(
284 self.__generateRequirements) 287 self.__generateRequirements)
285 self.actions.append(self.generateRequirementsAct) 288 self.actions.append(self.generateRequirementsAct)
286 289
287 ############################################## 290 ## ##############################################
288 ## Actions for generating requirements files 291 ## ## Actions for generating requirements files
289 ############################################## 292 ## ##############################################
290 293 ##
291 self.searchPyPIAct = E5Action( 294 ## self.searchPyPIAct = E5Action(
292 self.tr('Search PyPI'), 295 ## self.tr('Search PyPI'),
293 self.tr('&Search PyPI...'), 296 ## self.tr('&Search PyPI...'),
294 0, 0, 297 ## 0, 0,
295 self, 'pip_search_pypi') 298 ## self, 'pip_search_pypi')
296 self.searchPyPIAct.setStatusTip(self.tr( 299 ## self.searchPyPIAct.setStatusTip(self.tr(
297 'Open a dialog to search the Python Package Index')) 300 ## 'Open a dialog to search the Python Package Index'))
298 self.searchPyPIAct.setWhatsThis(self.tr( 301 ## self.searchPyPIAct.setWhatsThis(self.tr(
299 """<b>Search PyPI</b>""" 302 ## """<b>Search PyPI</b>"""
300 """<p>This opens a dialog to search the Python Package""" 303 ## """<p>This opens a dialog to search the Python Package"""
301 """ Index.</p>""" 304 ## """ Index.</p>"""
302 )) 305 ## ))
303 self.searchPyPIAct.triggered.connect(self.__searchPyPI) 306 ## self.searchPyPIAct.triggered.connect(self.__searchPyPI)
304 self.actions.append(self.searchPyPIAct) 307 ## self.actions.append(self.searchPyPIAct)
305 308 ##
306 ############################################## 309 ##############################################
307 ## Actions for editing configuration files 310 ## Actions for editing configuration files
308 ############################################## 311 ##############################################
309 312
310 self.editUserConfigAct = E5Action( 313 self.editUserConfigAct = E5Action(
359 Public slot to initialize the menu. 362 Public slot to initialize the menu.
360 363
361 @return the menu generated 364 @return the menu generated
362 @rtype QMenu 365 @rtype QMenu
363 """ 366 """
364 self.__menus = {} # clear menus references 367 ## self.__menus = {} # clear menus references
365 368 ##
366 menu = QMenu() 369 menu = QMenu()
367 ## menu.setTearOffEnabled(True) 370 ## menu.setTearOffEnabled(True)
368 ## menu.setIcon(UI.PixmapCache.getIcon("pypi.png")) 371 ## menu.setIcon(UI.PixmapCache.getIcon("pypi.png"))
369 372 ##
370 menu.addAction(self.selectEnvironmentAct) 373 ## menu.addAction(self.selectEnvironmentAct)
371 menu.addSeparator() 374 ## menu.addSeparator()
372 ## menu.addAction(self.listPackagesAct) 375 ## menu.addAction(self.listPackagesAct)
373 ## menu.addAction(self.listUptodatePackagesAct) 376 ## menu.addAction(self.listUptodatePackagesAct)
374 ## menu.addAction(self.listOutdatedPackagesAct) 377 ## menu.addAction(self.listOutdatedPackagesAct)
375 ## menu.addSeparator() 378 ## menu.addSeparator()
376 menu.addAction(self.installPipAct) 379 menu.addAction(self.installPipAct)
394 menu.addAction(self.editUserConfigAct) 397 menu.addAction(self.editUserConfigAct)
395 menu.addAction(self.editVirtualenvConfigAct) 398 menu.addAction(self.editVirtualenvConfigAct)
396 menu.addSeparator() 399 menu.addSeparator()
397 menu.addAction(self.pipConfigAct) 400 menu.addAction(self.pipConfigAct)
398 401
399 self.__menus["main"] = menu 402 ## self.__menus["main"] = menu
400 403 ##
401 menu.aboutToShow.connect(self.__aboutToShowMenu) 404 menu.aboutToShow.connect(self.__aboutToShowMenu)
402 405
403 return menu 406 return menu
404 407
405 def __aboutToShowMenu(self): 408 def __aboutToShowMenu(self):
412 self.installPipAct, 415 self.installPipAct,
413 self.editUserConfigAct, 416 self.editUserConfigAct,
414 self.editVirtualenvConfigAct, 417 self.editVirtualenvConfigAct,
415 self.pipConfigAct]: 418 self.pipConfigAct]:
416 act.setEnabled(enable) 419 act.setEnabled(enable)
417 420 ##
418 def getMenu(self, name): 421 ## def getMenu(self, name):
419 """ 422 ## """
420 Public method to get a reference to the requested menu. 423 ## Public method to get a reference to the requested menu.
421 424 ##
422 @param name name of the menu 425 ## @param name name of the menu
423 @type str 426 ## @type str
424 @return reference to the menu or None, if no 427 ## @return reference to the menu or None, if no
425 menu with the given name exists 428 ## menu with the given name exists
426 @rtype QMenu or None 429 ## @rtype QMenu or None
427 """ 430 ## """
428 if name in self.__menus: 431 ## if name in self.__menus:
429 return self.__menus[name] 432 ## return self.__menus[name]
430 else: 433 ## else:
431 return None 434 ## return None
432 435 ##
433 def getMenuNames(self): 436 ## def getMenuNames(self):
434 """ 437 ## """
435 Public method to get the names of all menus. 438 ## Public method to get the names of all menus.
436 439 ##
437 @return menu names 440 ## @return menu names
438 @rtype list of str 441 ## @rtype list of str
439 """ 442 ## """
440 return list(self.__menus.keys()) 443 ## return list(self.__menus.keys())
441 444 ##
442 def __handleTearOffMenu(self, venvName): 445 ## def __handleTearOffMenu(self, venvName):
443 """ 446 ## """
444 Private slot to handle a change of the selected virtual environment. 447 ## Private slot to handle a change of the selected virtual environment.
445 448 ##
446 @param venvName logical name of the virtual environment 449 ## @param venvName logical name of the virtual environment
447 @type str 450 ## @type str
448 """ 451 ## """
449 if self.__menus["main"].isTearOffMenuVisible(): 452 ## if self.__menus["main"].isTearOffMenuVisible():
450 # determine, if torn off menu needs to be refreshed 453 ## # determine, if torn off menu needs to be refreshed
451 enabled = self.listPackagesAct.isEnabled() 454 ## enabled = self.listPackagesAct.isEnabled()
452 if ((bool(venvName) and not enabled) or 455 ## if ((bool(venvName) and not enabled) or
453 (not bool(venvName) and enabled)): 456 ## (not bool(venvName) and enabled)):
454 self.__menus["main"].hideTearOffMenu() 457 ## self.__menus["main"].hideTearOffMenu()
455 458
456 ########################################################################## 459 ##########################################################################
457 ## Methods below implement some utility functions 460 ## Methods below implement some utility functions
458 ########################################################################## 461 ##########################################################################
459 462
557 else: 560 else:
558 config = "" 561 config = ""
559 562
560 return config 563 return config
561 564
562 def getDefaultEnvironmentString(self): 565 ## def getDefaultEnvironmentString(self):
563 """ 566 ## """
564 Public method to get the string for the default environment. 567 ## Public method to get the string for the default environment.
565 568 ##
566 @return string for the default environment 569 ## @return string for the default environment
567 @rtype str 570 ## @rtype str
568 """ 571 ## """
569 return self.tr("<standard>") 572 ## return self.tr("<standard>")
570 573 ##
571 def getProjectEnvironmentString(self): 574 def getProjectEnvironmentString(self):
572 """ 575 """
573 Public method to get the string for the project environment. 576 Public method to get the string for the project environment.
574 577
575 @return string for the project environment 578 @return string for the project environment
587 @param venvName logical name for the virtual environment 590 @param venvName logical name for the virtual environment
588 @type str 591 @type str
589 @return interpreter path 592 @return interpreter path
590 @rtype str 593 @rtype str
591 """ 594 """
592 if venvName == self.getDefaultEnvironmentString(): 595 ## if venvName == self.getDefaultEnvironmentString():
593 venvName = Preferences.getPip("CurrentEnvironment") 596 ## venvName = Preferences.getPip("CurrentEnvironment")
594 elif venvName == self.getProjectEnvironmentString(): 597 if venvName == self.getProjectEnvironmentString():
595 venvName = \ 598 venvName = \
596 e5App().getObject("Project").getDebugProperty("VIRTUALENV") 599 e5App().getObject("Project").getDebugProperty("VIRTUALENV")
597 if not venvName: 600 if not venvName:
598 # fall back to standard if not defined 601 # fall back to interpreter used to run eric6
599 venvName = Preferences.getPip("CurrentEnvironment") 602 return sys.executable
603 ## # fall back to standard if not defined
604 ## venvName = Preferences.getPip("CurrentEnvironment")
600 605
601 interpreter = \ 606 interpreter = \
602 e5App().getObject("VirtualEnvManager").getVirtualenvInterpreter( 607 e5App().getObject("VirtualEnvManager").getVirtualenvInterpreter(
603 venvName) 608 venvName)
604 if not interpreter: 609 if not interpreter:
622 627
623 ########################################################################## 628 ##########################################################################
624 ## Methods below implement the individual menu entries 629 ## Methods below implement the individual menu entries
625 ########################################################################## 630 ##########################################################################
626 631
627 def __selectPipVirtualenv(self): 632 ## def __selectPipVirtualenv(self):
628 """ 633 ## """
629 Private method to select the virtual environment to be used. 634 ## Private method to select the virtual environment to be used.
630 """ 635 ## """
631 environments = self.getVirtualenvNames() 636 ## environments = self.getVirtualenvNames()
632 if environments: 637 ## if environments:
633 currentEnvironment = Preferences.getPip("CurrentEnvironment") 638 ## currentEnvironment = Preferences.getPip("CurrentEnvironment")
634 try: 639 ## try:
635 index = environments.index(currentEnvironment) 640 ## index = environments.index(currentEnvironment)
636 except ValueError: 641 ## except ValueError:
637 index = 0 642 ## index = 0
638 environment, ok = QInputDialog.getItem( 643 ## environment, ok = QInputDialog.getItem(
639 None, 644 ## None,
640 self.tr("Virtual Environment for pip"), 645 ## self.tr("Virtual Environment for pip"),
641 self.tr("Select the virtual environment to be used:"), 646 ## self.tr("Select the virtual environment to be used:"),
642 environments, index, False) 647 ## environments, index, False)
643 648 ##
644 if ok and environment: 649 ## if ok and environment:
645 Preferences.getPip("CurrentEnvironment", environment) 650 ## Preferences.getPip("CurrentEnvironment", environment)
646 else: 651 ## else:
647 E5MessageBox.warning( 652 ## E5MessageBox.warning(
648 None, 653 ## None,
649 self.tr("Virtual Environment for pip"), 654 ## self.tr("Virtual Environment for pip"),
650 self.tr("""No virtual environments have been configured yet.""" 655 ## self.tr("""No virtual environments have been configured yet."""
651 """ Please use the Virtualenv Manager to do that.""")) 656 ## """ Please use the Virtualenv Manager to do that."""))
652 657 ##
653 # TODO: move these three to the widget 658 ## def __listPackages(self):
654 def __listPackages(self): 659 ## """
655 """ 660 ## Private slot to list all installed packages.
656 Private slot to list all installed packages. 661 ## """
657 """ 662 ## from .PipListDialog import PipListDialog
658 from .PipListDialog import PipListDialog 663 ## self.__listDialog = PipListDialog(
659 self.__listDialog = PipListDialog( 664 ## self, "list", Preferences.getPip("PipSearchIndex"),
660 self, "list", Preferences.getPip("PipSearchIndex"), 665 ## self.tr("Installed Packages"))
661 self.tr("Installed Packages")) 666 ## self.__listDialog.show()
662 self.__listDialog.show() 667 ## self.__listDialog.start()
663 self.__listDialog.start() 668 ##
664 669 ## def __listUptodatePackages(self):
665 def __listUptodatePackages(self): 670 ## """
666 """ 671 ## Private slot to list all installed, up-to-date packages.
667 Private slot to list all installed, up-to-date packages. 672 ## """
668 """ 673 ## from .PipListDialog import PipListDialog
669 from .PipListDialog import PipListDialog 674 ## self.__listUptodateDialog = PipListDialog(
670 self.__listUptodateDialog = PipListDialog( 675 ## self, "uptodate", Preferences.getPip("PipSearchIndex"),
671 self, "uptodate", Preferences.getPip("PipSearchIndex"), 676 ## self.tr("Up-to-date Packages"))
672 self.tr("Up-to-date Packages")) 677 ## self.__listUptodateDialog.show()
673 self.__listUptodateDialog.show() 678 ## self.__listUptodateDialog.start()
674 self.__listUptodateDialog.start() 679 ##
675 680 ## def __listOutdatedPackages(self):
676 def __listOutdatedPackages(self): 681 ## """
677 """ 682 ## Private slot to list all installed, up-to-date packages.
678 Private slot to list all installed, up-to-date packages. 683 ## """
679 """ 684 ## from .PipListDialog import PipListDialog
680 from .PipListDialog import PipListDialog 685 ## self.__listOutdatedDialog = PipListDialog(
681 self.__listOutdatedDialog = PipListDialog( 686 ## self, "outdated", Preferences.getPip("PipSearchIndex"),
682 self, "outdated", Preferences.getPip("PipSearchIndex"), 687 ## self.tr("Outdated Packages"))
683 self.tr("Outdated Packages")) 688 ## self.__listOutdatedDialog.show()
684 self.__listOutdatedDialog.show() 689 ## self.__listOutdatedDialog.start()
685 self.__listOutdatedDialog.start() 690 ##
686
687 def __editUserConfiguration(self): 691 def __editUserConfiguration(self):
688 """ 692 """
689 Private slot to edit the user configuration. 693 Private slot to edit the user configuration.
690 """ 694 """
691 self.__editConfiguration() 695 self.__editConfiguration()
1118 from .PipFreezeDialog import PipFreezeDialog 1122 from .PipFreezeDialog import PipFreezeDialog
1119 self.__freezeDialog = PipFreezeDialog(self) 1123 self.__freezeDialog = PipFreezeDialog(self)
1120 self.__freezeDialog.show() 1124 self.__freezeDialog.show()
1121 self.__freezeDialog.start() 1125 self.__freezeDialog.start()
1122 1126
1123 def __searchPyPI(self): 1127 ## def __searchPyPI(self):
1124 """ 1128 ## """
1125 Private slot to search the Python Package Index. 1129 ## Private slot to search the Python Package Index.
1126 """ 1130 ## """
1127 from .PipSearchDialog import PipSearchDialog 1131 ## from .PipSearchDialog import PipSearchDialog
1128 1132 ##
1133 ## if Preferences.getPip("PipSearchIndex"):
1134 ## indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
1135 ## else:
1136 ## indexUrl = DefaultIndexUrlXml
1137 ##
1138 ## self.__searchDialog = PipSearchDialog(self, indexUrl)
1139 ## self.__searchDialog.show()
1140 ##
1141 def getIndexUrl(self):
1142 """
1143 Public method to get the index URL for PyPI.
1144
1145 @return index URL for PyPI
1146 @rtype str
1147 """
1148 if Preferences.getPip("PipSearchIndex"):
1149 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
1150 else:
1151 indexUrl = Pip.DefaultIndexUrlPip
1152
1153 return indexUrl
1154
1155 def getIndexUrlXml(self):
1156 """
1157 Public method to get the index URL for XML RPC calls.
1158
1159 @return index URL for XML RPC calls
1160 @rtype str
1161 """
1129 if Preferences.getPip("PipSearchIndex"): 1162 if Preferences.getPip("PipSearchIndex"):
1130 indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi" 1163 indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
1131 else: 1164 else:
1132 indexUrl = DefaultIndexUrlXml 1165 indexUrl = Pip.DefaultIndexUrlXml
1133 1166
1134 self.__searchDialog = PipSearchDialog(self, indexUrl) 1167 return indexUrl
1135 self.__searchDialog.show()
1136 1168
1137 def getInstalledPackages(self, envName, localPackages=True, 1169 def getInstalledPackages(self, envName, localPackages=True,
1138 notRequired=False, usersite=False): 1170 notRequired=False, usersite=False):
1139 """ 1171 """
1140 Public method to get the list of installed packages. 1172 Public method to get the list of installed packages.

eric ide

mercurial