src/eric7/Project/Project.py

branch
eric7-maintenance
changeset 10659
43ead32943ca
parent 10616
4aa36fcd4a30
parent 10650
4618223e6e32
child 10694
f46c1e224e8a
diff -r df71ea10a451 -r 43ead32943ca src/eric7/Project/Project.py
--- a/src/eric7/Project/Project.py	Sun Mar 03 10:39:56 2024 +0100
+++ b/src/eric7/Project/Project.py	Tue Apr 02 10:00:22 2024 +0200
@@ -1394,10 +1394,7 @@
 
         fn1, ext = os.path.splitext(os.path.basename(self.pfile))
         fn = os.path.join(self.getProjectManagementDir(), "{0}.edj".format(fn1))
-        if (
-            os.path.exists(fn)
-            and self.__debuggerPropertiesFile.readFile(fn)
-        ):
+        if os.path.exists(fn) and self.__debuggerPropertiesFile.readFile(fn):
             self.debugPropertiesLoaded = True
             self.debugPropertiesChanged = False
 
@@ -1484,7 +1481,7 @@
         @return load status of debug properties
         @rtype bool
         """
-        return self.debugPropertiesLoaded or self.__pdata["EMBEDDED_VENV"]
+        return self.debugPropertiesLoaded
 
     def __showDebugProperties(self):
         """
@@ -4889,6 +4886,27 @@
         self.createSBOMAct.triggered.connect(self.__createSBOMFile)
         self.actions.append(self.createSBOMAct)
 
+        self.clearByteCodeCachesAct = EricAction(
+            self.tr("Clear Byte Code Caches"),
+            self.tr("Clear Byte Code &Caches"),
+            0,
+            0,
+            self.othersGrp,
+            "project_clear_bytecode_caches",
+        )
+        self.clearByteCodeCachesAct.setStatusTip(
+            self.tr("Clear the byte code caches of the project.")
+        )
+        self.clearByteCodeCachesAct.setWhatsThis(
+            self.tr(
+                """<b>Clear Byte Code Caches</b>"""
+                """<p>This deletes all directories containing byte code cache files."""
+                """</p>"""
+            )
+        )
+        self.clearByteCodeCachesAct.triggered.connect(self.__clearByteCodeCaches)
+        self.actions.append(self.clearByteCodeCachesAct)
+
         ###################################################################
         ## Project Tools - code formatting actions - Black
         ###################################################################
@@ -5588,7 +5606,7 @@
                     if recursiveSearch:
                         d = self.getRelativePath(ns)
                         if d not in dirs:
-                            dirs.append(d)  # noqa: M538
+                            dirs.append(d)  # noqa: M569
                     continue
 
                 filetype = ""
@@ -7152,6 +7170,39 @@
             # the configuration file does not exist or is invalid JSON
             self.__initVenvConfiguration()
 
+    #########################################################################
+    ## Below are methods implementing some tool functionality
+    #########################################################################
+
+    @pyqtSlot()
+    def __clearByteCodeCaches(self, directory=None):
+        """
+        Private method to recursively clear the byte code caches of a given directory.
+
+        Note: The byte code cache directories are named '__pycache__'.
+
+        @param directory directory name to clear byte code caches from (defaults to
+            None)
+        @type str (optional)
+        """
+        if directory is None:
+            # When directory is 'None', we were called by the QAction.
+            if self.ppath:
+                directory = self.ppath
+            else:
+                return
+
+        # step 1: delete the __pycache__ directory
+        cacheDir = os.path.join(directory, "__pycache__")
+        if os.path.exists(cacheDir):
+            shutil.rmtree(cacheDir, ignore_errors=True)
+
+        # step 2: descent into subdirectories
+        with os.scandir(directory) as dirEntriesIterator:
+            for dirEntry in dirEntriesIterator:
+                if dirEntry.is_dir():
+                    self.__clearByteCodeCaches(dirEntry.path)
+
 
 #
 # eflag: noqa = M601

eric ide

mercurial