No_color в переопределенной команде django не работает
Я переопределил команду django check в ~/<project_name>/commands/management/commands/check.py, которая выглядит следующим образом:
from django.core.management.commands import check
class Command(check.Command):
help = 'My Customized Version of the Original check Command'
def handle(self, *args, **options):
print('>>> Running customized check')
options['deploy'] = True
options['no_color'] = True
super(Command, self).handle(*args, **options)
Запуск manage.py check 2>/tmp/check-output запускает команду, но проблема в том, что, несмотря на установку 'no_color', вывод все равно окрашивается, и мне приходится запускать его как manage.py check --no-color 2>/tmp/check-output
no_color - это не параметр, который передается самой команде управления, а момент построения BaseCommand, поэтому вы работаете с:
from django.core.management.commands import check
class Command(check.Command):
help = 'My Customized Version of the Original check Command'
def __init__(self, *args, **kwargs):
kwargs['no_color'] = not kwargs.get('force_color', False)
super().__init__(*args, **kwargs)
def handle(self, *args, **options):
print('>>> Running customized check')
options['deploy'] = True
super().handle(*args, **options)
Note: Since PEP-3135 [pep], you don't need to call
super(…)with parameters if the first parameter is the class in which you define the method, and the second is the first parameter (usuallyself) of the function.