Commit c34e13e1 authored by Loic Bistuer's avatar Loic Bistuer
Browse files

Fixed #23107 -- Made runserver output respect --no-color.

This commit reverts 67d7da5f.

The previous fix changed the environment globally, which meant
that any call to `call_command(no_color=True)` prevented further
`call_command` with color.

This fix still relies on the environment because it's currently the only
way to reach WSGIRequestHandler, but it's now limited to the `runserver`
command. This seems an acceptable compromise considering `runserver` runs
indefinitely.

Thanks Tim Graham for the review.
parent 9f1202c1
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -386,7 +386,6 @@ class BaseCommand(object):
        if options.get('no_color'):
            self.style = no_style()
            self.stderr = OutputWrapper(options.get('stderr', sys.stderr))
            os.environ[str("DJANGO_COLORS")] = str("nocolor")
        else:
            self.stderr = OutputWrapper(options.get('stderr', sys.stderr), self.style.ERROR)

+8 −0
Original line number Diff line number Diff line
@@ -41,6 +41,14 @@ class Command(BaseCommand):
        parser.add_argument('--noreload', action='store_false', dest='use_reloader', default=True,
            help='Tells Django to NOT use the auto-reloader.')

    def execute(self, *args, **options):
        if options.get('no_color'):
            # We rely on the environment because it's currently the only
            # way to reach WSGIRequestHandler. This seems an acceptable
            # compromise considering `runserver` runs indefinitely.
            os.environ[str("DJANGO_COLORS")] = str("nocolor")
        super(Command, self).execute(*args, **options)

    def get_handler(self, *args, **options):
        """
        Returns the default WSGI handler for the runner.
+0 −1
Original line number Diff line number Diff line
@@ -1397,7 +1397,6 @@ class CommandTypes(AdminScriptTestCase):
        out = StringIO()

        call_command('color_command', no_color=True, stdout=out)
        self.assertEqual(os.environ.get('DJANGO_COLORS', ''), 'nocolor')
        self.assertEqual(out.getvalue(), 'BEGIN\n')

    def test_base_command(self):