From d46fdab7c565a2565aad128137327e486578c783 Mon Sep 17 00:00:00 2001 From: Preston Holmes Date: Sat, 7 Jul 2012 22:28:10 -0700 Subject: [PATCH] get_apps -> get_models_modules --- django/apps/cache.py | 8 +++++++- django/contrib/admin/validation.py | 3 ++- django/contrib/contenttypes/management.py | 4 ++-- django/core/management/commands/dumpdata.py | 4 ++-- django/core/management/commands/flush.py | 2 +- django/core/management/commands/loaddata.py | 4 ++-- django/core/management/sql.py | 2 +- django/core/serializers/base.py | 2 +- django/core/serializers/python.py | 3 ++- django/db/backends/__init__.py | 7 ++++--- django/test/simple.py | 3 +-- tests/appcachetests/cachetests/tests.py | 14 +++++++------- tests/runtests.py | 4 ++-- 13 files changed, 34 insertions(+), 26 deletions(-) diff --git a/django/apps/cache.py b/django/apps/cache.py index a05e01285338b..a2644c3b10909 100644 --- a/django/apps/cache.py +++ b/django/apps/cache.py @@ -241,7 +241,7 @@ def ready(self): """ return self.loaded - def get_apps(self): + def get_models_modules(self): """ Returns a list of all models modules. """ @@ -272,6 +272,12 @@ def get_app(self, app_label, emptyOK=False): PendingDeprecationWarning) return self.get_model_module(app_label, emptyOK=emptyOK) + def get_apps(self): + warnings.warn( + 'get_apps is deprecated, please use cache.get_models_modules', + PendingDeprecationWarning) + return self.get_model_modules() + def get_app_errors(self): """ Returns the map of known problems with the INSTALLED_APPS. diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 733f89d06f088..89bdb918edbae 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -1,3 +1,4 @@ +from django.apps import cache from django.core.exceptions import ImproperlyConfigured from django.db import models from django.db.models.fields import FieldDoesNotExist @@ -19,7 +20,7 @@ def validate(cls, model): """ # Before we can introspect models, they need to be fully loaded so that # inter-relations are set up correctly. We force that here. - models.get_apps() + cache._populate() opts = model._meta validate_base(cls, model) diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py index 26ba169bbe5fb..458181520dd94 100644 --- a/django/contrib/contenttypes/management.py +++ b/django/contrib/contenttypes/management.py @@ -1,4 +1,4 @@ -from django.apps import cache, get_apps, get_models +from django.apps import cache, get_models from django.contrib.contenttypes.models import ContentType from django.utils.encoding import smart_text from django.utils import six @@ -74,7 +74,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs): print("Stale content types remain.") def update_all_contenttypes(verbosity=2, **kwargs): - for app in get_apps(): + for app in cache.get_models_modules(): update_contenttypes(app, None, verbosity, **kwargs) signals.post_syncdb.connect(update_contenttypes) diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index df0e981b78479..0836196cce95b 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -29,7 +29,7 @@ class Command(BaseCommand): args = '[appname appname.ModelName ...]' def handle(self, *app_labels, **options): - from django.db.models import get_apps, get_model + from django.db.models import get_model format = options.get('format') indent = options.get('indent') @@ -56,7 +56,7 @@ def handle(self, *app_labels, **options): raise CommandError('Unknown app in excludes: %s' % exclude) if len(app_labels) == 0: - app_list = SortedDict((app, None) for app in get_apps() if app not in excluded_apps) + app_list = SortedDict((app, None) for app in cache.get_models_modules() if app not in excluded_apps) else: app_list = SortedDict() for label in app_labels: diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 4fb65844398a6..68b421a63bae8 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -75,7 +75,7 @@ def handle_noargs(self, **options): # applications to respond as if the database had been # sync'd from scratch. all_models = [] - for app in models.get_apps(): + for app in cache.get_models_modules(): all_models.extend([ m for m in models.get_models(app, include_auto_created=True) if router.allow_syncdb(db, m) diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 30cf740cdf90a..0741df168518d 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -7,13 +7,13 @@ from optparse import make_option import traceback +from django.apps import cache from django.conf import settings from django.core import serializers from django.core.management.base import BaseCommand, CommandError from django.core.management.color import no_style from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS, IntegrityError, DatabaseError) -from django.db.models import get_apps from django.utils.encoding import force_text from itertools import product @@ -92,7 +92,7 @@ def read(self): compression_types['bz2'] = bz2.BZ2File app_module_paths = [] - for app in get_apps(): + for app in cache.get_models_modules(): if hasattr(app, '__path__'): # It's a 'models/' subpackage for path in app.__path__: diff --git a/django/core/management/sql.py b/django/core/management/sql.py index d4b971ffdb5f0..a083794cf643a 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -178,7 +178,7 @@ def custom_sql_for_model(model, style, connection): def emit_post_sync_signal(created_models, verbosity, interactive, db): # Emit the post_sync signal for every application. - for app in models.get_apps(): + for app in cache.get_models_modules(): app_cls = cache.find_app_by_models_module(app) app_name = app_cls._meta.label if verbosity >= 2: diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index 276f9a4738639..a6f4c059ec88b 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -129,7 +129,7 @@ def __init__(self, stream_or_string, **options): # hack to make sure that the models have all been loaded before # deserialization starts (otherwise subclass calls to get_model() # and friends might fail...) - models.get_apps() + cache._populate() def __iter__(self): return self diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index a1fff6f9bbc37..3e7512808b8af 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -5,6 +5,7 @@ """ from __future__ import unicode_literals +from django.apps import cache from django.conf import settings from django.core.serializers import base from django.db import models, DEFAULT_DB_ALIAS @@ -80,7 +81,7 @@ def Deserializer(object_list, **options): stream or a string) to the constructor """ db = options.pop('using', DEFAULT_DB_ALIAS) - models.get_apps() + cache._populate() for d in object_list: # Look up the model and starting build a dict of data for it. Model = _get_model(d["model"]) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 649f807f26458..0203bc0c7df79 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -6,6 +6,7 @@ from django.utils.six.moves import _dummy_thread as thread from contextlib import contextmanager +from django.apps import cache from django.conf import settings from django.db import DEFAULT_DB_ALIAS from django.db.backends import util @@ -967,7 +968,7 @@ def django_table_names(self, only_existing=False): """ from django.db import models, router tables = set() - for app in models.get_apps(): + for app in cache.get_models_modules(): for model in models.get_models(app): if not model._meta.managed: continue @@ -989,7 +990,7 @@ def installed_models(self, tables): "Returns a set of all models represented by the provided list of table names." from django.db import models, router all_models = [] - for app in models.get_apps(): + for app in cache.get_models_modules(): for model in models.get_models(app): if router.allow_syncdb(self.connection.alias, model): all_models.append(model) @@ -1003,7 +1004,7 @@ def sequence_list(self): "Returns a list of information about all DB sequences for all models in all apps." from django.db import models, router - apps = models.get_apps() + apps = cache.get_models_modules() sequence_list = [] for app in apps: diff --git a/django/test/simple.py b/django/test/simple.py index 762cef1088458..09d1def957724 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -3,7 +3,6 @@ from django.apps import cache from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.db.models import get_apps from django.test import _doctest as doctest from django.test.utils import setup_test_environment, teardown_test_environment from django.test.testcases import OutputChecker, DocTestRunner @@ -257,7 +256,7 @@ def build_suite(self, test_labels, extra_tests=None, **kwargs): app = cache.get_models_module(label) suite.addTest(build_suite(app)) else: - for app in get_apps(): + for app in cache.get_models_modules: suite.addTest(build_suite(app)) if extra_tests: diff --git a/tests/appcachetests/cachetests/tests.py b/tests/appcachetests/cachetests/tests.py index ebae9812838a1..f5af1c2954226 100755 --- a/tests/appcachetests/cachetests/tests.py +++ b/tests/appcachetests/cachetests/tests.py @@ -146,8 +146,8 @@ def test_incorrect_subclass(self): settings.INSTALLED_APPS[0]) -class GetAppsTests(AppCacheTestCase): - """Tests for the get_apps function""" +class GetModelsModulesTests(AppCacheTestCase): + """Tests for the get_models_modules function""" def test_app_classes(self): """ @@ -155,7 +155,7 @@ def test_app_classes(self): installed via the INSTALLED_APPS setting """ settings.INSTALLED_APPS = ('model_app.app.MyApp',) - apps = cache.get_apps() + apps = cache.get_models_modules() self.assertTrue(cache.ready()) self.assertEquals(apps[0].__name__, 'model_app.othermodels') @@ -165,7 +165,7 @@ def test_installed_apps(self): via the INSTALLED_APPS setting """ settings.INSTALLED_APPS = ('model_app',) - apps = cache.get_apps() + apps = cache.get_models_modules() self.assertTrue(cache.ready()) self.assertEquals(apps[0].__name__, 'model_app.models') @@ -175,7 +175,7 @@ def test_same_app_in_both_settings(self): only one of them is loaded """ settings.INSTALLED_APPS = ('model_app.app.MyApp', 'model_app') - apps = cache.get_apps() + apps = cache.get_models_modules() self.assertEquals(len(apps), 1) self.assertEquals(apps[0].__name__, 'model_app.othermodels') @@ -184,7 +184,7 @@ def test_empty_models(self): Test that modules that don't contain models are not returned """ settings.INSTALLED_APPS = ('nomodel_app',) - self.assertEqual(cache.get_apps(), []) + self.assertEqual(cache.get_models_modules(), []) self.assertTrue(cache.ready()) def test_db_prefix_exception(self): @@ -194,7 +194,7 @@ def test_db_prefix_exception(self): """ settings.INSTALLED_APPS = ('nomodel_app.app.MyApp', 'model_app.app.MyOtherApp') - self.assertRaises(ImproperlyConfigured, cache.get_apps) + self.assertRaises(ImproperlyConfigured, cache.get_models_modules) class GetModelsModuleTests(AppCacheTestCase): diff --git a/tests/runtests.py b/tests/runtests.py index 02a0b11ad468c..65051e344fa2e 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -180,7 +180,7 @@ def bisect_tests(bisection_label, options, test_labels): if not test_labels: # Get the full list of test labels to use for bisection from django.apps import cache - test_labels = [app.__name__.split('.')[-2] for app in cache.get_apps()] + test_labels = [app.__name__.split('.')[-2] for app in cache.get_models_modules()] print('***** Bisecting test suite: %s' % ' '.join(test_labels)) @@ -241,7 +241,7 @@ def paired_tests(paired_test, options, test_labels): print("") # Get the full list of test labels to use for bisection from django.apps import cache - test_labels = [app.__name__.split('.')[-2] for app in cache.get_apps()] + test_labels = [app.__name__.split('.')[-2] for app in cache.get_models_modules()] print('***** Trying paired execution')