|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing some utility functions for the isort import statement formatting |
|
8 tool. |
|
9 """ |
|
10 |
|
11 import contextlib |
|
12 import os |
|
13 import sys |
|
14 |
|
15 import isort |
|
16 |
|
17 from PyQt6.QtCore import QCoreApplication, pyqtSlot |
|
18 |
|
19 from eric7.EricWidgets import EricMessageBox |
|
20 |
|
21 |
|
22 @pyqtSlot() |
|
23 def aboutIsort(): |
|
24 """ |
|
25 Slot to show an 'About isort' dialog. |
|
26 """ |
|
27 EricMessageBox.information( |
|
28 None, |
|
29 QCoreApplication.translate("IsortUtilities", "About isort"), |
|
30 QCoreApplication.translate( |
|
31 "IsortUtilities", |
|
32 """<p><b>isort Version {0}</b></p>""" |
|
33 """<p><i>isort</i> is a Python utility / library to sort imports""" |
|
34 """ alphabetically, and automatically separated into sections and by""" |
|
35 """ type.</p>""", |
|
36 ).format(isort.__version__), |
|
37 ) |
|
38 |
|
39 |
|
40 @contextlib.contextmanager |
|
41 def suppressStderr(): |
|
42 """ |
|
43 Function to suppress output to stderr. |
|
44 """ |
|
45 stderr = sys.stderr |
|
46 with open(os.devnull, "w") as devnull: |
|
47 sys.stderr = devnull |
|
48 yield |
|
49 sys.stderr = stderr |