Skip to content

Conversation

@geieredgar
Copy link
Contributor

@geieredgar geieredgar commented Jul 22, 2019

Resolves #1073

if setting not in COLOR_CHOICES:
raise InvalidColorSetting(setting)

if 'NO_COLOR' in os.environ:
Copy link
Member

Choose a reason for hiding this comment

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

this isn't quite right -- NO_COLOR= git commit ... should still have color

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asottile Ok, I pushed a new commit

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

looks good -- mind adding a quick test in tests/color_test.py -- you can use either mock.patch.dict(os.environ, ...) or pre_commit.envcontext.envcontext to test the various cases -- probably just needs these three cases considered:

  • unset
  • set to empty string
  • set to non-empty string

raise InvalidColorSetting(setting)

if 'NO_COLOR' in os.environ:
if 'NO_COLOR' in os.environ and os.environ['NO_COLOR']:
Copy link
Member

Choose a reason for hiding this comment

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

if os.environ.get('NO_COLOR') would be ~slightly simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will change that.

@geieredgar
Copy link
Contributor Author

Ok, I will do that



def test_no_color_env_unset():
with mock.patch.dict(os.environ):
Copy link
Member

Choose a reason for hiding this comment

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

clear=True is what you want here I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that remove all entries from os.environ? It would probably still work, though.

Copy link
Member

Choose a reason for hiding this comment

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

yes, and yes

I guess if you want to be more direct you could use:

with envcontext([('NO_COLOR', UNSET)]):
    ...

envcotext and UNSET come from pre_commit.envcontext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will change that because otherwise the coverage is reduced.

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

@asottile asottile merged commit 1874cea into pre-commit:master Jul 22, 2019
@asottile
Copy link
Member

thanks again! and thanks @saper for the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Globally disable color?

2 participants