diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-03-18 16:55:59 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-03-18 16:55:59 +0000 |
| commit | c485e236bd7e5ea40c64b2fe54d85dbb15b2fd39 (patch) | |
| tree | fc5e86abf39b69181b2084f5c39038f1811b6b44 /django/core/management/__init__.py | |
| parent | ee2f04d79e5bca55637b9bb3301618738a4e342a (diff) | |
Fixed #8193: all dynamic imports in Django are now done correctly. I know this because Brett Cannon borrowed the time machine and brought Python 2.7's '`importlib` back for inclusion in Django. Thanks for the patch-from-the-future, Brett!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/management/__init__.py')
| -rw-r--r-- | django/core/management/__init__.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index ec5ea19c98..4b40009e76 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -5,6 +5,7 @@ import imp import django from django.core.management.base import BaseCommand, CommandError, handle_default_options +from django.utils.importlib import import_module # For backwards compatibility: get_version() used to be in this module. get_version = django.get_version @@ -63,8 +64,8 @@ def load_command_class(app_name, name): class instance. All errors raised by the import process (ImportError, AttributeError) are allowed to propagate. """ - return getattr(__import__('%s.management.commands.%s' % (app_name, name), - {}, {}, ['Command']), 'Command')() + module = import_module('%s.management.commands.%s' % (app_name, name)) + return module.Command() def get_commands(): """ @@ -104,12 +105,9 @@ def get_commands(): # Find the project directory try: from django.conf import settings - project_directory = setup_environ( - __import__( - settings.SETTINGS_MODULE, {}, {}, - (settings.SETTINGS_MODULE.split(".")[-1],) - ), settings.SETTINGS_MODULE - ) + module = import_module(settings.SETTINGS_MODULE.split('.', 1)[0]) + project_directory = setup_environ(module, + settings.SETTINGS_MODULE) except (AttributeError, EnvironmentError, ImportError): project_directory = None @@ -328,7 +326,7 @@ def setup_environ(settings_mod, original_settings_path=None): # Import the project module. We add the parent directory to PYTHONPATH to # avoid some of the path errors new users can have. sys.path.append(os.path.join(project_directory, os.pardir)) - project_module = __import__(project_name, {}, {}, ['']) + project_module = import_module(project_name) sys.path.pop() return project_directory |
