Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.1.36
++++++
* Remove colorama reference (#321)

0.1.35
++++++
* Support Python 3.10 (#319)
Expand Down
2 changes: 1 addition & 1 deletion azdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------

__VERSION__ = '0.1.35'
__VERSION__ = '0.1.36'
23 changes: 13 additions & 10 deletions azdev/operations/linter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pkgutil import iter_modules
from enum import Enum
import yaml
import colorama
from knack.log import get_logger

from azdev.utilities.path import get_cli_repo_path, get_ext_repo_paths
Expand Down Expand Up @@ -255,7 +254,6 @@ def run(self, run_params=None, run_commands=None, run_command_groups=None, run_h
found_rules.add(rule_name)
add_to_linter_func(self)

colorama.init()
# run all rule-checks
if run_help_files_entries and self._rules.get('help_file_entries'):
self._run_rules('help_file_entries')
Expand Down Expand Up @@ -290,11 +288,15 @@ def run(self, run_params=None, run_commands=None, run_command_groups=None, run_h
with open(exclusion_path, 'w') as f:
yaml.safe_dump(exclusions, f)

colorama.deinit()
return self.exit_code

def _run_rules(self, rule_group):
from colorama import Fore
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting
RED = '\x1b[31m'
GREEN = '\x1b[32m'
YELLOW = '\x1b[33m'
CYAN = '\x1b[36m'
RESET = '\x1b[39m'
Comment on lines +295 to +299
Copy link
Member Author

Choose a reason for hiding this comment

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

>>> import colorama
>>> colorama.Fore.RED
'\x1b[31m'
>>> colorama.Fore.GREEN
'\x1b[32m'
>>> colorama.Fore.YELLOW
'\x1b[33m'
>>> colorama.Fore.CYAN
'\x1b[36m'
>>> colorama.Fore.RESET
'\x1b[39m'

for rule_name, (rule_func, linter_callable, rule_severity) in self._rules.get(rule_group).items():
severity_str = rule_severity.name
# use new linter if needed
Expand All @@ -304,20 +306,21 @@ def _run_rules(self, rule_group):
violations = sorted(rule_func()) or []
if violations:
if rule_severity == LinterSeverity.HIGH:
sev_color = Fore.RED
sev_color = RED
elif rule_severity == LinterSeverity.MEDIUM:
sev_color = Fore.YELLOW
sev_color = YELLOW
else:
sev_color = Fore.CYAN
sev_color = CYAN

print('- {} FAIL{} - {}{}{} severity: {}'.format(Fore.RED, Fore.RESET, sev_color,
severity_str, Fore.RESET, rule_name,))
# pylint: disable=duplicate-string-formatting-argument
print('- {} FAIL{} - {}{}{} severity: {}'.format(RED, RESET, sev_color,
severity_str, RESET, rule_name,))
for violation_msg, entity_name, name in violations:
print(violation_msg)
self._save_violations(entity_name, name)
print()
else:
print('- {} pass{}: {} '.format(Fore.GREEN, Fore.RESET, rule_name))
print('- {} pass{}: {} '.format(GREEN, RESET, rule_name))

def _linter_severity_is_applicable(self, rule_severity, rule_name):
if self.min_severity.value > rule_severity.value:
Expand Down