Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2031 not fixed in v6.0.0b2 #2133

Closed
aryyh opened this issue May 15, 2023 · 3 comments
Closed

Issue #2031 not fixed in v6.0.0b2 #2133

aryyh opened this issue May 15, 2023 · 3 comments

Comments

@aryyh
Copy link

aryyh commented May 15, 2023

Issue #2031 not fixed. It still tries to use colorama when not requested and not installed

I'm still getting this error on isort version6.0.0b2. See also confirmed from others here

It looks like the fix that went in isn't working in my case. The added line colorama.init(strip=False) fails in format.py line 153.

It gets called even when color is False AND color_unavailable is True, which then doesn't trigger the sorry msg due to the AND condition evaluating to False. I have confirmed this is what has been happening in my case at least

See failing function below for more context

def create_terminal_printer(
    color: bool, output: Optional[TextIO] = None, error: str = "", success: str = ""
) -> BasicPrinter:
    if color and colorama_unavailable:
        no_colorama_message = (
            "\n"
            "Sorry, but to use --color (color_output) the colorama python package is required.\n\n"
            "Reference: https://pypi.org/project/colorama/\n\n"
            "You can either install it separately on your system or as the colors extra "
            "for isort. Ex: \n\n"
            "$ pip install isort[colors]\n"
        )
        print(no_colorama_message, file=sys.stderr)
        sys.exit(1)

    colorama.init(strip=False)
    return (
        ColoramaPrinter(error, success, output) if color else BasicPrinter(error, success, output)
    )

Failing trace

Traceback (most recent call last):
  File "/home/runner/.local/share/virtualenvs/python-fi6_LwSQ/lib/python3.8/site-packages/isort/main.py", line 87, in sort_imports
    incorrectly_sorted = not api.check_file(file_name, config=config, **kwargs)
  File "/home/runner/.local/share/virtualenvs/python-fi6_LwSQ/lib/python3.8/site-packages/isort/api.py", line 338, in check_file
    return check_stream(
  File "/home/runner/.local/share/virtualenvs/python-fi6_LwSQ/lib/python3.8/site-packages/isort/api.py", line 272, in check_stream
    printer = create_terminal_printer(
  File "/home/runner/.local/share/virtualenvs/python-fi6_LwSQ/lib/python3.8/site-packages/isort/format.py", line 153, in create_terminal_printer
    colorama.init(strip=False)
NameError: name 'colorama' is not defined
@aryyh
Copy link
Author

aryyh commented May 15, 2023

Tested this with stable 5.12.0 and it's working fine. It has a follow up on fix here that hasn't made it to the pre-release version of isort

@aryyh aryyh changed the title Issue #2031 not fixed, request re-open Issue #2031 not fixed in v6.0.0b2 May 15, 2023
@amarvin
Copy link

amarvin commented Dec 13, 2023

Not sure if this is the same, but I've got GitHub Actions failing in a Ubuntu runtime with Python 3.10.13 that tries to run these commands, but fails on the second:

pip install isort[colors]==5.13.1
isort . --color

with error traceback:

Sorry, but to use --color (color_output) the colorama python package is required.

Reference: https://pypi.org/project/colorama/

You can either install it separately on your system or as the colors extra for isort. Ex: 

$ pip install isort[colors]

Maybe same as #2211.

@staticdev
Copy link
Collaborator

Correct @amarvin, fixed in 5.13.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants