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

Remove dependency on ansible.utils.color #833

Merged
merged 1 commit into from
Jun 17, 2020
Merged

Remove dependency on ansible.utils.color #833

merged 1 commit into from
Jun 17, 2020

Conversation

ssbarnea
Copy link
Member

Removes dependency on internal Ansible coloring implementation. This
was a problem for multiple reasons:

  • use of private Ansible APIs (color already broke linter once)
  • licensing: Ansible is GPL, linter is MIT
  • premature initialization of Ansible before our cli loads

The same colors are kept but now we set them using styles, making easier to restyle it if needed and to assure consistency.

lib/ansiblelint/color.py Outdated Show resolved Hide resolved
"""Color styles."""

reset = "0"
error_code = "1;31" # bright red
Copy link
Member

@webknjaz webknjaz Jun 16, 2020

Choose a reason for hiding this comment

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

This is problematic because it'll only work in terminals that support misusing the bold setting for bright. Standard-compliant terminals don't work like that.

It's roughly summarized here: kovidgoyal/kitty#197 (comment). And while for red it's semi-okay, for things like grey it's a disaster because it looks the same as the background == looks like empty lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

My change does not touch current behavior. ANSI support is a can of worms due to the variance in implementations. I am ok to investigate drop of bold but in a different change, also after looking at what other linters are doing with output (is likely that ansible-lint would be used in parallel with others too).

line = "0;35" # purple


def stringc(text: str, color: Color):
Copy link
Member

Choose a reason for hiding this comment

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

Since it's a function, it should be a verb:

Suggested change
def stringc(text: str, color: Color):
def colorize(text: str, color: Color):

Removes dependency on internal Ansible coloring implementation. This
was a problem for multiple reasons:
- use of private APIs
- licensing (Ansible is GPL)
- premature initialization of Ansible before our cli loads

The colors are kept but use styles instead of hardcoded colors.
@ssbarnea ssbarnea merged commit 9a3a03b into ansible:master Jun 17, 2020
@ssbarnea ssbarnea deleted the rm/color branch June 17, 2020 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants