1
0
mirror of https://github.com/django/django.git synced 2025-06-07 04:29:12 +00:00

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

View File

@ -108,7 +108,7 @@ def get_commands():
__import__( __import__(
settings.SETTINGS_MODULE, {}, {}, settings.SETTINGS_MODULE, {}, {},
(settings.SETTINGS_MODULE.split(".")[-1],) (settings.SETTINGS_MODULE.split(".")[-1],)
) ), settings.SETTINGS_MODULE
) )
except (AttributeError, EnvironmentError, ImportError): except (AttributeError, EnvironmentError, ImportError):
project_directory = None project_directory = None
@ -294,12 +294,15 @@ class ManagementUtility(object):
else: else:
self.fetch_command(subcommand).run_from_argv(self.argv) 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 Configures the runtime environment. This can also be used by external
scripts wanting to set up a similar environment to manage.py. scripts wanting to set up a similar environment to manage.py.
Returns the project directory (assuming the passed settings module is Returns the project directory (assuming the passed settings module is
directly in the project directory). 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 # 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 # way. For example, if this file (manage.py) lives in a directory
@ -314,6 +317,9 @@ def setup_environ(settings_mod):
sys.path.pop() sys.path.pop()
# Set DJANGO_SETTINGS_MODULE appropriately. # Set DJANGO_SETTINGS_MODULE appropriately.
if original_settings_path:
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
else:
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
return project_directory return project_directory