summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@gmail.com>2014-10-20 18:01:03 +0700
committerLoic Bistuer <loic.bistuer@gmail.com>2014-10-22 01:03:15 +0700
commitc34e13e17c664ea43b85572428bcf74c7509db3f (patch)
tree8e19c3d6ea197d3748404a5f32053b67bc745d4e
parent9f1202c166093160c8796dc570d675415fdf5bf8 (diff)
Fixed #23107 -- Made runserver output respect --no-color.
This commit reverts 67d7da5fb9498b811f0168f5df2308ad4743027f. 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.
-rw-r--r--django/core/management/base.py1
-rw-r--r--django/core/management/commands/runserver.py8
-rw-r--r--tests/admin_scripts/tests.py1
3 files changed, 8 insertions, 2 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index 910b43ecd2..7b62d6c259 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -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)
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index 58011b67b7..28b52e31ac 100644
--- a/django/core/management/commands/runserver.py
+++ b/django/core/management/commands/runserver.py
@@ -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.
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index b5eeac713b..2b3f4824fd 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -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):