PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

Suppress all `check_file()` output #1868

Open kmurphy4 opened 2 years ago

kmurphy4 commented 2 years ago

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 :)

vortechs2000 commented 1 year ago

I'd also love to have this option. I tried just setting the format_error setting to the empty string, but then it prints a blank line for every file being checked.