Traceback (most recent call last):
File "[sic]\site-packages\isort\main.py", line 87, in sort_imports
incorrectly_sorted = not api.check_file(file_name, config=config, **kwargs)
File "[sic]\site-packages\isort\api.py", line 338, in check_file
return check_stream(
File "[sic]\site-packages\isort\api.py", line 272, in check_stream
printer = create_terminal_printer(
File "[sic]\site-packages\isort\format.py", line 153, in create_terminal_printer
colorama.init(strip=False)
NameError: name 'colorama' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "[sic]\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "[sic]\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "[sic]\site-packages\isort\__main__.py", line 3, in <module>
main()
File "[sic]\site-packages\isort\main.py", line 1225, in main
for sort_attempt in attempt_iterator:
File "[sic]\site-packages\isort\main.py", line 1209, in <genexpr>
sort_imports( # type: ignore
File "[sic]\site-packages\isort\main.py", line 114, in sort_imports
_print_hard_fail(config, offending_file=file_name)
File "[sic]\site-packages\isort\main.py", line 127, in _print_hard_fail
printer = create_terminal_printer(
File "[sic]\site-packages\isort\format.py", line 153, in create_terminal_printer
colorama.init(strip=False)
NameError: name 'colorama' is not defined
Hello!
Bug overview
colorama.initis always called increate_terminal_printer, even ifcolorama_unavailableis set to True andcoloramais unavailable.Details
A Printer is initialized in this function:
isort/isort/format.py
Lines 138 to 156 in 6525008
As you can see,
colorama_unavailableis a global variable in this context. It should be used to ensure thatcoloramais not used if set to True. However, this is not done.How to reproduce
Ensure the following:
isortat 5.11.0 (or at any point since Fix Rich compatibility #1961 / c1a4139)coloramamust not be downloaded.Then, any use of
isort --check-only demo.py, withdemo.pyas an existing file, should trigger the following error:In the wild
See this Github Actions for the error in the wild.