src/eric7/Project/Project.py

branch
eric7
changeset 10618
b2faf1b237f9
parent 10611
60c838d75276
child 10621
f5631f40c4d9
equal deleted inserted replaced
10615:08d340b8b7c7 10618:b2faf1b237f9
4887 ) 4887 )
4888 ) 4888 )
4889 self.createSBOMAct.triggered.connect(self.__createSBOMFile) 4889 self.createSBOMAct.triggered.connect(self.__createSBOMFile)
4890 self.actions.append(self.createSBOMAct) 4890 self.actions.append(self.createSBOMAct)
4891 4891
4892 self.clearByteCodeCachesAct = EricAction(
4893 self.tr("Clear Byte Code Caches"),
4894 self.tr("Clear Byte Code &Caches"),
4895 0,
4896 0,
4897 self.othersGrp,
4898 "project_clear_bytecode_caches",
4899 )
4900 self.clearByteCodeCachesAct.setStatusTip(
4901 self.tr("Clear the byte code caches of the project.")
4902 )
4903 self.clearByteCodeCachesAct.setWhatsThis(
4904 self.tr(
4905 """<b>Clear Byte Code Caches</b>"""
4906 """<p>This deletes all directories containing byte code cache files."""
4907 """</p>"""
4908 )
4909 )
4910 self.clearByteCodeCachesAct.triggered.connect(self.__clearByteCodeCaches)
4911 self.actions.append(self.clearByteCodeCachesAct)
4912
4892 ################################################################### 4913 ###################################################################
4893 ## Project Tools - code formatting actions - Black 4914 ## Project Tools - code formatting actions - Black
4894 ################################################################### 4915 ###################################################################
4895 4916
4896 self.blackFormattingGrp = createActionGroup(self) 4917 self.blackFormattingGrp = createActionGroup(self)
7150 self.__createEmbeddedEnvironment(upgrade=True) 7171 self.__createEmbeddedEnvironment(upgrade=True)
7151 except (OSError, json.JSONDecodeError): 7172 except (OSError, json.JSONDecodeError):
7152 # the configuration file does not exist or is invalid JSON 7173 # the configuration file does not exist or is invalid JSON
7153 self.__initVenvConfiguration() 7174 self.__initVenvConfiguration()
7154 7175
7176 #########################################################################
7177 ## Below are methods implementing some tool functionality
7178 #########################################################################
7179
7180 @pyqtSlot()
7181 def __clearByteCodeCaches(self, directory=None):
7182 """
7183 Private method to recursively clear the byte code caches of a given directory.
7184
7185 Note: The byte code cache directiries are named '__pycache__'.
7186
7187 @param directory directory name to clear byte code caches from (defaults to
7188 None)
7189 @type str (optional)
7190 """
7191 if directory is None:
7192 # When directory is 'None', we were called by the QAction.
7193 if self.ppath:
7194 directory = self.ppath
7195 else:
7196 return
7197
7198 # step 1: delete the __pycache__ directory
7199 cacheDir = os.path.join(directory, "__pycache__")
7200 if os.path.exists(cacheDir):
7201 shutil.rmtree(cacheDir, ignore_errors=True)
7202
7203 # step 2: descent into subdirectories
7204 with os.scandir(directory) as dirEntriesIterator:
7205 for dirEntry in dirEntriesIterator:
7206 if dirEntry.is_dir():
7207 self.__clearByteCodeCaches(dirEntry.path)
7208
7155 7209
7156 # 7210 #
7157 # eflag: noqa = M601 7211 # eflag: noqa = M601

eric ide

mercurial