Mon, 31 Oct 2022 15:29:18 +0100
Code Formatting
- added an interface to resort the import statements of Python source files with the 'isort' utility
9214 | 1 | # -*- coding: utf-8 -*- |
2 | ||
3 | # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> | |
4 | # | |
5 | ||
6 | """ | |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
7 | Module implementing a dialog showing the Black code formatting progress and the results. |
9214 | 8 | """ |
9 | ||
10 | import copy | |
11 | import datetime | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
12 | import multiprocessing |
9214 | 13 | import pathlib |
14 | ||
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
15 | from dataclasses import dataclass |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
16 | |
9214 | 17 | import black |
18 | ||
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
19 | from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QCoreApplication, QObject |
9214 | 20 | from PyQt6.QtWidgets import ( |
21 | QAbstractButton, | |
22 | QDialog, | |
23 | QDialogButtonBox, | |
24 | QHeaderView, | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
25 | QTreeWidgetItem, |
9214 | 26 | ) |
27 | ||
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9360
diff
changeset
|
28 | from eric7.EricWidgets import EricMessageBox |
9214 | 29 | |
30 | from .Ui_BlackFormattingDialog import Ui_BlackFormattingDialog | |
31 | ||
32 | from . import BlackUtilities | |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
33 | from .FormattingDiffWidget import FormattingDiffWidget |
9214 | 34 | from .BlackFormattingAction import BlackFormattingAction |
35 | ||
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9360
diff
changeset
|
36 | from eric7 import Preferences, Utilities |
9214 | 37 | |
38 | ||
39 | class BlackFormattingDialog(QDialog, Ui_BlackFormattingDialog): | |
40 | """ | |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
41 | Class implementing a dialog showing the Black code formatting progress and the |
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
42 | results. |
9214 | 43 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
44 | |
9214 | 45 | DataTypeRole = Qt.ItemDataRole.UserRole |
46 | DataRole = Qt.ItemDataRole.UserRole + 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
47 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
48 | StatusColumn = 0 |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
49 | FileNameColumn = 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
50 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
51 | def __init__( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
52 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
53 | configuration, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
54 | filesList, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
55 | project=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
56 | action=BlackFormattingAction.Format, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
57 | parent=None, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
58 | ): |
9214 | 59 | """ |
60 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
61 | |
9214 | 62 | @param configuration dictionary containing the configuration parameters |
63 | @type dict | |
64 | @param filesList list of absolute file paths to be processed | |
65 | @type list of str | |
66 | @param project reference to the project object (defaults to None) | |
67 | @type Project (optional) | |
68 | @param action action to be performed (defaults to BlackFormattingAction.Format) | |
69 | @type BlackFormattingAction (optional) | |
70 | @param parent reference to the parent widget (defaults to None) | |
71 | @type QWidget (optional) | |
72 | """ | |
73 | super().__init__(parent) | |
74 | self.setupUi(self) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
75 | |
9214 | 76 | self.progressBar.setMaximum(len(filesList)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
77 | |
9214 | 78 | self.resultsList.header().setSortIndicator(1, Qt.SortOrder.AscendingOrder) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
79 | |
9214 | 80 | self.__config = copy.deepcopy(configuration) |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
81 | self.__config["__action__"] = action # needed by the workers |
9214 | 82 | self.__project = project |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
83 | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
84 | self.__filesList = filesList[:] |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
85 | |
9214 | 86 | self.__diffDialog = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
87 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
88 | self.__allFilter = self.tr("<all>") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
89 | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
90 | self.__formatButton = self.buttonBox.addButton( |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
91 | self.tr("Format Code"), QDialogButtonBox.ButtonRole.ActionRole |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
92 | ) |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
93 | self.__formatButton.setVisible(False) |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
94 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
95 | self.show() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
96 | QCoreApplication.processEvents() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
97 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
98 | self.__performAction() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
99 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
100 | def __performAction(self): |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
101 | """ |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
102 | Private method to execute the requested formatting action. |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
103 | """ |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
104 | self.progressBar.setValue(0) |
9360
8b46571d9cc9
Forgot to make the progress bar of the formatting dialog visible again.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9348
diff
changeset
|
105 | self.progressBar.setVisible(True) |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
106 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
107 | self.statisticsGroup.setVisible(False) |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
108 | self.__statistics = BlackStatistics() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
109 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
110 | self.__cancelled = False |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
111 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
112 | self.statusFilterComboBox.clear() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
113 | self.resultsList.clear() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
114 | |
9214 | 115 | self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
116 | self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) | |
117 | self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
118 | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
119 | files = self.__filterFiles(self.__filesList) |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
120 | if len(files) > 1: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
121 | self.__formatManyFiles(files) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
122 | elif len(files) == 1: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
123 | self.__formatOneFile(files[0]) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
124 | |
9214 | 125 | def __filterFiles(self, filesList): |
126 | """ | |
127 | Private method to filter the given list of files according the | |
128 | configuration parameters. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
129 | |
9214 | 130 | @param filesList list of files |
131 | @type list of str | |
132 | @return list of filtered files | |
133 | @rtype list of str | |
134 | """ | |
135 | filterRegExps = [ | |
136 | BlackUtilities.compileRegExp(self.__config[k]) | |
137 | for k in ["force-exclude", "extend-exclude", "exclude"] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
138 | if k in self.__config |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
139 | and bool(self.__config[k]) |
9214 | 140 | and BlackUtilities.validateRegExp(self.__config[k])[0] |
141 | ] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
142 | |
9214 | 143 | files = [] |
144 | for file in filesList: | |
145 | file = Utilities.fromNativeSeparators(file) | |
146 | for filterRegExp in filterRegExps: | |
147 | filterMatch = filterRegExp.search(file) | |
148 | if filterMatch and filterMatch.group(0): | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
149 | self.__handleBlackFormattingResult("ignored", file, "") |
9214 | 150 | break |
151 | else: | |
152 | files.append(file) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
153 | |
9214 | 154 | return files |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
155 | |
9214 | 156 | def __resort(self): |
157 | """ | |
158 | Private method to resort the result list. | |
159 | """ | |
160 | self.resultsList.sortItems( | |
161 | self.resultsList.sortColumn(), | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
162 | self.resultsList.header().sortIndicatorOrder(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
163 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
164 | |
9214 | 165 | def __resizeColumns(self): |
166 | """ | |
167 | Private method to resize the columns of the result list. | |
168 | """ | |
169 | self.resultsList.header().resizeSections( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
170 | QHeaderView.ResizeMode.ResizeToContents |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
171 | ) |
9214 | 172 | self.resultsList.header().setStretchLastSection(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
173 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
174 | def __populateStatusFilterCombo(self): |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
175 | """ |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
176 | Private method to populate the status filter combo box with allowed selections. |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
177 | """ |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
178 | allowedSelections = set() |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
179 | for row in range(self.resultsList.topLevelItemCount()): |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
180 | allowedSelections.add( |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
181 | self.resultsList.topLevelItem(row).text( |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
182 | BlackFormattingDialog.StatusColumn |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
183 | ) |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
184 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
185 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
186 | self.statusFilterComboBox.addItem(self.__allFilter) |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
187 | self.statusFilterComboBox.addItems(sorted(allowedSelections)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
188 | |
9214 | 189 | def __finish(self): |
190 | """ | |
191 | Private method to perform some actions after the run was performed or canceled. | |
192 | """ | |
193 | self.__resort() | |
194 | self.__resizeColumns() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
195 | |
9214 | 196 | self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
197 | self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) | |
198 | self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
199 | |
9214 | 200 | self.progressBar.setVisible(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
201 | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
202 | self.__formatButton.setVisible( |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
203 | self.__config["__action__"] is not BlackFormattingAction.Format |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
204 | and self.__statistics.changeCount > 0 |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
205 | ) |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
206 | |
9214 | 207 | self.__updateStatistics() |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
208 | self.__populateStatusFilterCombo() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
209 | |
9214 | 210 | def __updateStatistics(self): |
211 | """ | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
212 | Private method to update the statistics about the recent formatting run and |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
213 | make them visible. |
9214 | 214 | """ |
215 | self.reformattedLabel.setText( | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
216 | self.tr("Reformatted:") |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
217 | if self.__config["__action__"] is BlackFormattingAction.Format |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
218 | else self.tr("Would Reformat:") |
9214 | 219 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
220 | |
9214 | 221 | total = self.progressBar.maximum() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
222 | |
9214 | 223 | self.totalCountLabel.setText("{0:n}".format(total)) |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
224 | self.excludedCountLabel.setText("{0:n}".format(self.__statistics.ignoreCount)) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
225 | self.failuresCountLabel.setText("{0:n}".format(self.__statistics.failureCount)) |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
226 | self.processedCountLabel.setText( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
227 | "{0:n}".format(self.__statistics.processedCount) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
228 | ) |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
229 | self.reformattedCountLabel.setText( |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
230 | "{0:n}".format(self.__statistics.changeCount) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
231 | ) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
232 | self.unchangedCountLabel.setText("{0:n}".format(self.__statistics.sameCount)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
233 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
234 | self.statisticsGroup.setVisible(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
235 | |
9214 | 236 | @pyqtSlot(QAbstractButton) |
237 | def on_buttonBox_clicked(self, button): | |
238 | """ | |
239 | Private slot to handle button presses of the dialog buttons. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
240 | |
9214 | 241 | @param button reference to the pressed button |
242 | @type QAbstractButton | |
243 | """ | |
244 | if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): | |
245 | self.__cancelled = True | |
246 | elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): | |
247 | self.accept() | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
248 | elif button is self.__formatButton: |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
249 | self.__formatButtonClicked() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
250 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
251 | @pyqtSlot() |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
252 | def __formatButtonClicked(self): |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
253 | """ |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
254 | Private slot handling the selection of the 'Format Code' button. |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
255 | """ |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
256 | self.__config["__action__"] = BlackFormattingAction.Format |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
257 | |
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
258 | self.__performAction() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
259 | |
9214 | 260 | @pyqtSlot(QTreeWidgetItem, int) |
261 | def on_resultsList_itemDoubleClicked(self, item, column): | |
262 | """ | |
263 | Private slot handling a double click of a result item. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
264 | |
9214 | 265 | @param item reference to the double clicked item |
266 | @type QTreeWidgetItem | |
267 | @param column column number that was double clicked | |
268 | @type int | |
269 | """ | |
270 | dataType = item.data(0, BlackFormattingDialog.DataTypeRole) | |
271 | if dataType == "error": | |
272 | EricMessageBox.critical( | |
273 | self, | |
274 | self.tr("Formatting Failure"), | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
275 | self.tr("<p>Formatting failed due to this error.</p><p>{0}</p>").format( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
276 | item.data(0, BlackFormattingDialog.DataRole) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
277 | ), |
9214 | 278 | ) |
279 | elif dataType == "diff": | |
280 | if self.__diffDialog is None: | |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
281 | self.__diffDialog = FormattingDiffWidget() |
9214 | 282 | self.__diffDialog.showDiff(item.data(0, BlackFormattingDialog.DataRole)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
283 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
284 | def __formatManyFiles(self, files): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
285 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
286 | Private method to format the list of files according the configuration using |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
287 | multiple processes in parallel. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
288 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
289 | @param files list of files to be processed |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
290 | @type list of str |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
291 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
292 | maxProcesses = Preferences.getUI("BackgroundServiceProcesses") |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
293 | if maxProcesses == 0: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
294 | # determine based on CPU count |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
295 | try: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
296 | NumberOfProcesses = multiprocessing.cpu_count() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
297 | if NumberOfProcesses >= 1: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
298 | NumberOfProcesses -= 1 |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
299 | except NotImplementedError: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
300 | NumberOfProcesses = 1 |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
301 | else: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
302 | NumberOfProcesses = maxProcesses |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
303 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
304 | # Create queues |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
305 | taskQueue = multiprocessing.Queue() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
306 | doneQueue = multiprocessing.Queue() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
307 | |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
308 | # Submit tasks (initially two times the number of processes) |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
309 | tasks = len(files) |
9292
a5c8a0213fe3
Fixed an issue in the multiprocessing usage causing a traceback when then number of tasks is smaller than the number of worker processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9289
diff
changeset
|
310 | initialTasks = min(2 * NumberOfProcesses, tasks) |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
311 | for _ in range(initialTasks): |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
312 | file = files.pop(0) |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
313 | relSrc = self.__project.getRelativePath(str(file)) if self.__project else "" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
314 | taskQueue.put((file, relSrc)) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
315 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
316 | # Start worker processes |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
317 | workers = [ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
318 | multiprocessing.Process( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
319 | target=self.formattingWorkerTask, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
320 | args=(taskQueue, doneQueue, self.__config), |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
321 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
322 | for _ in range(NumberOfProcesses) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
323 | ] |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
324 | for worker in workers: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
325 | worker.start() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
326 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
327 | # Get the results from the worker tasks |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
328 | for _ in range(tasks): |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
329 | result = doneQueue.get() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
330 | self.__handleBlackFormattingResult( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
331 | result.status, result.filename, result.data |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
332 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
333 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
334 | if self.__cancelled: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
335 | break |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
336 | |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
337 | if files: |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
338 | file = files.pop(0) |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
339 | relSrc = ( |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
340 | self.__project.getRelativePath(str(file)) if self.__project else "" |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
341 | ) |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
342 | taskQueue.put((file, relSrc)) |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
343 | |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
344 | # Tell child processes to stop |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
345 | for _ in range(NumberOfProcesses): |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
346 | taskQueue.put("STOP") |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
347 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
348 | for worker in workers: |
9348
f61d71d95cb1
Changed the multiprocessing start method to 'spawn' because 'fork' (on *nix) seems to be unreliable with respect to queues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9344
diff
changeset
|
349 | worker.join() |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
350 | worker.close() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
351 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
352 | taskQueue.close() |
9348
f61d71d95cb1
Changed the multiprocessing start method to 'spawn' because 'fork' (on *nix) seems to be unreliable with respect to queues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9344
diff
changeset
|
353 | doneQueue.close() |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
354 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
355 | self.__finish() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
356 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
357 | @staticmethod |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
358 | def formattingWorkerTask(inputQueue, outputQueue, config): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
359 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
360 | Static method acting as the parallel worker for the formatting task. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
361 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
362 | @param inputQueue input queue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
363 | @type multiprocessing.Queue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
364 | @param outputQueue output queue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
365 | @type multiprocessing.Queue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
366 | @param config dictionary containing the configuration parameters |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
367 | @type dict |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
368 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
369 | report = BlackMultiprocessingReport(outputQueue) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
370 | report.check = config["__action__"] is BlackFormattingAction.Check |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
371 | report.diff = config["__action__"] is BlackFormattingAction.Diff |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
372 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
373 | versions = ( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
374 | {black.TargetVersion[target.upper()] for target in config["target-version"]} |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
375 | if config["target-version"] |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
376 | else set() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
377 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
378 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
379 | mode = black.Mode( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
380 | target_versions=versions, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
381 | line_length=int(config["line-length"]), |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
382 | string_normalization=not config["skip-string-normalization"], |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
383 | magic_trailing_comma=not config["skip-magic-trailing-comma"], |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
384 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
385 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
386 | if config["__action__"] is BlackFormattingAction.Diff: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
387 | for file, relSrc in iter(inputQueue.get, "STOP"): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
388 | BlackFormattingDialog.__diffFormatFile( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
389 | pathlib.Path(file), |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
390 | fast=False, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
391 | mode=mode, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
392 | report=report, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
393 | relSrc=relSrc, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
394 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
395 | else: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
396 | writeBack = black.WriteBack.from_configuration( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
397 | check=config["__action__"] is BlackFormattingAction.Check, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
398 | diff=config["__action__"] is BlackFormattingAction.Diff, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
399 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
400 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
401 | for file, _relSrc in iter(inputQueue.get, "STOP"): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
402 | black.reformat_one( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
403 | pathlib.Path(file), |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
404 | fast=False, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
405 | write_back=writeBack, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
406 | mode=mode, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
407 | report=report, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
408 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
409 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
410 | def __formatOneFile(self, file): |
9214 | 411 | """ |
412 | Private method to format the list of files according the configuration. | |
9284
3b3a4f659782
"Blacked" the sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9283
diff
changeset
|
413 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
414 | @param file name of the file to be processed |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
415 | @type str |
9214 | 416 | """ |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
417 | report = BlackReport(self) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
418 | report.check = self.__config["__action__"] is BlackFormattingAction.Check |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
419 | report.diff = self.__config["__action__"] is BlackFormattingAction.Diff |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
420 | report.result.connect(self.__handleBlackFormattingResult) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
421 | |
9214 | 422 | writeBack = black.WriteBack.from_configuration( |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
423 | check=self.__config["__action__"] is BlackFormattingAction.Check, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
424 | diff=self.__config["__action__"] is BlackFormattingAction.Diff, |
9214 | 425 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
426 | |
9214 | 427 | versions = ( |
428 | { | |
429 | black.TargetVersion[target.upper()] | |
430 | for target in self.__config["target-version"] | |
431 | } | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
432 | if self.__config["target-version"] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
433 | else set() |
9214 | 434 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
435 | |
9214 | 436 | mode = black.Mode( |
437 | target_versions=versions, | |
438 | line_length=int(self.__config["line-length"]), | |
439 | string_normalization=not self.__config["skip-string-normalization"], | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
440 | magic_trailing_comma=not self.__config["skip-magic-trailing-comma"], |
9214 | 441 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
442 | |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
443 | if self.__config["__action__"] is BlackFormattingAction.Diff: |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
444 | relSrc = self.__project.getRelativePath(str(file)) if self.__project else "" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
445 | self.__diffFormatFile( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
446 | pathlib.Path(file), fast=False, mode=mode, report=report, relSrc=relSrc |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
447 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
448 | else: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
449 | black.reformat_one( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
450 | pathlib.Path(file), |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
451 | fast=False, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
452 | write_back=writeBack, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
453 | mode=mode, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
454 | report=report, |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
455 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
456 | |
9214 | 457 | self.__finish() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
458 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
459 | @staticmethod |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
460 | def __diffFormatFile(src, fast, mode, report, relSrc=""): |
9214 | 461 | """ |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
462 | Static method to check, if the given files need to be reformatted, and generate |
9214 | 463 | a unified diff. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
464 | |
9214 | 465 | @param src path of file to be checked |
466 | @type pathlib.Path | |
467 | @param fast flag indicating fast operation | |
468 | @type bool | |
469 | @param mode code formatting options | |
470 | @type black.Mode | |
471 | @param report reference to the report object | |
472 | @type BlackReport | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
473 | @param relSrc name of the file relative to the project (defaults to "") |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
474 | @type str (optional) |
9214 | 475 | """ |
476 | then = datetime.datetime.utcfromtimestamp(src.stat().st_mtime) | |
477 | with open(src, "rb") as buf: | |
478 | srcContents, _, _ = black.decode_bytes(buf.read()) | |
479 | try: | |
480 | dstContents = black.format_file_contents(srcContents, fast=fast, mode=mode) | |
481 | except black.NothingChanged: | |
482 | report.done(src, black.Changed.NO) | |
483 | return | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
484 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
485 | fileName = relSrc if bool(relSrc) else str(src) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
486 | |
9214 | 487 | now = datetime.datetime.utcnow() |
488 | srcName = f"{fileName}\t{then} +0000" | |
489 | dstName = f"{fileName}\t{now} +0000" | |
490 | diffContents = black.diff(srcContents, dstContents, srcName, dstName) | |
491 | report.done(src, black.Changed.YES, diff=diffContents) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
492 | |
9214 | 493 | def closeEvent(self, evt): |
494 | """ | |
495 | Protected slot implementing a close event handler. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
496 | |
9214 | 497 | @param evt reference to the close event |
498 | @type QCloseEvent | |
499 | """ | |
500 | if self.__diffDialog is not None: | |
501 | self.__diffDialog.close() | |
502 | evt.accept() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
503 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
504 | @pyqtSlot(str) |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
505 | def on_statusFilterComboBox_currentTextChanged(self, status): |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
506 | """ |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
507 | Private slot handling the selection of a status for items to be shown. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
508 | |
9220
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
509 | @param status selected status |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
510 | @type str |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
511 | """ |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
512 | for row in range(self.resultsList.topLevelItemCount()): |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
513 | itm = self.resultsList.topLevelItem(row) |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
514 | itm.setHidden( |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
515 | status != self.__allFilter |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
516 | and itm.text(BlackFormattingDialog.StatusColumn) != status |
e9e7eca7efee
Black Formatting Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9214
diff
changeset
|
517 | ) |
9214 | 518 | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
519 | @pyqtSlot(str, str, str) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
520 | def __handleBlackFormattingResult(self, status, filename, data): |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
521 | """ |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
522 | Private slot to handle the result of a black reformatting action. |
9214 | 523 | |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
524 | @param status status of the performed action (one of 'changed', 'failed', |
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
525 | 'ignored', 'unchanged' or 'unmodified') |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
526 | @type str |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
527 | @param filename name of the processed file |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
528 | @type str |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
529 | @param data action data (error message or unified diff) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
530 | @type str |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
531 | """ |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
532 | isError = False |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
533 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
534 | if status == "changed": |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
535 | statusMsg = ( |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
536 | self.tr("would reformat") |
9344
52990830b13f
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
537 | if self.__config["__action__"] |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
538 | in (BlackFormattingAction.Check, BlackFormattingAction.Diff) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
539 | else self.tr("reformatted") |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
540 | ) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
541 | self.__statistics.changeCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
542 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
543 | elif status == "unchanged": |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
544 | statusMsg = self.tr("unchanged") |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
545 | self.__statistics.sameCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
546 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
547 | elif status == "unmodified": |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
548 | statusMsg = self.tr("unmodified") |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
549 | self.__statistics.sameCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
550 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
551 | elif status == "ignored": |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
552 | statusMsg = self.tr("ignored") |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
553 | self.__statistics.ignoreCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
554 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
555 | elif status == "failed": |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
556 | statusMsg = self.tr("failed") |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
557 | self.__statistics.failureCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
558 | isError = True |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
559 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
560 | else: |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
561 | statusMsg = self.tr("invalid status ({0})").format(status) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
562 | self.__statistics.failureCount += 1 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
563 | isError = True |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
564 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
565 | if status != "ignored": |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
566 | self.__statistics.processedCount += 1 |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
567 | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
568 | if self.__project: |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
569 | filename = self.__project.getRelativePath(filename) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
570 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
571 | itm = QTreeWidgetItem(self.resultsList, [statusMsg, filename]) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
572 | if data: |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
573 | itm.setData( |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
574 | 0, BlackFormattingDialog.DataTypeRole, "error" if isError else "diff" |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
575 | ) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
576 | itm.setData(0, BlackFormattingDialog.DataRole, data) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
577 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
578 | self.progressBar.setValue(self.progressBar.value() + 1) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
579 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
580 | QCoreApplication.processEvents() |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
581 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
582 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
583 | @dataclass |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
584 | class BlackStatistics: |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
585 | """ |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
586 | Class containing the reformatting statistic data. |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
587 | """ |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
588 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
589 | ignoreCount: int = 0 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
590 | changeCount: int = 0 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
591 | sameCount: int = 0 |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
592 | failureCount: int = 0 |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
593 | processedCount: int = 0 |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
594 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
595 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
596 | class BlackReport(QObject, black.Report): |
9214 | 597 | """ |
598 | Class extending the black Report to work with our dialog. | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
599 | |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
600 | @signal result(status, file name, data) emitted to signal the reformatting result |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
601 | as three strings giving the status (one of 'changed', 'unchanged', 'unmodified', |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
602 | 'failed' or 'ignored'), the file name and data related to the result |
9214 | 603 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
604 | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
605 | result = pyqtSignal(str, str, str) |
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
606 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
607 | def __init__(self, parent=None): |
9214 | 608 | """ |
609 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
610 | |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
611 | @param parent reference to the parent object (defaults to None |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
612 | @type QObject (optional) |
9214 | 613 | """ |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
614 | QObject.__init__(self, parent) |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
615 | black.Report.__init__(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
616 | |
9214 | 617 | def done(self, src, changed, diff=""): |
618 | """ | |
619 | Public method to handle the end of a reformat. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
620 | |
9214 | 621 | @param src name of the processed file |
622 | @type pathlib.Path | |
623 | @param changed change status | |
624 | @type black.Changed | |
625 | @param diff unified diff of potential changes (defaults to "") | |
626 | @type str | |
627 | """ | |
628 | if changed is black.Changed.YES: | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
629 | status = "changed" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
630 | |
9214 | 631 | elif changed is black.Changed.NO: |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
632 | status = "unchanged" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
633 | |
9214 | 634 | elif changed is black.Changed.CACHED: |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
635 | status = "unmodified" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
636 | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
637 | self.result.emit(status, str(src), diff) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
638 | |
9214 | 639 | def failed(self, src, message): |
640 | """ | |
641 | Public method to handle a reformat failure. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
642 | |
9214 | 643 | @param src name of the processed file |
644 | @type pathlib.Path | |
645 | @param message error message | |
646 | @type str | |
647 | """ | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
648 | self.result.emit("failed", str(src), message) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
649 | |
9214 | 650 | def path_ignored(self, src, message=""): |
651 | """ | |
652 | Public method handling an ignored path. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9220
diff
changeset
|
653 | |
9214 | 654 | @param src name of the processed file |
655 | @type pathlib.Path or str | |
656 | @param message ignore message (default to "") | |
657 | @type str (optional) | |
658 | """ | |
9281
76caf27cb8a8
Changed the code reformatting dialog to work with signals and slots and do the statistics calculation in the dialog class (prepare for multi processing).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
659 | self.result.emit("ignored", str(src), "") |
9283
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
660 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
661 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
662 | @dataclass |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
663 | class BlackMultiprocessingResult: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
664 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
665 | Class containing the reformatting result data. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
666 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
667 | This class is used when reformatting multiple files in parallel using processes. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
668 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
669 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
670 | status: str = "" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
671 | filename: str = "" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
672 | data: str = "" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
673 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
674 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
675 | class BlackMultiprocessingReport(black.Report): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
676 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
677 | Class extending the black Report to work with multiprocessing. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
678 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
679 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
680 | def __init__(self, resultQueue): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
681 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
682 | Constructor |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
683 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
684 | @param resultQueue reference to the queue to put the results into |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
685 | @type multiprocessing.Queue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
686 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
687 | super().__init__() |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
688 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
689 | self.__queue = resultQueue |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
690 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
691 | def done(self, src, changed, diff=""): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
692 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
693 | Public method to handle the end of a reformat. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
694 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
695 | @param src name of the processed file |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
696 | @type pathlib.Path |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
697 | @param changed change status |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
698 | @type black.Changed |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
699 | @param diff unified diff of potential changes (defaults to "") |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
700 | @type str |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
701 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
702 | if changed is black.Changed.YES: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
703 | status = "changed" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
704 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
705 | elif changed is black.Changed.NO: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
706 | status = "unchanged" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
707 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
708 | elif changed is black.Changed.CACHED: |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
709 | status = "unmodified" |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
710 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
711 | self.__queue.put( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
712 | BlackMultiprocessingResult(status=status, filename=str(src), data=diff) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
713 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
714 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
715 | def failed(self, src, message): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
716 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
717 | Public method to handle a reformat failure. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
718 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
719 | @param src name of the processed file |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
720 | @type pathlib.Path |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
721 | @param message error message |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
722 | @type str |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
723 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
724 | self.__queue.put( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
725 | BlackMultiprocessingResult(status="failed", filename=str(src), data=message) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
726 | ) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
727 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
728 | def path_ignored(self, src, message=""): |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
729 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
730 | Public method handling an ignored path. |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
731 | |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
732 | @param src name of the processed file |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
733 | @type pathlib.Path or str |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
734 | @param message ignore message (default to "") |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
735 | @type str (optional) |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
736 | """ |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
737 | self.__queue.put( |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
738 | BlackMultiprocessingResult(status="ignored", filename=str(src), data="") |
0e9d2c4e379e
Changed the code reformatting dialog such, that it uses multiple processes to reformat files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9281
diff
changeset
|
739 | ) |