src/eric7/CodeFormatting/IsortFormattingDialog.py

branch
eric7
changeset 9455
5f138ee215a5
parent 9453
e5065dde905d
child 9460
0d1b5d0fd815
equal deleted inserted replaced
9454:f3cf935c0c66 9455:5f138ee215a5
102 102
103 self.__performAction() 103 self.__performAction()
104 104
105 def __performAction(self): 105 def __performAction(self):
106 """ 106 """
107 Private method to execute the requested formatting action. 107 Private method to execute the requested sorting action.
108 """ 108 """
109 self.progressBar.setValue(0) 109 self.progressBar.setValue(0)
110 self.progressBar.setVisible(True) 110 self.progressBar.setVisible(True)
111 111
112 self.statisticsGroup.setVisible(False) 112 self.statisticsGroup.setVisible(False)
121 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) 121 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
122 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) 122 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
123 123
124 files = self.__filterFiles(self.__filesList) 124 files = self.__filterFiles(self.__filesList)
125 if len(files) > 1: 125 if len(files) > 1:
126 self.__formatManyFiles(files) 126 self.__sortManyFiles(files)
127 elif len(files) == 1: 127 elif len(files) == 1:
128 self.__formatOneFile(files[0]) 128 self.__sortOneFile(files[0])
129 129
130 def __filterFiles(self, filesList): 130 def __filterFiles(self, filesList):
131 """ 131 """
132 Private method to filter the given list of files according the 132 Private method to filter the given list of files according the
133 configuration parameters. 133 configuration parameters.
202 self.__updateStatistics() 202 self.__updateStatistics()
203 self.__populateStatusFilterCombo() 203 self.__populateStatusFilterCombo()
204 204
205 def __updateStatistics(self): 205 def __updateStatistics(self):
206 """ 206 """
207 Private method to update the statistics about the recent formatting run and 207 Private method to update the statistics about the recent sorting run and
208 make them visible. 208 make them visible.
209 """ 209 """
210 self.reformattedLabel.setText( 210 self.reformattedLabel.setText(
211 self.tr("Reformatted:") 211 self.tr("Resorted:")
212 if self.__config["__action__"] is IsortFormattingAction.Sort 212 if self.__config["__action__"] is IsortFormattingAction.Sort
213 else self.tr("Would Reformat:") 213 else self.tr("Would Resort:")
214 ) 214 )
215 215
216 total = self.progressBar.maximum() 216 total = self.progressBar.maximum()
217 217
218 self.totalCountLabel.setText("{0:n}".format(total)) 218 self.totalCountLabel.setText("{0:n}".format(total))
264 """ 264 """
265 dataType = item.data(0, IsortFormattingDialog.DataTypeRole) 265 dataType = item.data(0, IsortFormattingDialog.DataTypeRole)
266 if dataType == "error": 266 if dataType == "error":
267 EricMessageBox.critical( 267 EricMessageBox.critical(
268 self, 268 self,
269 self.tr("Formatting Failure"), 269 self.tr("Imports Sorting Failure"),
270 self.tr("<p>Formatting failed due to this error.</p><p>{0}</p>").format( 270 self.tr(
271 item.data(0, IsortFormattingDialog.DataRole) 271 "<p>Imports sorting failed due to this error.</p><p>{0}</p>"
272 ), 272 ).format(item.data(0, IsortFormattingDialog.DataRole)),
273 ) 273 )
274 elif dataType == "diff": 274 elif dataType == "diff":
275 if self.__diffDialog is None: 275 if self.__diffDialog is None:
276 self.__diffDialog = FormattingDiffWidget() 276 self.__diffDialog = FormattingDiffWidget()
277 self.__diffDialog.showDiff(item.data(0, IsortFormattingDialog.DataRole)) 277 self.__diffDialog.showDiff(item.data(0, IsortFormattingDialog.DataRole))
302 self.__diffDialog.close() 302 self.__diffDialog.close()
303 evt.accept() 303 evt.accept()
304 304
305 def __handleIsortResult(self, filename, status, data=""): 305 def __handleIsortResult(self, filename, status, data=""):
306 """ 306 """
307 Private method to handle an isort formatting result. 307 Private method to handle an isort sorting result.
308 308
309 @param filename name of the processed file 309 @param filename name of the processed file
310 @type str 310 @type str
311 @param status status of the performed action (one of 'changed', 'failed', 311 @param status status of the performed action (one of 'changed', 'failed',
312 'skipped' or 'unchanged') 312 'skipped' or 'unchanged')
366 366
367 self.progressBar.setValue(self.progressBar.value() + 1) 367 self.progressBar.setValue(self.progressBar.value() + 1)
368 368
369 QCoreApplication.processEvents() 369 QCoreApplication.processEvents()
370 370
371 def __formatManyFiles(self, files): 371 def __sortManyFiles(self, files):
372 """ 372 """
373 Private method to format the list of files according the configuration using 373 Private method to sort imports of the list of files according the configuration
374 multiple processes in parallel. 374 using multiple processes in parallel.
375 375
376 @param files list of files to be processed 376 @param files list of files to be processed
377 @type list of str 377 @type list of str
378 """ 378 """
379 maxProcesses = Preferences.getUI("BackgroundServiceProcesses") 379 maxProcesses = Preferences.getUI("BackgroundServiceProcesses")
400 taskQueue.put((file, self.__config["__action__"])) 400 taskQueue.put((file, self.__config["__action__"]))
401 401
402 # Start worker processes 402 # Start worker processes
403 workers = [ 403 workers = [
404 multiprocessing.Process( 404 multiprocessing.Process(
405 target=self.formattingWorkerTask, 405 target=self.sortingWorkerTask,
406 args=(taskQueue, doneQueue, self.__isortConfig), 406 args=(taskQueue, doneQueue, self.__isortConfig),
407 ) 407 )
408 for _ in range(NumberOfProcesses) 408 for _ in range(NumberOfProcesses)
409 ] 409 ]
410 for worker in workers: 410 for worker in workers:
434 doneQueue.close() 434 doneQueue.close()
435 435
436 self.__finish() 436 self.__finish()
437 437
438 @staticmethod 438 @staticmethod
439 def formattingWorkerTask(inputQueue, outputQueue, isortConfig): 439 def sortingWorkerTask(inputQueue, outputQueue, isortConfig):
440 """ 440 """
441 Static method acting as the parallel worker for the formatting task. 441 Static method acting as the parallel worker for the formatting task.
442 442
443 @param inputQueue input queue 443 @param inputQueue input queue
444 @type multiprocessing.Queue 444 @type multiprocessing.Queue
467 filename=file, 467 filename=file,
468 ) 468 )
469 469
470 outputQueue.put(result) 470 outputQueue.put(result)
471 471
472 def __formatOneFile(self, file): 472 def __sortOneFile(self, file):
473 """ 473 """
474 Private method to format the list of files according the configuration. 474 Private method to sort the imports of the list of files according the
475 configuration.
475 476
476 @param file name of the file to be processed 477 @param file name of the file to be processed
477 @type str 478 @type str
478 """ 479 """
479 if self.__config["__action__"] == IsortFormattingAction.Diff: 480 if self.__config["__action__"] == IsortFormattingAction.Diff:
554 555
555 556
556 @dataclass 557 @dataclass
557 class IsortStatistics: 558 class IsortStatistics:
558 """ 559 """
559 Class containing the isort reformatting statistic data. 560 Class containing the isort statistic data.
560 """ 561 """
561 562
562 skippedCount: int = 0 563 skippedCount: int = 0
563 changeCount: int = 0 564 changeCount: int = 0
564 sameCount: int = 0 565 sameCount: int = 0
567 568
568 569
569 @dataclass 570 @dataclass
570 class IsortResult: 571 class IsortResult:
571 """ 572 """
572 Class containing the isort reformatting result data. 573 Class containing the isort result data.
573 """ 574 """
574 575
575 status: str = "" 576 status: str = ""
576 filename: str = "" 577 filename: str = ""
577 data: str = "" 578 data: str = ""

eric ide

mercurial