isort 5.11.0, NameError: name 'colorama' is not defined
See original GitHub issueHello!
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: https://github.com/PyCQA/isort/blob/65250088ca11ea59eba80bfb8e65891e92333edb/isort/format.py#L138-L156
As you can see, colorama_unavailable is a global variable in this context. It should be used to ensure that colorama is not used if set to True. However, this is not done.
How to reproduce
Ensure the following:
- Download
isortat 5.11.0 (or at any point since #1961 / c1a4139241b757a5af3d85143bbd05cd11721a17) coloramamust not be downloaded.
Then, any use of isort --check-only demo.py, with demo.py as an existing file, should trigger the following error:
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
In the wild
See this Github Actions for the error in the wild.
- Tom Aarsen
Issue Analytics
- State:
- Created 9 months ago
- Reactions:14
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Fix Rich compatibility #1961 - PyCQA/isort - GitHub
isort 5.11.0, NameError: name 'colorama' is not defined #2031. Closed. Sign up for free to join this conversation on GitHub. Already have an...
Read more >Problems using Colorama on Python 2.7 - Stack Overflow
I'm learning to use colorama in Python, so I installed it and I'm able to import the module with no problems from the...
Read more >Package List — Spack 0.20.0.dev0 documentation
ACPID reads a set of configuration files which define event->action pairs. ... of the Python standard argparse library (though not necessarily the API)....
Read more >Debian -- Software Packages in "sid", Subsection python
Software Packages in "sid", Subsection python ... libbasix0.5 (0.5.1-1): Finite Element Basis Function Definition Runtime Library (Python 3) ...
Read more >Installed Python Libraries - CoCalc
Library Python 3 SageMath Anaconda 2020 Anaco...
abelfunctions 0.1.0
access. Calculate spatial accessibility metrics. 1.1.8 1.1.8 1.1.3 1.1.3
admcycles. Tautological ring on Mbar_g,n 1.3.2
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

pip install isort[colors], as the message above suggests also worked for meThanks for the quick fix!