Fixed #8703 -- Allow deeply nested import paths for DJANGO_SETTINGS_MODULE when

running django-admin.py. Also adds a parameter to setup_environ() for others to
use as well.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8768 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-08-31 18:21:06 +00:00
parent 8f56d6d017
commit 79968f9867
1 changed files with 22 additions and 16 deletions

View File

@ -108,7 +108,7 @@ def get_commands():
__import__(
settings.SETTINGS_MODULE, {}, {},
(settings.SETTINGS_MODULE.split(".")[-1],)
)
), settings.SETTINGS_MODULE
)
except (AttributeError, EnvironmentError, ImportError):
project_directory = None
@ -294,12 +294,15 @@ class ManagementUtility(object):
else:
self.fetch_command(subcommand).run_from_argv(self.argv)
def setup_environ(settings_mod):
def setup_environ(settings_mod, original_settings_path=None):
"""
Configures the runtime environment. This can also be used by external
scripts wanting to set up a similar environment to manage.py.
Returns the project directory (assuming the passed settings module is
directly in the project directory).
The "original_settings_path" parameter is optional, but recommended, since
trying to work out the original path from the module can be problematic.
"""
# Add this project to sys.path so that it's importable in the conventional
# way. For example, if this file (manage.py) lives in a directory
@ -314,7 +317,10 @@ def setup_environ(settings_mod):
sys.path.pop()
# Set DJANGO_SETTINGS_MODULE appropriately.
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
if original_settings_path:
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
else:
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
return project_directory
def execute_from_command_line(argv=None):