src/eric7/CodeFormatting/IsortUtilities.py

Mon, 31 Oct 2022 15:29:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 31 Oct 2022 15:29:18 +0100
branch
eric7
changeset 9453
e5065dde905d
child 9475
5c09d70e9290
permissions
-rw-r--r--

Code Formatting
- added an interface to resort the import statements of Python source files with the 'isort' utility

# -*- coding: utf-8 -*-

# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing some utility functions for the isort import statement formatting
tool.
"""

import contextlib
import os
import sys

import isort

from PyQt6.QtCore import QCoreApplication, pyqtSlot

from eric7.EricWidgets import EricMessageBox


@pyqtSlot()
def aboutIsort():
    """
    Slot to show an 'About isort' dialog.
    """
    EricMessageBox.information(
        None,
        QCoreApplication.translate("IsortUtilities", "About isort"),
        QCoreApplication.translate(
            "IsortUtilities",
            """<p><b>isort Version {0}</b></p>"""
            """<p><i>isort</i> is a Python utility / library to sort imports"""
            """ alphabetically, and automatically separated into sections and by"""
            """ type.</p>""",
        ).format(isort.__version__),
    )


@contextlib.contextmanager
def suppressStderr():
    """
    Function to suppress output to stderr.
    """
    stderr = sys.stderr
    with open(os.devnull, "w") as devnull:
        sys.stderr = devnull
        yield
        sys.stderr = stderr

eric ide

mercurial