Skip to content

Commit

Permalink
[1.7.x] Fixed #22194 -- Added --list-tags option to check command.
Browse files Browse the repository at this point in the history
Thanks Elvard for the patch.

Backport of 395d75e from master
  • Loading branch information
timgraham committed Apr 10, 2014
1 parent 32e6237 commit ddd25b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/core/checks/registry.py
Expand Up @@ -64,8 +64,10 @@ def run_checks(self, app_configs=None, tags=None):
return errors

def tag_exists(self, tag):
tags = chain(*[check.tags for check in self.registered_checks if hasattr(check, 'tags')])
return tag in tags
return tag in self.tags_available()

def tags_available(self):
return set(chain(*[check.tags for check in self.registered_checks if hasattr(check, 'tags')]))


registry = CheckRegistry()
Expand Down
7 changes: 7 additions & 0 deletions django/core/management/commands/check.py
Expand Up @@ -5,6 +5,7 @@

from django.apps import apps
from django.core import checks
from django.core.checks.registry import registry
from django.core.management.base import BaseCommand, CommandError


Expand All @@ -16,9 +17,15 @@ class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--tag', '-t', action='append', dest='tags',
help='Run only checks labeled with given tag.'),
make_option('--list-tags', action='store_true', dest='list_tags',
help='List available tags.'),
)

def handle(self, *app_labels, **options):
if options.get('list_tags'):
self.stdout.write('\n'.join(sorted(registry.tags_available())))
return

if app_labels:
app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
else:
Expand Down
4 changes: 4 additions & 0 deletions docs/ref/django-admin.txt
Expand Up @@ -126,6 +126,10 @@ to perform only security and compatibility checks, you would run::

python manage.py check --tag security --tag compatibility

.. django-admin-option:: --list-tags

List all available tags.

compilemessages
---------------

Expand Down
10 changes: 10 additions & 0 deletions tests/check_framework/tests.py
Expand Up @@ -194,6 +194,16 @@ def test_given_tag(self):
def test_invalid_tag(self):
self.assertRaises(CommandError, call_command, 'check', tags=['missingtag'])

@override_system_checks([simple_system_check])
def test_list_tags_empty(self):
call_command('check', list_tags=True)
self.assertEqual('\n', sys.stdout.getvalue())

@override_system_checks([tagged_system_check])
def test_list_tags(self):
call_command('check', list_tags=True)
self.assertEqual('simpletag\n', sys.stdout.getvalue())


def custom_error_system_check(app_configs, **kwargs):
return [
Expand Down

0 comments on commit ddd25b2

Please sign in to comment.