isort icon indicating copy to clipboard operation
isort copied to clipboard

Suppress all `check_file()` output

Open kmurphy4 opened this issue 3 years ago • 0 comments

Hi! I apologize if this has been answered elsewhere, but I don't see any existing documentation on this point (https://github.com/PyCQA/isort/issues/156 is the closest I found).

I'm currently building a tool that will call the isort.check_file() API, but I don't want to emit the lines like

ERROR: /tmp/test.py Imports are incorrectly sorted and/or formatted.

Looking at the code, it doesn't look like this is currently possible, as we just unconditionally create a "terminal printer" and then unconditionally call .error() on it: https://github.com/PyCQA/isort/blob/44e3b5d179da5033ce23f796b014e74f3a3259cd/isort/api.py#L272-L275 https://github.com/PyCQA/isort/blob/44e3b5d179da5033ce23f796b014e74f3a3259cd/isort/api.py#L280

which ultimately unconditionally calls print(): https://github.com/PyCQA/isort/blob/44e3b5d179da5033ce23f796b014e74f3a3259cd/isort/format.py#L107

Is there a config option I'm missing somewhere? If not, what options do I have? I've considered monkey-patching create_terminal_printer() and monkey-patching sys.stderr, but neither seem like long-term solutions :)

kmurphy4 avatar Dec 20 '21 17:12 kmurphy4