src/eric7/Project/Project.py

branch
eric7
changeset 9638
6ee095b9d3bd
parent 9632
dd907ee33b03
child 9639
9e66fd88193c
equal deleted inserted replaced
9637:e3f0fc3bb6ff 9638:6ee095b9d3bd
5148 "<p>This opens a dialog to enter the parameters to recreate the" 5148 "<p>This opens a dialog to enter the parameters to recreate the"
5149 " embedded virtual environment of the project. The existing environment" 5149 " embedded virtual environment of the project. The existing environment"
5150 " is cleared first.</p>" 5150 " is cleared first.</p>"
5151 ) 5151 )
5152 ) 5152 )
5153 self.recreateVenvAct.triggered.connect(self.__createEmbeddedEnvironment) 5153 self.recreateVenvAct.triggered.connect(
5154 lambda: self.__createEmbeddedEnvironment(force=True)
5155 )
5154 self.actions.append(self.recreateVenvAct) 5156 self.actions.append(self.recreateVenvAct)
5155 5157
5156 self.reloadAct.setEnabled(False) 5158 self.reloadAct.setEnabled(False)
5157 self.closeAct.setEnabled(False) 5159 self.closeAct.setEnabled(False)
5158 self.saveAct.setEnabled(False) 5160 self.saveAct.setEnabled(False)
6936 "interpreter": "", 6938 "interpreter": "",
6937 "exec_path": "", 6939 "exec_path": "",
6938 "system_site_packages": False, 6940 "system_site_packages": False,
6939 } 6941 }
6940 6942
6941 def __createEmbeddedEnvironment(self, upgrade=False): 6943 def __createEmbeddedEnvironment(self, upgrade=False, force=False):
6942 """ 6944 """
6943 Private method to create the embedded virtual environment. 6945 Private method to create the embedded virtual environment.
6944 6946
6945 @param upgrade flag indicating an upgrade operation (defaults to False) 6947 @param upgrade flag indicating an upgrade operation (defaults to False)
6946 @type bool (optional) 6948 @type bool (optional)
6949 @param force flag indicating to force the creation (defaults to False)
6950 @type bool (optional)
6947 """ 6951 """
6948 from eric7.VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog 6952 from eric7.VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog
6949 6953
6950 from .ProjectVenvCreationParametersDialog import ( 6954 from .ProjectVenvCreationParametersDialog import (
6951 ProjectVenvCreationParametersDialog, 6955 ProjectVenvCreationParametersDialog,
6952 ) 6956 )
6953 6957
6954 dlg = ProjectVenvCreationParametersDialog( 6958 if force or upgrade or not self.__findEmbeddedEnvironment():
6955 withSystemSitePackages=self.__venvConfiguration["system_site_packages"] 6959 dlg = ProjectVenvCreationParametersDialog(
6956 ) 6960 withSystemSitePackages=self.__venvConfiguration["system_site_packages"]
6957 if dlg.exec() != QDialog.DialogCode.Accepted: 6961 )
6958 # user canceled the environment creation 6962 if dlg.exec() != QDialog.DialogCode.Accepted:
6959 self.__setEmbeddedEnvironmentProjectConfig(False) 6963 # user canceled the environment creation
6960 return 6964 self.__setEmbeddedEnvironmentProjectConfig(False)
6961 6965 return
6962 pythonPath, withSystemSitePackages = dlg.getData() 6966
6963 configuration = { 6967 pythonPath, withSystemSitePackages = dlg.getData()
6964 "envType": "pyvenv", 6968 configuration = {
6965 "targetDirectory": os.path.join(self.getProjectPath(), ".venv"), 6969 "envType": "pyvenv",
6966 "openTarget": False, 6970 "targetDirectory": os.path.join(self.getProjectPath(), ".venv"),
6967 "createLog": True, 6971 "openTarget": False,
6968 "createScript": True, 6972 "createLog": True,
6969 "logicalName": self.__venvConfiguration["name"], 6973 "createScript": True,
6970 "pythonExe": pythonPath, 6974 "logicalName": self.__venvConfiguration["name"],
6971 } 6975 "pythonExe": pythonPath,
6972 6976 }
6973 args = [] 6977
6974 if upgrade: 6978 args = []
6975 args.append("--upgrade") 6979 if upgrade:
6976 else: 6980 args.append("--upgrade")
6977 if os.path.exists(os.path.join(self.getProjectPath(), ".venv")): 6981 else:
6978 args.append("--clear") 6982 if os.path.exists(os.path.join(self.getProjectPath(), ".venv")):
6979 if withSystemSitePackages: 6983 args.append("--clear")
6980 args.append("--system-site-packages") 6984 if withSystemSitePackages:
6981 args.append(configuration["targetDirectory"]) 6985 args.append("--system-site-packages")
6982 dia = VirtualenvExecDialog(configuration, None) 6986 args.append(configuration["targetDirectory"])
6983 dia.show() 6987 dia = VirtualenvExecDialog(configuration, None)
6984 dia.start(args) 6988 dia.show()
6985 dia.exec() 6989 dia.start(args)
6986 6990 dia.exec()
6987 self.__venvConfiguration["system_site_packages"] = withSystemSitePackages 6991
6988 6992 self.__venvConfiguration["system_site_packages"] = withSystemSitePackages
6989 self.__configureEnvironment() 6993
6990 if not self.__venvConfiguration["interpreter"]: 6994 self.__configureEnvironment()
6991 # user canceled the environment creation, delete the created directory 6995 if not self.__venvConfiguration["interpreter"]:
6992 shutil.rmtree(configuration["targetDirectory"], True) 6996 # user canceled the environment creation, delete the created directory
6993 self.__setEmbeddedEnvironmentProjectConfig(False) 6997 shutil.rmtree(configuration["targetDirectory"], True)
6994 return 6998 self.__setEmbeddedEnvironmentProjectConfig(False)
6995 6999 return
6996 if upgrade and not withSystemSitePackages: 7000
6997 # re-install the project into the upgraded environment 7001 if upgrade and not withSystemSitePackages:
6998 # Note: seems to fail on some systems with access to system site-packages 7002 # re-install the project into the upgraded environment
6999 self.__installProjectIntoEnvironment() 7003 # Note: seems to fail on some systems with access to system
7004 # site-packages
7005 self.__installProjectIntoEnvironment()
7000 7006
7001 @pyqtSlot() 7007 @pyqtSlot()
7002 def __configureEnvironment(self, environmentPath=""): 7008 def __configureEnvironment(self, environmentPath=""):
7003 """ 7009 """
7004 Private slot to configure the embedded environment. 7010 Private slot to configure the embedded environment.

eric ide

mercurial