Moving notes for assertNumQueries next to the other changes to test infrastructure
Moved django.db.models.loading to django.apps.cache.

This commit doesn't contain any code changes; it's purely a refactoring.
Removed BaseAppCache.app_store.

It was only storing redundant information. This is part of the effort to
allow applications without a models module.
Removed ModelDict.

Its only difference with OrderedDict is that it didn't deepcopy its
keys. However it wasn't used anywhere with models modules as keys, only
as values. So this commit doesn't result in any change in functionality.
Removed model-level functions for the app cache.

Since the original ones in django.db.models.loading were kept only for
backwards compatibility, there's no need to recreate them. However, many
internals of Django still relied on them.

They were also imported in django.db.models. They never appear in the
documentation, except a quick mention of get_models and get_app in the
1.2 release notes to document an edge case in GIS. I don't think that
makes them a public API.

This commit doesn't change the overall amount of global state but
clarifies that it's tied to the app_cache object instead of hiding it
behind half a dozen functions.
Stored AppConfig objects instead of models modules in the app cache.

This is a step towards allowing applications without a models module.
Removed unused attribute app_errors of the app cache.

get_app_errors() always returned an empty dictionary; this behavior is
preserved in django.db.models.loading until that module is deprecated.
Moved list of models inside AppConfig instances.

This commit is a refactoring with no change of functionality, according
to the following invariants:

- An app_label that was in app_configs and app_models stays in
  app_config and has its 'installed' attribute set to True.

- An app_label that was in app_models but not in app_configs is added to
  app_configs and has its 'installed' attribute set to True.

As a consequence, all the code that iterated on app_configs is modified
to check for the 'installed' attribute. Code that iterated on app_models
is rewritten in terms of app_configs.

Many tests that stored and restored the state of the app cache were
updated.

In the long term, we should reconsider the usefulness of allowing
importing models from non-installed applications. This doesn't sound
particularly useful, can be a trap in some circumstances, and causes
significant complexity in sensitive areas of Django.
Fleshed out AppConfig objects.

Marginally improved creation of AppConfig stubs for non-installed apps.
Added get_app_config() to look up app configs by label.

Refactored get_app() to rely on that method.

get_app() starts by calling _populate(), which goes through
INSTALLED_APPS and, for each app, imports the app module and attempts to
import the models module. At this point, no further imports are
necessary to return the models module for a  given app. Therefore, the
implementation of get_app() can be simplified and the safeguards for
race conditions can be removed.

Besides, the emptyOK parameter isn't used anywhere in Django. It was
introduced in d6c95e93 but not actually used nor documented, and it has
just been carried around since then. Since it's an obscure private API,
it's acceptable to stop supporting it without a deprecation path. This
branch aims at providing first-class support for applications without a
models module eventually.

For backwards-compatibility, get_app() still raises ImproperlyConfigured
when an app isn't found, even though LookupError is technically more
correct. I haven't gone as far as to preserve the exact error messages.
I've adjusted a few tests instead.
Added get_app_configs() to iterate on app_config instances.

Refactored get_apps() to rely on that method.

This commit is fully backwards-compatible.
Deprecated get_app_package, get_app_path and get_app_paths.
Simplified handling of available_apps slightly.

It feels more natural for self.available_apps to contain app names (like
INSTALLED_APPS) than app labels, and this is easy to implement now.
Simplified register_models.

Since it's never called with more than one model at a time the current
signature is needlessly complicated.