src/eric7/Project/Project.py

branch
eric7
changeset 9389
7b2344009d7a
parent 9388
bfe7ea6599a3
child 9390
9dba609bcc23
diff -r bfe7ea6599a3 -r 7b2344009d7a src/eric7/Project/Project.py
--- a/src/eric7/Project/Project.py	Wed Oct 05 16:19:31 2022 +0200
+++ b/src/eric7/Project/Project.py	Thu Oct 06 16:22:35 2022 +0200
@@ -33,7 +33,7 @@
 from PyQt6.Qsci import QsciScintilla
 
 from EricWidgets.EricApplication import ericApp
-from EricWidgets import EricFileDialog, EricMessageBox, EricPathPickerDialog
+from EricWidgets import EricFileDialog, EricMessageBox
 from EricWidgets.EricListSelectionDialog import EricListSelectionDialog
 from EricWidgets.EricProgressDialog import EricProgressDialog
 from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
@@ -5035,6 +5035,27 @@
         self.configureVenvAct.triggered.connect(self.__configureEnvironment)
         self.actions.append(self.configureVenvAct)
 
+        self.upgradeVenvAct = EricAction(
+            self.tr("Upgrade"),
+            self.tr("&Upgrade"),
+            0,
+            0,
+            self.embeddedEnvironmentGrp,
+            "project_venv_upgrade",
+        )
+        self.upgradeVenvAct.setStatusTip(self.tr("Upgrade the embedded environment."))
+        self.upgradeVenvAct.setWhatsThis(
+            self.tr(
+                "<b>Upgrade</b>"
+                "<p>This opens a dialog to enter the parameters to upgrade the"
+                " embedded virtual environment of the project.</p>"
+            )
+        )
+        self.upgradeVenvAct.triggered.connect(
+            lambda: self.__createEmbeddedEnvironment(upgrade=True)
+        )
+        self.actions.append(self.upgradeVenvAct)
+
         self.closeAct.setEnabled(False)
         self.saveAct.setEnabled(False)
         self.saveasAct.setEnabled(False)
@@ -6757,6 +6778,8 @@
         """
         Private slot called before the 'Embedded Environment' menu is shown.
         """
+        self.upgradeVenvAct.setEnabled(self.__findEmbeddedEnvironment())
+
         self.showMenu.emit("Environment", self.environmentMenu)
 
     def __findEmbeddedEnvironment(self):
@@ -6792,23 +6815,29 @@
             "name": "embedded environment",
             "interpreter": "",
             "exec_path": "",
+            "system_site_packages": False,
         }
 
-    def __createEmbeddedEnvironment(self):
+    def __createEmbeddedEnvironment(self, upgrade=False):
         """
         Private method to create the embedded virtual environment.
-        """
-        pythonPath, ok = EricPathPickerDialog.getStrPath(
-            None,
-            self.tr("Python Executable"),
-            self.tr("Enter the Python interpreter for the virtual environment:"),
-            defaultDirectory=Globals.getPythonExecutable(),
+
+        @param upgrade flag indicating an upgrade operation (defaults to False)
+        @type bool (optional)
+        """
+        from .ProjectVenvCreationParametersDialog import (
+            ProjectVenvCreationParametersDialog,
         )
-        if not ok:
+
+        dlg = ProjectVenvCreationParametersDialog(
+            withSystemSitePackages=self.__venvConfiguration["system_site_packages"]
+        )
+        if dlg.exec() != QDialog.DialogCode.Accepted:
             # user canceled the environment creation
             self.__setEmbeddedEnvironmentProjectConfig(False)
             return
 
+        pythonPath, withSystemSitePackages = dlg.getData()
         configuration = {
             "envType": "pyvenv",
             "targetDirectory": os.path.join(self.getProjectPath(), ".venv"),
@@ -6820,17 +6849,31 @@
         }
         from VirtualEnv.VirtualenvExecDialog import VirtualenvExecDialog
 
+        args = []
+        if upgrade:
+            args.append("--upgrade")
+        if withSystemSitePackages:
+            args.append("--system-site-packages")
+        args.append(configuration["targetDirectory"])
         dia = VirtualenvExecDialog(configuration, None)
         dia.show()
-        dia.start([configuration["targetDirectory"]])
+        dia.start(args)
         dia.exec()
 
+        self.__venvConfiguration["system_site_packages"] = withSystemSitePackages
+
         self.__configureEnvironment()
         if not self.__venvConfiguration["interpreter"]:
-            # user canceled the environment creation
+            # user canceled the environment creation, delete the created directory
+            shutil.rmtree(configuration["targetDirectory"], True)
             self.__setEmbeddedEnvironmentProjectConfig(False)
             return
 
+        if upgrade and not withSystemSitePackages:
+            # re-install the project into the upgraded environment
+            # Note: seems to fail with access to system site-packages
+            self.__installProjectIntoEnvironment()
+
     @pyqtSlot()
     def __configureEnvironment(self, environmentPath=""):
         """

eric ide

mercurial