djLint
djLint copied to clipboard
Make colorama and tqdm optional in djlint
djlint is a great tool for linting and formatting, but it currently depends on the colorama and tqdm library for color output and progress bars in the terminal. For some users, these dependencies may be unnecessary or unwanted.
As an example, the black formatter also provides an option to disable color output. This allows users to redirect the output to a file or pipe it to another process without the color codes interfering.
It would be great if djlint could also provide an option to disable color output and progress bars. This would make djlint more flexible and usable for a wider range of users and use cases.
Thank you for your consideration.
PS: Also I suggest considering dropping regex dependency and using standard python re. It's useful to minimise dependencies count. However, such a change may require a lot of effort. At the moment I do not understand how much use is made of ragex and whether it can be simply replaced.
Thanks for the suggestion. Have you tried the --quiet flag?
We use the regex module because of its support for the \K option and wildcards in look after statements.
Have you tried the --quiet flag?
It's not only about disabling coloring. It is more about additional dependencies that I do not want to install in my system.
I'd be happy to take a look at a PR with any suggestions :)
Just another note on an unintended impact of colorama as a dependency here:
Django calls colorama.init() on module load if it is installed. This causes sys.stdout to be replaced with a colorama.ansitowin32.StreamWrapper instance.
That in turn causes execnet-wrapped output from pytest-xdist's --looponfail mode to swallow ansi color codes, eliminating colorized output when using pytest --looponfail --color=yes.
This one is a nasty interaction of 3 libraries:
- djlint, because it installs colorama as a non-win32-only dependency
- django, because it assumes colorama will only be present on win32
- pytest-xdist, because it uses a multiprocessing output mode that fails to preserve ansi escapes with colorama's wrapper
This is arguably a Django bug (and I opened a ticket there), but mentioning here since there will be a high correlation between users of djlint who use Django, and all of them will be getting colorama.ansitowin32.StreamWrapper as their sys.stdout since djlint includes colorama.