Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deprecated django.utils.importlib

This was a shim for pre-Python 2.7 support.
  • Loading branch information...
commit fdd7a355bf053217d25b8d2189e37069c1304283 1 parent ac09558
@claudep claudep authored
Showing with 64 additions and 49 deletions.
  1. +1 −1  django/conf/__init__.py
  2. +2 −1  django/conf/urls/__init__.py
  3. +1 −1  django/contrib/admin/__init__.py
  4. +1 −1  django/contrib/admindocs/views.py
  5. +1 −1  django/contrib/auth/hashers.py
  6. +1 −1  django/contrib/comments/__init__.py
  7. +1 −1  django/contrib/formtools/tests/wizard/storage.py
  8. +2 −1  django/contrib/formtools/tests/wizard/test_forms.py
  9. +3 −2 django/contrib/gis/geometry/backend/__init__.py
  10. +2 −1  django/contrib/sessions/management/commands/clearsessions.py
  11. +1 −1  django/contrib/sessions/middleware.py
  12. +1 −1  django/contrib/staticfiles/storage.py
  13. +1 −1  django/core/cache/__init__.py
  14. +3 −3 django/core/management/__init__.py
  15. +1 −1  django/core/management/commands/flush.py
  16. +2 −1  django/core/management/commands/startapp.py
  17. +2 −1  django/core/management/commands/startproject.py
  18. +1 −1  django/core/management/commands/syncdb.py
  19. +2 −1  django/core/serializers/__init__.py
  20. +1 −1  django/core/servers/fastcgi.py
  21. +1 −1  django/core/urlresolvers.py
  22. +1 −1  django/db/backends/__init__.py
  23. +6 −6 django/db/models/loading.py
  24. +2 −2 django/db/utils.py
  25. +1 −1  django/template/base.py
  26. +1 −1  django/template/loaders/app_directories.py
  27. +1 −1  django/test/client.py
  28. +1 −1  django/test/simple.py
  29. +2 −2 django/utils/formats.py
  30. +5 −0 django/utils/importlib.py
  31. +1 −1  django/utils/module_loading.py
  32. +1 −1  django/utils/translation/trans_real.py
  33. +1 −1  django/views/i18n.py
  34. +2 −0  docs/internals/deprecation.txt
  35. +5 −4 docs/releases/1.7.txt
  36. +1 −1  tests/i18n/tests.py
  37. +1 −1  tests/test_runner/tests.py
  38. +1 −1  tests/utils_tests/test_module_loading.py
