Skip to content

Commit

Permalink
get_apps -> get_models_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ptone committed Aug 28, 2012
1 parent 2304034 commit d46fdab
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 26 deletions.
8 changes: 7 additions & 1 deletion django/apps/cache.py
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion 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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/dumpdata.py
Expand Up @@ -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')
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/commands/flush.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/loaddata.py
Expand Up @@ -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

Expand Down Expand Up @@ -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__:
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/sql.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/core/serializers/base.py
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion django/core/serializers/python.py
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down
7 changes: 4 additions & 3 deletions django/db/backends/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions django/test/simple.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions tests/appcachetests/cachetests/tests.py
Expand Up @@ -146,16 +146,16 @@ 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):
"""
Test that the correct models modules are returned for app classes
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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/runtests.py
Expand Up @@ -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))

Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit d46fdab

Please sign in to comment.