diff --git a/django/apps/cache.py b/django/apps/cache.py index 034971c624..6f673704ac 100644 --- a/django/apps/cache.py +++ b/django/apps/cache.py @@ -5,6 +5,7 @@ import imp from importlib import import_module import os import sys +import warnings from django.conf import settings from django.core.exceptions import ImproperlyConfigured @@ -194,36 +195,6 @@ class BaseAppCache(object): """ return [app_config.models_module for app_config in self.get_app_configs()] - def _get_app_package(self, app): - return '.'.join(app.__name__.split('.')[:-1]) - - def get_app_package(self, app_label): - return self._get_app_package(self.get_app(app_label)) - - def _get_app_path(self, app): - if hasattr(app, '__path__'): # models/__init__.py package - app_path = app.__path__[0] - else: # models.py module - app_path = app.__file__ - return os.path.dirname(upath(app_path)) - - def get_app_path(self, app_label): - return self._get_app_path(self.get_app(app_label)) - - def get_app_paths(self): - """ - Returns a list of paths to all installed apps. - - Useful for discovering files at conventional locations inside apps - (static files, templates, etc.) - """ - self._populate() - - app_paths = [] - for app in self.get_apps(): - app_paths.append(self._get_app_path(app)) - return app_paths - def get_app(self, app_label): """ Returns the module containing the models for the given app_label. @@ -363,6 +334,48 @@ class BaseAppCache(object): def unset_available_apps(self): self.available_apps = None + ### DEPRECATED METHODS GO BELOW THIS LINE ### + + def _get_app_package(self, app): + return '.'.join(app.__name__.split('.')[:-1]) + + def get_app_package(self, app_label): + warnings.warn( + "get_app_config(label).name supersedes get_app_package(label).", + PendingDeprecationWarning, stacklevel=2) + return self._get_app_package(self.get_app(app_label)) + + def _get_app_path(self, app): + if hasattr(app, '__path__'): # models/__init__.py package + app_path = app.__path__[0] + else: # models.py module + app_path = app.__file__ + return os.path.dirname(upath(app_path)) + + def get_app_path(self, app_label): + warnings.warn( + "get_app_config(label).path supersedes get_app_path(label).", + PendingDeprecationWarning, stacklevel=2) + return self._get_app_path(self.get_app(app_label)) + + def get_app_paths(self): + """ + Returns a list of paths to all installed apps. + + Useful for discovering files at conventional locations inside apps + (static files, templates, etc.) + """ + warnings.warn( + "[a.path for a in get_app_configs()] supersedes get_app_paths().", + PendingDeprecationWarning, stacklevel=2) + + self._populate() + + app_paths = [] + for app in self.get_apps(): + app_paths.append(self._get_app_path(app)) + return app_paths + class AppCache(BaseAppCache): """ diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 64a57fbc79..bfeba68aa6 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -230,8 +230,8 @@ class Command(BaseCommand): current directory. """ dirs = [] - for path in app_cache.get_app_paths(): - d = os.path.join(path, 'fixtures') + for app_config in app_cache.get_app_configs(): + d = os.path.join(app_config.path, 'fixtures') if os.path.isdir(d): dirs.append(d) dirs.extend(list(settings.FIXTURE_DIRS)) diff --git a/django/core/management/sql.py b/django/core/management/sql.py index bcd4769dde..36ee5760e1 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -169,7 +169,7 @@ def _split_statements(content): def custom_sql_for_model(model, style, connection): opts = model._meta app_dirs = [] - app_dir = app_cache.get_app_path(model._meta.app_label) + app_dir = app_cache.get_app_config(model._meta.app_label).path app_dirs.append(os.path.normpath(os.path.join(app_dir, 'sql'))) # Deprecated location -- remove in Django 1.9 diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py index f4a7168441..859e57f352 100644 --- a/django/db/migrations/loader.py +++ b/django/db/migrations/loader.py @@ -46,7 +46,7 @@ class MigrationLoader(object): if app_label in settings.MIGRATION_MODULES: return settings.MIGRATION_MODULES[app_label] else: - return '%s.migrations' % app_cache.get_app_package(app_label) + return '%s.migrations' % app_cache.get_app_config(app_label).name def load_disk(self): """ diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 9356c8d8aa..a23a9b1253 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -69,14 +69,12 @@ class MigrationWriter(object): migrations_module = import_module(migrations_package_name) basedir = os.path.dirname(migrations_module.__file__) except ImportError: - app = app_cache.get_app(self.migration.app_label) - app_path = app_cache._get_app_path(app) - app_package_name = app_cache._get_app_package(app) + app_config = app_cache.get_app_config(self.migration.app_label) migrations_package_basename = migrations_package_name.split(".")[-1] # Alright, see if it's a direct submodule of the app - if '%s.%s' % (app_package_name, migrations_package_basename) == migrations_package_name: - basedir = os.path.join(app_path, migrations_package_basename) + if '%s.%s' % (app_config.name, migrations_package_basename) == migrations_package_name: + basedir = os.path.join(app_config.path, migrations_package_basename) else: raise ImportError("Cannot open migrations module %s for app %s" % (migrations_package_name, self.migration.app_label)) return os.path.join(basedir, self.filename) diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index d548f275fe..c3b0cda95b 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -223,7 +223,8 @@ these changes. to :setting:`CACHES` and use :data:`django.core.cache.caches` instead. * ``django.db.models.loading`` will be removed. Use the new application - loading APIs instead. + loading APIs instead. Several undocumented methods of the ``AppCache`` class + will also be removed. 2.0 ---