View
2  django/conf/__init__.py
@@ -6,6 +6,7 @@
a list of all possible variables.
"""
+import importlib
import logging
import os
import sys
@@ -15,7 +16,6 @@
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import LazyObject, empty
-from django.utils import importlib
from django.utils.module_loading import import_by_path
from django.utils import six
View
3  django/conf/urls/__init__.py
@@ -1,7 +1,8 @@
+from importlib import import_module
+
from django.core.urlresolvers import (RegexURLPattern,
RegexURLResolver, LocaleRegexURLResolver)
from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
from django.utils import six
View
2  django/contrib/admin/__init__.py
@@ -17,8 +17,8 @@ def autodiscover():
"""
import copy
+ from importlib import import_module
from django.conf import settings
- from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
for app in settings.INSTALLED_APPS:
View
2  django/contrib/admindocs/views.py
@@ -1,3 +1,4 @@
+from importlib import import_module
import inspect
import os
import re
@@ -13,7 +14,6 @@
from django.core import urlresolvers
from django.contrib.admindocs import utils
from django.contrib.sites.models import Site
-from django.utils.importlib import import_module
from django.utils._os import upath
from django.utils import six
from django.utils.translation import ugettext as _
View
2  django/contrib/auth/hashers.py
@@ -3,11 +3,11 @@
import base64
import binascii
import hashlib
+import importlib
from django.dispatch import receiver
from django.conf import settings
from django.test.signals import setting_changed
-from django.utils import importlib
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_str, force_text
from django.core.exceptions import ImproperlyConfigured
View
2  django/contrib/comments/__init__.py
@@ -1,10 +1,10 @@
+from importlib import import_module
import warnings
from django.conf import settings
from django.core import urlresolvers
from django.core.exceptions import ImproperlyConfigured
from django.contrib.comments.models import Comment
from django.contrib.comments.forms import CommentForm
-from django.utils.importlib import import_module
warnings.warn("django.contrib.comments is deprecated and will be removed before Django 1.8.", DeprecationWarning)
View
2  django/contrib/formtools/tests/wizard/storage.py
@@ -1,8 +1,8 @@
from datetime import datetime
+from importlib import import_module
from django.http import HttpRequest
from django.conf import settings
-from django.utils.importlib import import_module
from django.contrib.auth.models import User
View
3  django/contrib/formtools/tests/wizard/test_forms.py
@@ -1,11 +1,12 @@
from __future__ import unicode_literals
+from importlib import import_module
+
from django import forms, http
from django.conf import settings
from django.db import models
from django.test import TestCase
from django.template.response import TemplateResponse
-from django.utils.importlib import import_module
from django.contrib.auth.models import User
View
5 django/contrib/gis/geometry/backend/__init__.py
@@ -1,11 +1,12 @@
+from importlib import import_module
+
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
geom_backend = getattr(settings, 'GEOMETRY_BACKEND', 'geos')
try:
- module = import_module('.%s' % geom_backend, 'django.contrib.gis.geometry.backend')
+ module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
except ImportError:
try:
module = import_module(geom_backend)
View
3  django/contrib/sessions/management/commands/clearsessions.py
@@ -1,6 +1,7 @@
+from importlib import import_module
+
from django.conf import settings
from django.core.management.base import NoArgsCommand
-from django.utils.importlib import import_module
class Command(NoArgsCommand):
View
2  django/contrib/sessions/middleware.py
@@ -1,9 +1,9 @@
+from importlib import import_module
import time
from django.conf import settings
from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date
-from django.utils.importlib import import_module
class SessionMiddleware(object):
def __init__(self):
View
2  django/contrib/staticfiles/storage.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
import hashlib
+from importlib import import_module
import os
import posixpath
import re
@@ -18,7 +19,6 @@
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_text
from django.utils.functional import LazyObject
-from django.utils.importlib import import_module
from django.utils._os import upath
from django.contrib.staticfiles.utils import check_settings, matches_patterns
View
2  django/core/cache/__init__.py
@@ -14,6 +14,7 @@
See docs/topics/cache.txt for information on the public API.
"""
+import importlib
try:
from urllib.parse import parse_qsl
except ImportError: # Python 2
@@ -24,7 +25,6 @@
from django.core.cache.backends.base import (
InvalidCacheBackendError, CacheKeyWarning, BaseCache)
from django.core.exceptions import ImproperlyConfigured
-from django.utils import importlib
from django.utils.module_loading import import_by_path
View
6 django/core/management/__init__.py
@@ -1,13 +1,13 @@
import collections
+import imp
+from importlib import import_module
+from optparse import OptionParser, NO_DEFAULT
import os
import sys
-from optparse import OptionParser, NO_DEFAULT
-import imp
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError, handle_default_options
from django.core.management.color import color_style
-from django.utils.importlib import import_module
from django.utils import six
# For backwards compatibility: get_version() used to be in this module.
View
2  django/core/management/commands/flush.py
@@ -1,4 +1,5 @@
import sys
+from importlib import import_module
from optparse import make_option
from django.conf import settings
@@ -7,7 +8,6 @@
from django.core.management.base import NoArgsCommand, CommandError
from django.core.management.color import no_style
from django.core.management.sql import sql_flush, emit_post_sync_signal
-from django.utils.importlib import import_module
from django.utils.six.moves import input
from django.utils import six
View
3  django/core/management/commands/startapp.py
@@ -1,6 +1,7 @@
+from importlib import import_module
+
from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand
-from django.utils.importlib import import_module
class Command(TemplateCommand):
View
3  django/core/management/commands/startproject.py
@@ -1,7 +1,8 @@
+from importlib import import_module
+
from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand
from django.utils.crypto import get_random_string
-from django.utils.importlib import import_module
class Command(TemplateCommand):
View
2  django/core/management/commands/syncdb.py
@@ -1,3 +1,4 @@
+from importlib import import_module
from optparse import make_option
import itertools
import traceback
@@ -9,7 +10,6 @@
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.utils.datastructures import SortedDict
-from django.utils.importlib import import_module
class Command(NoArgsCommand):
View
3  django/core/serializers/__init__.py
@@ -16,8 +16,9 @@
"""
+import importlib
+
from django.conf import settings
-from django.utils import importlib
from django.utils import six
from django.core.serializers.base import SerializerDoesNotExist
View
2  django/core/servers/fastcgi.py
@@ -12,9 +12,9 @@
pass to this server.
"""
+import importlib
import os
import sys
-from django.utils import importlib
__version__ = "0.1"
__all__ = ["runfastcgi"]
View
2  django/core/urlresolvers.py
@@ -8,6 +8,7 @@
"""
from __future__ import unicode_literals
+from importlib import import_module
import re
from threading import local
@@ -17,7 +18,6 @@
from django.utils.encoding import force_str, force_text, iri_to_uri
from django.utils.functional import memoize, lazy
from django.utils.http import urlquote
-from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.utils.regex_helper import normalize
from django.utils import six
View
2  django/db/backends/__init__.py
@@ -9,6 +9,7 @@
from django.utils.six.moves import _dummy_thread as thread
from collections import namedtuple
from contextlib import contextmanager
+from importlib import import_module
from django.conf import settings
from django.db import DEFAULT_DB_ALIAS
@@ -17,7 +18,6 @@
from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseErrorWrapper
from django.utils.functional import cached_property
-from django.utils.importlib import import_module
from django.utils import six
from django.utils import timezone
View
12 django/db/models/loading.py
@@ -1,17 +1,17 @@
"Utilities for loading models and the modules that contain them."
+import imp
+from importlib import import_module
+import os
+import sys
+
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict
-from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.utils._os import upath
from django.utils import six
-import imp
-import sys
-import os
-
__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
'load_app', 'app_cache_ready')
@@ -100,7 +100,7 @@ def load_app(self, app_name, can_postpone=False):
self.nesting_level += 1
app_module = import_module(app_name)
try:
- models = import_module('.' + MODELS_MODULE_NAME, app_name)
+ models = import_module('%s.%s' % (app_name, MODELS_MODULE_NAME))
except ImportError:
self.nesting_level -= 1
# If the app doesn't have a models module, we can just ignore the
View
4 django/db/utils.py
@@ -1,4 +1,5 @@
from functools import wraps
+from importlib import import_module
import os
import pkgutil
from threading import local
@@ -7,7 +8,6 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import cached_property
-from django.utils.importlib import import_module
from django.utils.module_loading import import_by_path
from django.utils._os import upath
from django.utils import six
@@ -104,7 +104,7 @@ def inner(*args, **kwargs):
def load_backend(backend_name):
# Look for a fully qualified database backend name
try:
- return import_module('.base', backend_name)
+ return import_module('%s.base' % backend_name)
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends.
View
2  django/template/base.py
@@ -2,12 +2,12 @@
import re
from functools import partial
+from importlib import import_module
from inspect import getargspec
from django.conf import settings
from django.template.context import (Context, RequestContext,
ContextPopException)
-from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable
from django.utils.text import (smart_split, unescape_string_literal,
get_text_list)
View
2  django/template/loaders/app_directories.py
@@ -3,6 +3,7 @@
packages.
"""
+from importlib import import_module
import os
import sys
@@ -11,7 +12,6 @@
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils._os import safe_join
-from django.utils.importlib import import_module
from django.utils import six
# At compile time, cache the directories to search.
View
2  django/test/client.py
@@ -5,6 +5,7 @@
import re
import mimetypes
from copy import copy
+from importlib import import_module
from io import BytesIO
try:
from urllib.parse import unquote, urlparse, urlsplit
@@ -25,7 +26,6 @@
from django.utils.functional import curry
from django.utils.encoding import force_bytes, force_str
from django.utils.http import urlencode
-from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable
from django.utils import six
from django.test.utils import ContextList
View
2  django/test/simple.py
@@ -3,6 +3,7 @@
version 1.8.
"""
+from importlib import import_module
import json
import re
import unittest as real_unittest
@@ -15,7 +16,6 @@
# django.utils.unittest is deprecated, but so is django.test.simple,
# and the latter will be removed before the former.
from django.utils import unittest
-from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
__all__ = ('DjangoTestSuiteRunner',)
View
4 django/utils/formats.py
@@ -1,10 +1,10 @@
import decimal
import datetime
+from importlib import import_module
@charettes Collaborator

