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

Add support for PyCharm #163

Merged
merged 3 commits into from May 3, 2018
Merged

Add support for PyCharm #163

merged 3 commits into from May 3, 2018

Conversation

veleek
Copy link
Contributor

@veleek veleek commented Apr 16, 2018

Fixes #107
Replaces the abandoned #108

@veleek
Copy link
Contributor Author

veleek commented Apr 16, 2018

This change is incredibly simple, and I think it's mostly the intended behavior. PyCharm behaves like a TTY (at least for colorama's intents) so this isolates the changes to one place and in the future if there need to be additional platforms/apps added this would be a reasonable place to do so.

@veleek
Copy link
Contributor Author

veleek commented Apr 28, 2018

Ping @tartley. Any chance we could get this pulled in?

@@ -18,7 +18,8 @@ def is_stream_closed(stream):


def is_a_tty(stream):
return hasattr(stream, 'isatty') and stream.isatty()
is_pycharm = 'PYCHARM_HOSTED' in os.environ
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will look better if we do:
if 'PYCHARM_HOSTED' in os.environ: return True and then leave the original return as it was. This is not important, though - what do you think?

@wiggin15
Copy link
Collaborator

Looks like the request to support PyCharm is quite popular so let's pull it in. See my comment on the commit.

@tartley
Copy link
Owner

tartley commented Apr 30, 2018

@veleek Hi thanks for the input. Looks good to me but I'm going to let @wiggin15 push the button - I don't use Windows any longer so he'll have to support it going forwards.

@veleek
Copy link
Contributor Author

veleek commented May 1, 2018

@wiggin15 Sounds good to me. Made the change and just pushed it.

@wiggin15
Copy link
Collaborator

wiggin15 commented May 3, 2018

Oops. When I wrote if 'PYCHARM_HOSTED' in os.environ: return True in one line, I meant it indented, i.e.

if 'PYCHARM_HOSTED' in os.environ:
    return True

The one-line works but doesn't look very "pythonic". Sorry for the hassle.

@veleek
Copy link
Contributor Author

veleek commented May 3, 2018

:) I'm pretty new to python, so I'm not familiar with the standard styles.

Fixed!

@wiggin15 wiggin15 merged commit e19cbb7 into tartley:master May 3, 2018
@wiggin15
Copy link
Collaborator

wiggin15 commented May 3, 2018

Thanks for the pull request! This will be included in the next release of colorama (I'm not sure when it will be released).

@Delgan
Copy link
Contributor

Delgan commented May 11, 2018

Hi @veleek and @wiggin15.

Does this change imply that every stream checked using colorama.is_a_tty() or wrapped using AnsiToWin32() will be considered as colorable while developing with Pycharm?

From what I guess looking at the source code, I'm afraid that using is_a_tty() with a file stream for example will wrongly return True on PyCharm, which means we could not use AnsiToWin32() with arbitrary stream (calling it with a non-tty stream would wrap it anyway).

I see two possible solutions:

  • In is_a_tty(), check that PYCHARM_HOSTED exists and check that the stream is stderr or stdout
  • Move the PYCHARM_HOSTED check to the init() function

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

Successfully merging this pull request may close these issues.

None yet

4 participants