diff options
| author | Daniel Lindsley <daniel@toastdriven.com> | 2013-06-13 18:39:02 -0700 |
|---|---|---|
| committer | Daniel Lindsley <daniel@toastdriven.com> | 2013-06-13 18:39:02 -0700 |
| commit | 91f317c76d503b4bcae5a26c230425944dbf4ea8 (patch) | |
| tree | 5373097cbee1993bfb229dc5a6067e9c46685e02 /django | |
| parent | 70d7e45eb0888f979775c997935bfee84c85d189 (diff) | |
Added a ``checksetup`` management command for verifying Django compatibility.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/compat_checks/__init__.py | 0 | ||||
| -rw-r--r-- | django/core/compat_checks/base.py | 39 | ||||
| -rw-r--r-- | django/core/compat_checks/django_1_6_0.py | 37 | ||||
| -rw-r--r-- | django/core/management/commands/checksetup.py | 14 |
4 files changed, 90 insertions, 0 deletions
diff --git a/django/core/compat_checks/__init__.py b/django/core/compat_checks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/django/core/compat_checks/__init__.py diff --git a/django/core/compat_checks/base.py b/django/core/compat_checks/base.py new file mode 100644 index 0000000000..b3d47a617c --- /dev/null +++ b/django/core/compat_checks/base.py @@ -0,0 +1,39 @@ +from __future__ import unicode_literals +import warnings + +from django.core.compat_checks import django_1_6_0 + + +COMPAT_CHECKS = [ + # Add new modules at the top, so we keep things in descending order. + # After two-three minor releases, old versions should get dropped. + django_1_6_0, +] + + +def check_compatibility(): + """ + Runs through compatibility checks to warn the user with an existing install + about changes in an up-to-date Django. + + Modules should be located in ``django.core.compat_checks`` (typically one + per release of Django) & must have a ``run_checks`` function that runs + all the checks. + + Returns a list of informational messages about incompatibilities. + """ + messages = [] + + for check_module in COMPAT_CHECKS: + check = getattr(check_module, u'run_checks', None) + + if check is None: + warnings.warn( + u"The '%s' module lacks a " % check_module.__name__ + + u"'run_checks' method, which is needed to verify compatibility." + ) + continue + + messages.extend(check()) + + return messages diff --git a/django/core/compat_checks/django_1_6_0.py b/django/core/compat_checks/django_1_6_0.py new file mode 100644 index 0000000000..53fe150cab --- /dev/null +++ b/django/core/compat_checks/django_1_6_0.py @@ -0,0 +1,37 @@ +from __future__ import unicode_literals + + +def check_test_runner(): + """ + Checks if the user has *not* overridden the ``TEST_RUNNER`` setting & + warns them about the default behavior changes. + + If the user has overridden that setting, we presume they know what they're + doing & avoid generating a message. + """ + from django.conf import settings + new_default = u'django.test.runner.DiscoverRunner' + test_runner_setting = getattr(settings, u'TEST_RUNNER', new_default) + + if test_runner_setting == new_default: + message = [ + u"You have not explicitly set 'TEST_RUNNER'. In Django 1.6,", + u"there is a new test runner ('%s')" % new_default, + u"by default. You should ensure your tests are still all", + u"running & behaving as expected. See", + u"https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module", + u"for more information.", + ] + return u' '.join(message) + + +def run_checks(): + """ + Required by the ``checksetup`` management command, this returns a list of + messages from all the relevant check functions for this version of Django. + """ + checks = [ + check_test_runner() + ] + # Filter out the ``None`` or empty strings. + return [output for output in checks if output] diff --git a/django/core/management/commands/checksetup.py b/django/core/management/commands/checksetup.py new file mode 100644 index 0000000000..35082b6093 --- /dev/null +++ b/django/core/management/commands/checksetup.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +import warnings + +from django.core.compat_checks.base import check_compatibility +from django.core.management.base import NoArgsCommand + + +class Command(NoArgsCommand): + help = u"Checks your configuration's compatibility with this version " + \ + u"of Django." + + def handle_noargs(self, **options): + for message in check_compatibility(): + warnings.warn(message) |