This will load the deprecated module since it's in the same package (I'm getting the deprecation warning on Python 2.7 at least).

I know import_module = __import__('importlib').import_module would load the correct module but it's definitely not pretty.

@alex Collaborator
alex added a note

You can add from __future__ import absolute_import.

@charettes Collaborator

Ahhh I initialy tried that but I was fooled into thinking it wasn't working because of the double warning (see module_loading comment below).

I'll add those two __future__ imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
import unicodedata
from django.conf import settings
from django.utils import dateformat, numberformat, datetime_safe
-from django.utils.importlib import import_module
from django.utils.encoding import force_str
from django.utils.functional import lazy
from django.utils.safestring import mark_safe
@@ -54,7 +54,7 @@ def iter_format_modules(lang):
for location in format_locations:
for loc in locales:
try:
- yield import_module('.formats', location % loc)
+ yield import_module('%s.formats' % (location % loc))
except ImportError:
pass
View
5 django/utils/importlib.py
@@ -1,6 +1,11 @@
# Taken from Python 2.7 with permission from/by the original author.
+import warnings
import sys
+warnings.warn("django.utils.importlib will be removed in Django 1.9.",
+ PendingDeprecationWarning, stacklevel=2)
+
+
def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'):
View
2  django/utils/module_loading.py
@@ -1,10 +1,10 @@
import imp
+from importlib import import_module
@charettes Collaborator

