src/eric7/Project/Project.py

branch
eric7
changeset 9389
7b2344009d7a
parent 9388
bfe7ea6599a3
child 9390
9dba609bcc23
equal deleted inserted replaced
9388:bfe7ea6599a3 9389:7b2344009d7a
31 from PyQt6.QtGui import QKeySequence, QAction 31 from PyQt6.QtGui import QKeySequence, QAction
32 from PyQt6.QtWidgets import QLineEdit, QToolBar, QDialog, QInputDialog, QMenu 32 from PyQt6.QtWidgets import QLineEdit, QToolBar, QDialog, QInputDialog, QMenu
33 from PyQt6.Qsci import QsciScintilla 33 from PyQt6.Qsci import QsciScintilla
34 34
35 from EricWidgets.EricApplication import ericApp 35 from EricWidgets.EricApplication import ericApp
36 from EricWidgets import EricFileDialog, EricMessageBox, EricPathPickerDialog 36 from EricWidgets import EricFileDialog, EricMessageBox
37 from EricWidgets.EricListSelectionDialog import EricListSelectionDialog 37 from EricWidgets.EricListSelectionDialog import EricListSelectionDialog
38 from EricWidgets.EricProgressDialog import EricProgressDialog 38 from EricWidgets.EricProgressDialog import EricProgressDialog
39 from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor 39 from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
40 40
41 from Globals import recentNameProject 41 from Globals import recentNameProject
5033 ) 5033 )
5034 ) 5034 )
5035 self.configureVenvAct.triggered.connect(self.__configureEnvironment) 5035 self.configureVenvAct.triggered.connect(self.__configureEnvironment)
5036 self.actions.append(self.configureVenvAct) 5036 self.actions.append(self.configureVenvAct)
5037 5037
5038 self.upgradeVenvAct = EricAction(
5039 self.tr("Upgrade"),
5040 self.tr("&Upgrade"),
5041 0,
5042 0,
5043 self.embeddedEnvironmentGrp,
5044 "project_venv_upgrade",
5045 )
5046 self.upgradeVenvAct.setStatusTip(self.tr("Upgrade the embedded environment."))
5047 self.upgradeVenvAct.setWhatsThis(
5048 self.tr(
5049 "<b>Upgrade</b>"
5050 "<p>This opens a dialog to enter the parameters to upgrade the"
5051 " embedded virtual environment of the project.</p>"
5052 )
5053 )
5054 self.upgradeVenvAct.triggered.connect(
5055 lambda: self.__createEmbeddedEnvironment(upgrade=True)
5056 )
5057 self.actions.append(self.upgradeVenvAct)
5058
5038 self.closeAct.setEnabled(False) 5059 self.closeAct.setEnabled(False)
5039 self.saveAct.setEnabled(False) 5060 self.saveAct.setEnabled(False)
5040 self.saveasAct.setEnabled(False) 5061 self.saveasAct.setEnabled(False)
5041 self.actGrp2.setEnabled(False) 5062 self.actGrp2.setEnabled(False)
5042 self.propsAct.setEnabled(False) 5063 self.propsAct.setEnabled(False)
6755 6776
6756 def __showContextMenuEnvironment(self): 6777 def __showContextMenuEnvironment(self):
6757 """ 6778 """
6758 Private slot called before the 'Embedded Environment' menu is shown. 6779 Private slot called before the 'Embedded Environment' menu is shown.
6759 """ 6780 """
6781 self.upgradeVenvAct.setEnabled(self.__findEmbeddedEnvironment())
6782
6760 self.showMenu.emit("Environment", self.environmentMenu) 6783 self.showMenu.emit("Environment", self.environmentMenu)
6761 6784
6762 def __findEmbeddedEnvironment(self): 6785 def __findEmbeddedEnvironment(self):
6763 """ 6786 """
6764 Private method to find the path of the embedded virtual environment. 6787 Private method to find the path of the embedded virtual environment.
6790 """ 6813 """
6791 self.__venvConfiguration = { 6814 self.__venvConfiguration = {
6792 "name": "embedded environment", 6815 "name": "embedded environment",
6793 "interpreter": "", 6816 "interpreter": "",
6794 "exec_path": "", 6817 "exec_path": "",
6818 "system_site_packages": False,
6795 } 6819 }
6796 6820
6797 def __createEmbeddedEnvironment(self): 6821 def __createEmbeddedEnvironment(self, upgrade=False):
6798 """ 6822 """
6799 Private method to create the embedded virtual environment. 6823 Private method to create the embedded virtual environment.
6800 """ 6824
6801 pythonPath, ok = EricPathPickerDialog.getStrPath( 6825 @param upgrade flag indicating an upgrade operation (defaults to False)
6802 None, 6826 @type bool (optional)
6803 self.tr("Python Executable"), 6827 """
6804 self.tr("Enter the Python interpreter for the virtual environment:"), 6828 from .ProjectVenvCreationParametersDialog import (
6805 defaultDirectory=Globals.getPythonExecutable(), 6829 ProjectVenvCreationParametersDialog,
6806 ) 6830 )
6807 if not ok: 6831
6832 dlg = ProjectVenvCreationParametersDialog(
6833 withSystemSitePackages=self.__venvConfiguration["system_site_packages"]
6834 )
6835 if dlg.exec() != QDialog.DialogCode.Accepted:
6808 # user canceled the environment creation 6836 # user canceled the environment creation
6809 self.__setEmbeddedEnvironmentProjectConfig(False) 6837 self.__setEmbeddedEnvironmentProjectConfig(False)
6810 return 6838 return
6811 6839
6840 pythonPath, withSystemSitePackages = dlg.getData()
6812 configuration = { 6841 configuration = {
6813 "envType": "pyvenv", 6842 "envType": "pyvenv",
6814 "targetDirectory": os.path.join(self.getProjectPath(), ".venv"), 6843 "targetDirectory": os.path.join(self.getProjectPath(), ".venv"),
6815 "openTarget": False, 6844 "openTarget": False,
6816 "createLog": True, 6845 "createLog": True,
6818 "logicalName": self.__venvConfiguration["name"], 6847 "logicalName": self.__venvConfiguration["name"],
6819 "pythonExe": pythonPath, 6848 "pythonExe": pythonPath,
6820 } 6849 }
6821 from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog 6850 from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog
6822 6851
6852 args = []
6853 if upgrade:
6854 args.append("--upgrade")
6855 if withSystemSitePackages:
6856 args.append("--system-site-packages")
6857 args.append(configuration["targetDirectory"])
6823 dia = VirtualenvExecDialog(configuration, None) 6858 dia = VirtualenvExecDialog(configuration, None)
6824 dia.show() 6859 dia.show()
6825 dia.start([configuration["targetDirectory"]]) 6860 dia.start(args)
6826 dia.exec() 6861 dia.exec()
6862
6863 self.__venvConfiguration["system_site_packages"] = withSystemSitePackages
6827 6864
6828 self.__configureEnvironment() 6865 self.__configureEnvironment()
6829 if not self.__venvConfiguration["interpreter"]: 6866 if not self.__venvConfiguration["interpreter"]:
6830 # user canceled the environment creation 6867 # user canceled the environment creation, delete the created directory
6868 shutil.rmtree(configuration["targetDirectory"], True)
6831 self.__setEmbeddedEnvironmentProjectConfig(False) 6869 self.__setEmbeddedEnvironmentProjectConfig(False)
6832 return 6870 return
6871
6872 if upgrade and not withSystemSitePackages:
6873 # re-install the project into the upgraded environment
6874 # Note: seems to fail with access to system site-packages
6875 self.__installProjectIntoEnvironment()
6833 6876
6834 @pyqtSlot() 6877 @pyqtSlot()
6835 def __configureEnvironment(self, environmentPath=""): 6878 def __configureEnvironment(self, environmentPath=""):
6836 """ 6879 """
6837 Private slot to configure the embedded environment. 6880 Private slot to configure the embedded environment.

eric ide

mercurial