Idem, this will load the deprecated module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
import os
import sys
from django.core.exceptions import ImproperlyConfigured
from django.utils import six
-from django.utils.importlib import import_module
def import_by_path(dotted_path, error_prefix=''):
View
2  django/utils/translation/trans_real.py
@@ -6,10 +6,10 @@
import re
import sys
import gettext as gettext_module
+from importlib import import_module
from threading import local
import warnings
-from django.utils.importlib import import_module
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_str, force_text
from django.utils.functional import memoize
View
2  django/views/i18n.py
@@ -1,3 +1,4 @@
+import importlib
import json
import os
import gettext as gettext_module
@@ -5,7 +6,6 @@
from django import http
from django.conf import settings
from django.template import Context, Template
-from django.utils import importlib
from django.utils.translation import check_for_language, to_locale, get_language
from django.utils.encoding import smart_text
from django.utils.formats import get_format_modules, get_format
View
2  docs/internals/deprecation.txt
@@ -412,6 +412,8 @@ these changes.
* ``django.utils.dictconfig`` will be removed.
+* ``django.utils.importlib`` will be removed.
+
* ``django.utils.unittest`` will be removed.
* If models are organized in a package, Django will no longer look for
View
9 docs/releases/1.7.txt
@@ -122,11 +122,12 @@ Miscellaneous
Features deprecated in 1.7
==========================
-``django.utils.dictconfig``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
+``django.utils.dictconfig``/``django.utils.importlib``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-``django.utils.dictconfig`` was a copy of :mod:`logging.config` provided for
-Python versions prior to 2.7. It has been deprecated.
+``django.utils.dictconfig`` and ``django.utils.importlib`` were copies of
+respectively :mod:`logging.config` and :mod:`importlib` provided for Python
+versions prior to 2.7. They have been deprecated.
``django.utils.unittest``
~~~~~~~~~~~~~~~~~~~~~~~~~
View
2  tests/i18n/tests.py
@@ -3,6 +3,7 @@
import datetime
import decimal
+from importlib import import_module
import os
import pickle
from threading import local
@@ -17,7 +18,6 @@
from django.utils.formats import (get_format, date_format, time_format,
localize, localize_input, iter_format_modules, get_format_modules,
number_format, reset_format_cache, sanitize_separators)
-from django.utils.importlib import import_module
from django.utils.numberformat import format as nformat
from django.utils._os import upath
from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText
View
2  tests/test_runner/tests.py
@@ -3,6 +3,7 @@
"""
from __future__ import absolute_import, unicode_literals
+from importlib import import_module
from optparse import make_option
import sys
import unittest
@@ -13,7 +14,6 @@
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.testcases import connections_support_transactions
from django.test.utils import IgnoreAllDeprecationWarningsMixin
-from django.utils.importlib import import_module
from admin_scripts.tests import AdminScriptTestCase
from .models import Person
View
2  tests/utils_tests/test_module_loading.py
@@ -1,11 +1,11 @@
import imp
+from importlib import import_module
import os
import sys
import unittest
from zipimport import zipimporter
from django.core.exceptions import ImproperlyConfigured
-from django.utils.importlib import import_module
from django.utils.module_loading import import_by_path, module_has_submodule
from django.utils._os import upath
Please sign in to comment.
Something went wrong with that request. Please try again.