Ticket #15372: t15372.diff

File t15372.diff, 55.8 KB (added by Carl Meyer, 13 years ago)

deprecate setup_environ and fix default project layout and manage.py

  • django/conf/project_template/manage.py

    diff --git a/django/conf/project_template/__init__.py b/django/conf/project_template/__init__.py
    deleted file mode 100644
    index e69de29..0000000
    diff --git a/django/conf/project_template/manage.py b/django/conf/project_template/manage.py
    index 3e4eedc..2568a32 100755
    a b  
    11#!/usr/bin/env python
    2 from django.core.management import execute_manager
    3 import imp
    4 try:
    5     imp.find_module('settings') # Assumed to be in the same directory.
    6 except ImportError:
    7     import sys
    8     sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
    9     sys.exit(1)
    10 
    11 import settings
     2import os, sys
    123
    134if __name__ == "__main__":
    14     execute_manager(settings)
     5    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
     6
     7    from django.core.management import execute_from_command_line
     8
     9    execute_from_command_line(sys.argv)
  • new file django/conf/project_template/project_name/settings.py

    diff --git a/django/conf/project_template/project_name/__init__.py b/django/conf/project_template/project_name/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/conf/project_template/project_name/settings.py b/django/conf/project_template/project_name/settings.py
    new file mode 100644
    index 0000000..b92c116
    - +  
     1# Django settings for {{ project_name }} project.
     2
     3DEBUG = True
     4TEMPLATE_DEBUG = DEBUG
     5
     6ADMINS = (
     7    # ('Your Name', 'your_email@example.com'),
     8)
     9
     10MANAGERS = ADMINS
     11
     12DATABASES = {
     13    'default': {
     14        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
     15        'NAME': '',                      # Or path to database file if using sqlite3.
     16        'USER': '',                      # Not used with sqlite3.
     17        'PASSWORD': '',                  # Not used with sqlite3.
     18        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
     19        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
     20    }
     21}
     22
     23# Local time zone for this installation. Choices can be found here:
     24# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
     25# although not all choices may be available on all operating systems.
     26# On Unix systems, a value of None will cause Django to use the same
     27# timezone as the operating system.
     28# If running in a Windows environment this must be set to the same as your
     29# system time zone.
     30TIME_ZONE = 'America/Chicago'
     31
     32# Language code for this installation. All choices can be found here:
     33# http://www.i18nguy.com/unicode/language-identifiers.html
     34LANGUAGE_CODE = 'en-us'
     35
     36SITE_ID = 1
     37
     38# If you set this to False, Django will make some optimizations so as not
     39# to load the internationalization machinery.
     40USE_I18N = True
     41
     42# If you set this to False, Django will not format dates, numbers and
     43# calendars according to the current locale
     44USE_L10N = True
     45
     46# Absolute filesystem path to the directory that will hold user-uploaded files.
     47# Example: "/home/media/media.lawrence.com/media/"
     48MEDIA_ROOT = ''
     49
     50# URL that handles the media served from MEDIA_ROOT. Make sure to use a
     51# trailing slash.
     52# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
     53MEDIA_URL = ''
     54
     55# Absolute path to the directory static files should be collected to.
     56# Don't put anything in this directory yourself; store your static files
     57# in apps' "static/" subdirectories and in STATICFILES_DIRS.
     58# Example: "/home/media/media.lawrence.com/static/"
     59STATIC_ROOT = ''
     60
     61# URL prefix for static files.
     62# Example: "http://media.lawrence.com/static/"
     63STATIC_URL = '/static/'
     64
     65# Additional locations of static files
     66STATICFILES_DIRS = (
     67    # Put strings here, like "/home/html/static" or "C:/www/django/static".
     68    # Always use forward slashes, even on Windows.
     69    # Don't forget to use absolute paths, not relative paths.
     70)
     71
     72# List of finder classes that know how to find static files in
     73# various locations.
     74STATICFILES_FINDERS = (
     75    'django.contrib.staticfiles.finders.FileSystemFinder',
     76    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
     77#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
     78)
     79
     80# Make this unique, and don't share it with anybody.
     81SECRET_KEY = ''
     82
     83# List of callables that know how to import templates from various sources.
     84TEMPLATE_LOADERS = (
     85    'django.template.loaders.filesystem.Loader',
     86    'django.template.loaders.app_directories.Loader',
     87#     'django.template.loaders.eggs.Loader',
     88)
     89
     90MIDDLEWARE_CLASSES = (
     91    'django.middleware.common.CommonMiddleware',
     92    'django.contrib.sessions.middleware.SessionMiddleware',
     93    'django.middleware.csrf.CsrfViewMiddleware',
     94    'django.contrib.auth.middleware.AuthenticationMiddleware',
     95    'django.contrib.messages.middleware.MessageMiddleware',
     96    # Uncomment the next line for simple clickjacking protection:
     97    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
     98)
     99
     100ROOT_URLCONF = '{{ project_name }}.urls'
     101
     102TEMPLATE_DIRS = (
     103    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     104    # Always use forward slashes, even on Windows.
     105    # Don't forget to use absolute paths, not relative paths.
     106)
     107
     108INSTALLED_APPS = (
     109    'django.contrib.auth',
     110    'django.contrib.contenttypes',
     111    'django.contrib.sessions',
     112    'django.contrib.sites',
     113    'django.contrib.messages',
     114    'django.contrib.staticfiles',
     115    # Uncomment the next line to enable the admin:
     116    # 'django.contrib.admin',
     117    # Uncomment the next line to enable admin documentation:
     118    # 'django.contrib.admindocs',
     119)
     120
     121# A sample logging configuration. The only tangible logging
     122# performed by this configuration is to send an email to
     123# the site admins on every HTTP 500 error when DEBUG=False.
     124# See http://docs.djangoproject.com/en/dev/topics/logging for
     125# more details on how to customize your logging configuration.
     126LOGGING = {
     127    'version': 1,
     128    'disable_existing_loggers': False,
     129    'filters': {
     130        'require_debug_false': {
     131            '()': 'django.utils.log.RequireDebugFalse'
     132        }
     133    },
     134    'handlers': {
     135        'mail_admins': {
     136            'level': 'ERROR',
     137            'filters': ['require_debug_false'],
     138            'class': 'django.utils.log.AdminEmailHandler'
     139        }
     140    },
     141    'loggers': {
     142        'django.request': {
     143            'handlers': ['mail_admins'],
     144            'level': 'ERROR',
     145            'propagate': True,
     146        },
     147    }
     148}
  • new file django/conf/project_template/project_name/urls.py

    diff --git a/django/conf/project_template/project_name/urls.py b/django/conf/project_template/project_name/urls.py
    new file mode 100644
    index 0000000..eb471d5
    - +  
     1from django.conf.urls import patterns, include, url
     2
     3# Uncomment the next two lines to enable the admin:
     4# from django.contrib import admin
     5# admin.autodiscover()
     6
     7urlpatterns = patterns('',
     8    # Examples:
     9    # url(r'^$', '{{ project_name }}.views.home', name='home'),
     10    # url(r'^{{ project_name }}/', include('{{ project_name }}.foo.urls')),
     11
     12    # Uncomment the admin/doc line below to enable admin documentation:
     13    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
     14
     15    # Uncomment the next line to enable the admin:
     16    # url(r'^admin/', include(admin.site.urls)),
     17)
  • deleted file django/conf/project_template/settings.py

    diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py
    deleted file mode 100644
    index b92c116..0000000
    + -  
    1 # Django settings for {{ project_name }} project.
    2 
    3 DEBUG = True
    4 TEMPLATE_DEBUG = DEBUG
    5 
    6 ADMINS = (
    7     # ('Your Name', 'your_email@example.com'),
    8 )
    9 
    10 MANAGERS = ADMINS
    11 
    12 DATABASES = {
    13     'default': {
    14         'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    15         'NAME': '',                      # Or path to database file if using sqlite3.
    16         'USER': '',                      # Not used with sqlite3.
    17         'PASSWORD': '',                  # Not used with sqlite3.
    18         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    19         'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    20     }
    21 }
    22 
    23 # Local time zone for this installation. Choices can be found here:
    24 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
    25 # although not all choices may be available on all operating systems.
    26 # On Unix systems, a value of None will cause Django to use the same
    27 # timezone as the operating system.
    28 # If running in a Windows environment this must be set to the same as your
    29 # system time zone.
    30 TIME_ZONE = 'America/Chicago'
    31 
    32 # Language code for this installation. All choices can be found here:
    33 # http://www.i18nguy.com/unicode/language-identifiers.html
    34 LANGUAGE_CODE = 'en-us'
    35 
    36 SITE_ID = 1
    37 
    38 # If you set this to False, Django will make some optimizations so as not
    39 # to load the internationalization machinery.
    40 USE_I18N = True
    41 
    42 # If you set this to False, Django will not format dates, numbers and
    43 # calendars according to the current locale
    44 USE_L10N = True
    45 
    46 # Absolute filesystem path to the directory that will hold user-uploaded files.
    47 # Example: "/home/media/media.lawrence.com/media/"
    48 MEDIA_ROOT = ''
    49 
    50 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    51 # trailing slash.
    52 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
    53 MEDIA_URL = ''
    54 
    55 # Absolute path to the directory static files should be collected to.
    56 # Don't put anything in this directory yourself; store your static files
    57 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
    58 # Example: "/home/media/media.lawrence.com/static/"
    59 STATIC_ROOT = ''
    60 
    61 # URL prefix for static files.
    62 # Example: "http://media.lawrence.com/static/"
    63 STATIC_URL = '/static/'
    64 
    65 # Additional locations of static files
    66 STATICFILES_DIRS = (
    67     # Put strings here, like "/home/html/static" or "C:/www/django/static".
    68     # Always use forward slashes, even on Windows.
    69     # Don't forget to use absolute paths, not relative paths.
    70 )
    71 
    72 # List of finder classes that know how to find static files in
    73 # various locations.
    74 STATICFILES_FINDERS = (
    75     'django.contrib.staticfiles.finders.FileSystemFinder',
    76     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    77 #    'django.contrib.staticfiles.finders.DefaultStorageFinder',
    78 )
    79 
    80 # Make this unique, and don't share it with anybody.
    81 SECRET_KEY = ''
    82 
    83 # List of callables that know how to import templates from various sources.
    84 TEMPLATE_LOADERS = (
    85     'django.template.loaders.filesystem.Loader',
    86     'django.template.loaders.app_directories.Loader',
    87 #     'django.template.loaders.eggs.Loader',
    88 )
    89 
    90 MIDDLEWARE_CLASSES = (
    91     'django.middleware.common.CommonMiddleware',
    92     'django.contrib.sessions.middleware.SessionMiddleware',
    93     'django.middleware.csrf.CsrfViewMiddleware',
    94     'django.contrib.auth.middleware.AuthenticationMiddleware',
    95     'django.contrib.messages.middleware.MessageMiddleware',
    96     # Uncomment the next line for simple clickjacking protection:
    97     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    98 )
    99 
    100 ROOT_URLCONF = '{{ project_name }}.urls'
    101 
    102 TEMPLATE_DIRS = (
    103     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    104     # Always use forward slashes, even on Windows.
    105     # Don't forget to use absolute paths, not relative paths.
    106 )
    107 
    108 INSTALLED_APPS = (
    109     'django.contrib.auth',
    110     'django.contrib.contenttypes',
    111     'django.contrib.sessions',
    112     'django.contrib.sites',
    113     'django.contrib.messages',
    114     'django.contrib.staticfiles',
    115     # Uncomment the next line to enable the admin:
    116     # 'django.contrib.admin',
    117     # Uncomment the next line to enable admin documentation:
    118     # 'django.contrib.admindocs',
    119 )
    120 
    121 # A sample logging configuration. The only tangible logging
    122 # performed by this configuration is to send an email to
    123 # the site admins on every HTTP 500 error when DEBUG=False.
    124 # See http://docs.djangoproject.com/en/dev/topics/logging for
    125 # more details on how to customize your logging configuration.
    126 LOGGING = {
    127     'version': 1,
    128     'disable_existing_loggers': False,
    129     'filters': {
    130         'require_debug_false': {
    131             '()': 'django.utils.log.RequireDebugFalse'
    132         }
    133     },
    134     'handlers': {
    135         'mail_admins': {
    136             'level': 'ERROR',
    137             'filters': ['require_debug_false'],
    138             'class': 'django.utils.log.AdminEmailHandler'
    139         }
    140     },
    141     'loggers': {
    142         'django.request': {
    143             'handlers': ['mail_admins'],
    144             'level': 'ERROR',
    145             'propagate': True,
    146         },
    147     }
    148 }
  • deleted file django/conf/project_template/urls.py

    diff --git a/django/conf/project_template/urls.py b/django/conf/project_template/urls.py
    deleted file mode 100644
    index eb471d5..0000000
    + -  
    1 from django.conf.urls import patterns, include, url
    2 
    3 # Uncomment the next two lines to enable the admin:
    4 # from django.contrib import admin
    5 # admin.autodiscover()
    6 
    7 urlpatterns = patterns('',
    8     # Examples:
    9     # url(r'^$', '{{ project_name }}.views.home', name='home'),
    10     # url(r'^{{ project_name }}/', include('{{ project_name }}.foo.urls')),
    11 
    12     # Uncomment the admin/doc line below to enable admin documentation:
    13     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    14 
    15     # Uncomment the next line to enable the admin:
    16     # url(r'^admin/', include(admin.site.urls)),
    17 )
  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index ea494c7..6edb0ba 100644
    a b import os  
    22import sys
    33from optparse import OptionParser, NO_DEFAULT
    44import imp
     5import warnings
    56
    67import django
    78from django.core.management.base import BaseCommand, CommandError, handle_default_options
    def get_commands():  
    102103        except (AttributeError, EnvironmentError, ImportError):
    103104            apps = []
    104105
    105         # Find the project directory
    106         try:
    107             from django.conf import settings
    108             module = import_module(settings.SETTINGS_MODULE)
    109             project_directory = setup_environ(module, settings.SETTINGS_MODULE)
    110         except (AttributeError, EnvironmentError, ImportError, KeyError):
    111             project_directory = None
    112 
    113106        # Find and load the management module for each installed app.
    114107        for app_name in apps:
    115108            try:
    def get_commands():  
    119112            except ImportError:
    120113                pass # No management module - ignore this app
    121114
    122         if project_directory:
    123             # Remove the "startproject" command from self.commands, because
    124             # that's a django-admin.py command, not a manage.py command.
    125             del _commands['startproject']
    126 
    127             # Override the startapp command so that it always uses the
    128             # project_directory, not the current working directory
    129             # (which is default).
    130             from django.core.management.commands.startapp import ProjectCommand
    131             _commands['startapp'] = ProjectCommand(project_directory)
    132 
    133115    return _commands
    134116
    135117def call_command(name, *args, **options):
    def setup_environ(settings_mod, original_settings_path=None):  
    388370    The "original_settings_path" parameter is optional, but recommended, since
    389371    trying to work out the original path from the module can be problematic.
    390372    """
     373    warnings.warn(
     374        "The 'setup_environ' function is deprecated, "
     375        "you likely need to update your 'manage.py'; "
     376        "please see the Django 1.4 release notes "
     377        "(https://docs.djangoproject.com/en/dev/releases/1.4/).",
     378        PendingDeprecationWarning)
     379
    391380    # Add this project to sys.path so that it's importable in the conventional
    392381    # way. For example, if this file (manage.py) lives in a directory
    393382    # "myproject", this code would add "/path/to/myproject" to sys.path.
    def execute_manager(settings_mod, argv=None):  
    437426    Like execute_from_command_line(), but for use by manage.py, a
    438427    project-specific django-admin.py utility.
    439428    """
     429    warnings.warn(
     430        "The 'execute_manager' function is deprecated, "
     431        "you likely need to update your 'manage.py'; "
     432        "please see the Django 1.4 release notes "
     433        "(https://docs.djangoproject.com/en/dev/releases/1.4/).",
     434        PendingDeprecationWarning)
     435
    440436    setup_environ(settings_mod)
    441437    utility = ManagementUtility(argv)
    442438    utility.execute()
  • django/core/management/commands/startproject.py

    diff --git a/django/core/management/commands/startproject.py b/django/core/management/commands/startproject.py
    index 712e43d..ce4d32b 100644
    a b class Command(LabelCommand):  
    1515    can_import_settings = False
    1616
    1717    def handle_label(self, project_name, **options):
    18         # Determine the project_name a bit naively -- by looking at the name of
    19         # the parent directory.
    2018        directory = os.getcwd()
    2119
    2220        # Check that the project_name cannot be imported.
    class Command(LabelCommand):  
    3028        copy_helper(self.style, 'project', project_name, directory)
    3129
    3230        # Create a random SECRET_KEY hash, and put it in the main settings.
    33         main_settings_file = os.path.join(directory, project_name, 'settings.py')
     31        main_settings_file = os.path.join(directory, project_name, project_name, 'settings.py')
    3432        settings_contents = open(main_settings_file, 'r').read()
    3533        fp = open(main_settings_file, 'w')
    3634        secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
  • docs/internals/deprecation.txt

    diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
    index 9e88ec4..b438fd6 100644
    a b these changes.  
    246246
    247247    * The Databrowse contrib module will be removed.
    248248
     249    * The functions :func:`~django.core.management.setup_environ` and
     250      :func:`~django.core.management.execute_manager` will be removed from
     251      :mod:`django.core.management`. This also means that the old (pre-1.4)
     252      style of :file:`manage.py` file will no longer work.
     253
    2492542.0
    250255---
    251256
  • docs/intro/tutorial01.txt

    diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt
    index 2f2e049..97743dc 100644
    a b within your Python installation. Consider symlinking to :doc:`django-admin.py  
    9090Let's look at what :djadmin:`startproject` created::
    9191
    9292    mysite/
    93         __init__.py
    9493        manage.py
    95         settings.py
    96         urls.py
     94        mysite/
     95            __init__.py
     96            settings.py
     97            urls.py
     98
     99.. admonition:: Doesn't match what you see?
     100
     101    The default project layout recently changed. If you're seeing a "flat"
     102    layout (with no inner :file:`mysite/` directory), you're probably using
     103    a version of Django that doesn't match this tutorial version.  You'll
     104    want to either switch to the older tutorial or the newer Django version.
    97105
    98106These files are:
    99107
    100     * :file:`__init__.py`: An empty file that tells Python that this directory
    101       should be considered a Python package. (Read `more about packages`_ in the
    102       official Python docs if you're a Python beginner.)
     108* The outer :file:`mysite/` directory is just a container for your
     109  project. Its name doesn't matter to Django; you can rename it to anything
     110  you like.
     111
     112* :file:`manage.py`: A command-line utility that lets you interact with this
     113  Django project in various ways. You can read all the details about
     114  :file:`manage.py` in :doc:`/ref/django-admin`.
    103115
    104     * :file:`manage.py`: A command-line utility that lets you interact with this
    105       Django project in various ways. You can read all the details about
    106       :file:`manage.py` in :doc:`/ref/django-admin`.
     116* The inner :file:`mysite/` directory is the actual Python package for your
     117  project. Its name is the Python package name you'll need to use to import
     118  anything inside it (e.g. ``import mysite.settings``).
    107119
    108     * :file:`settings.py`: Settings/configuration for this Django project.
    109       :doc:`/topics/settings` will tell you all about how settings work.
     120* :file:`mysite/__init__.py`: An empty file that tells Python that this
     121  directory should be considered a Python package. (Read `more about
     122  packages`_ in the official Python docs if you're a Python beginner.)
    110123
    111     * :file:`urls.py`: The URL declarations for this Django project; a "table of
    112       contents" of your Django-powered site. You can read more about URLs in
    113       :doc:`/topics/http/urls`.
     124* :file:`mysite/settings.py`: Settings/configuration for this Django
     125  project.  :doc:`/topics/settings` will tell you all about how settings
     126  work.
     127
     128* :file:`mysite/urls.py`: The URL declarations for this Django project; a
     129  "table of contents" of your Django-powered site. You can read more about
     130  URLs in :doc:`/topics/http/urls`.
    114131
    115132.. _more about packages: http://docs.python.org/tutorial/modules.html#packages
    116133
    117134The development server
    118135----------------------
    119136
    120 Let's verify this worked. Change into the :file:`mysite` directory, if you
    121 haven't already, and run the command ``python manage.py runserver``. You'll see
    122 the following output on the command line::
     137Let's verify this worked. Change into the outer :file:`mysite` directory, if
     138you haven't already, and run the command ``python manage.py runserver``. You'll
     139see the following output on the command line::
    123140
    124141    Validating models...
    125142    0 errors found.
    126143
    127     Django version 1.0, using settings 'mysite.settings'
     144    Django version 1.4, using settings 'mysite.settings'
    128145    Development server is running at http://127.0.0.1:8000/
    129146    Quit the server with CONTROL-C.
    130147
    It worked!  
    168185Database setup
    169186--------------
    170187
    171 Now, edit :file:`settings.py`. It's a normal Python module with
     188Now, edit :file:`mysite/settings.py`. It's a normal Python module with
    172189module-level variables representing Django settings. Change the
    173190following keys in the :setting:`DATABASES` ``'default'`` item to match
    174191your databases connection settings.
    so you can focus on writing code rather than creating directories.  
    286303    multiple apps. An app can be in multiple projects.
    287304
    288305Your apps can live anywhere on your `Python path`_. In this tutorial, we'll
    289 create our poll app in the :file:`mysite` directory for simplicity.
     306create our poll app right next to your :file:`manage.py` file so that it can be
     307imported as its own top-level module, rather than a submodule of ``mysite``.
    290308
    291 To create your app, make sure you're in the :file:`mysite` directory and type
    292 this command:
     309To create your app, make sure you're in the same directory as :file:`manage.py`
     310and type this command:
    293311
    294312.. code-block:: bash
    295313
    API Django gives you. To invoke the Python shell, use this command:  
    499517
    500518    python manage.py shell
    501519
    502 We're using this instead of simply typing "python", because ``manage.py`` sets
    503 up the project's environment for you. "Setting up the environment" involves two
    504 things:
    505 
    506     * Putting ``polls`` on ``sys.path``. For flexibility, several pieces of
    507       Django refer to projects in Python dotted-path notation (e.g.
    508       ``'polls.models'``). In order for this to work, the ``polls``
    509       package has to be on ``sys.path``.
    510 
    511       We've already seen one example of this: the :setting:`INSTALLED_APPS`
    512       setting is a list of packages in dotted-path notation.
    513 
    514     * Setting the ``DJANGO_SETTINGS_MODULE`` environment variable, which gives
    515       Django the path to your ``settings.py`` file.
     520We're using this instead of simply typing "python", because :file:`manage.py`
     521sets the ``DJANGO_SETTINGS_MODULE`` environment variable, which gives Django
     522the Python import path to your :file:`settings.py` file.
    516523
    517524.. admonition:: Bypassing manage.py
    518525
    519     If you'd rather not use ``manage.py``, no problem. Just make sure ``mysite``
    520     and ``polls`` are at the root level on the Python path (i.e., ``import mysite``
    521     and ``import polls`` work) and set the ``DJANGO_SETTINGS_MODULE`` environment
    522     variable to ``mysite.settings``.
     526    If you'd rather not use :file:`manage.py`, no problem. Just set the
     527    ``DJANGO_SETTINGS_MODULE`` environment variable to ``mysite.settings`` and
     528    run ``python`` from the same directory :file:`manage.py` is in (or ensure
     529    that directory is on the Python path, so that ``import mysite`` works).
    523530
    524531    For more information on all of this, see the :doc:`django-admin.py
    525532    documentation </ref/django-admin>`.
  • docs/releases/1.4.txt

    diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt
    index b71fd21..7ad403c 100644
    a b a :class:`~django.forms.fields.GenericIPAddressField` form field and  
    328328the validators :data:`~django.core.validators.validate_ipv46_address` and
    329329:data:`~django.core.validators.validate_ipv6_address`
    330330
     331Updated default project layout and ``manage.py``
     332~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     333
     334Django 1.4 ships with an updated default project layout and ``manage.py`` file
     335for the :djadmin:`startproject` management command. These fix some issues with
     336the previous ``manage.py`` handling of Python import paths that caused double
     337imports, trouble moving from development to deployment, and other
     338difficult-to-debug path issues.
     339
     340The previous ``manage.py`` calls functions that are now deprecated, and thus
     341projects upgrading to Django 1.4 should update their ``manage.py``. (The
     342old-style ``manage.py`` will continue to work as before until Django 1.6; in
     3431.5 it will raise ``DeprecationWarning``).
     344
     345The new recommended ``manage.py`` file should look like this::
     346
     347    #!/usr/bin/env python
     348    import os, sys
     349
     350    if __name__ == "__main__":
     351        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
     352
     353        from django.core.management import execute_from_command_line
     354
     355        execute_from_command_line(sys.argv)
     356
     357``{{ project_name }}`` should be replaced with the Python package name of the
     358actual project.
     359
     360If settings, URLconf, and apps within the project are imported or referenced
     361using the project-name prefix (e.g. ``myproject.settings``, ``ROOT_URLCONF =
     362``myproject.urls``, etc), the new ``manage.py`` will need to be moved one
     363directory up, so it is outside the project package rather than adjacent to
     364``settings.py`` and ``urls.py``.
     365
     366For instance, with the following layout::
     367
     368    manage.py
     369    mysite/
     370        __init__.py
     371        settings.py
     372        urls.py
     373        myapp/
     374            __init__.py
     375            models.py
     376
     377You could import ``mysite.settings``, ``mysite.urls``, and ``mysite.myapp``,
     378but not ``settings``, ``urls``, or ``myapp`` as top-level modules.
     379
     380Anything imported as a top-level module can be placed adjacent to the new
     381``manage.py``. For instance, to decouple "myapp" from the project module and
     382import it as just ``myapp``, place it outside the ``mysite/`` directory::
     383
     384    manage.py
     385    myapp/
     386        __init__.py
     387        models.py
     388    mysite/
     389        __init__.py
     390        settings.py
     391        urls.py
     392
     393If the same code is imported inconsistently (some places with the project
     394prefix, some places without it), the imports will need to be cleaned up when
     395switching to the new ``manage.py``.
     396
     397
    331398Minor features
    332399~~~~~~~~~~~~~~
    333400
    The code that powers Databrowse is licensed under the same terms as Django  
    729796itself, and so is available to be adopted by an individual or group as
    730797a third-party project.
    731798
     799``django.core.management.setup_environ``
     800~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     801
     802This function temporarily modified ``sys.path`` in order to make the parent
     803"project" directory importable under the old flat :djadmin:`startproject`
     804layout. This function is now deprecated, as its path workarounds are no longer
     805needed with the new ``manage.py`` and default project layout.
     806
     807This function was never documented or public API, but was widely recommended
     808for use in setting up a "Django environment" for a user script. These uses
     809should be replaced by setting the ``DJANGO_SETTINGS_MODULE`` environment
     810variable or using :func:`django.conf.settings.configure`.
     811
     812``django.core.management.execute_manager``
     813~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     814
     815This function was previously used by ``manage.py`` to execute a management
     816command. It is identical to
     817``django.core.management.execute_from_command_line``, except that it first
     818calls ``setup_environ``, which is now deprecated. ``execute_manager`` is also
     819deprecated; ``execute_from_command_line`` can be used instead. (Neither of
     820these functions is documented public API, but a deprecation path is needed due
     821to use in existing ``manage.py`` files.)
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index cf0dfc6..8580e36 100644
    a b A series of tests to establish that the command-line managment tools work as  
    33advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
    44and default settings.py files.
    55"""
     6from __future__ import with_statement
     7
    68import os
    79import shutil
    810import sys
    class AdminScriptTestCase(unittest.TestCase):  
    3537                settings_file.write("%s = %s\n" % (s, o))
    3638
    3739        if apps is None:
    38             apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']
     40            apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts']
    3941
    4042        settings_file.write("INSTALLED_APPS = %s\n" % apps)
    4143
    class AdminScriptTestCase(unittest.TestCase):  
    100102            os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
    101103        elif 'DJANGO_SETTINGS_MODULE' in os.environ:
    102104            del os.environ['DJANGO_SETTINGS_MODULE']
    103         python_path = [test_dir, base_dir]
     105        python_path = [project_dir, base_dir]
    104106        python_path.extend(ext_backend_base_dirs)
    105107        os.environ[python_path_var_name] = os.pathsep.join(python_path)
    106108
    class AdminScriptTestCase(unittest.TestCase):  
    148150        test_manage_py = os.path.join(test_dir, 'manage.py')
    149151        shutil.copyfile(template_manage_py, test_manage_py)
    150152
     153        with open(test_manage_py, 'r') as fp:
     154            manage_py_contents = fp.read()
     155        manage_py_contents = manage_py_contents.replace(
     156            "{{ project_name }}", "regressiontests")
     157        with open(test_manage_py, 'w') as fp:
     158            fp.write(manage_py_contents)
     159
    151160        stdout, stderr = self.run_test('./manage.py', args, settings_file)
    152161
    153162        # Cleanup - remove the generated manage.py script
    class DjangoAdminDefaultSettings(AdminScriptTestCase):  
    224233
    225234    def test_builtin_with_settings(self):
    226235        "default: django-admin builtin commands succeed if settings are provided as argument"
    227         args = ['sqlall','--settings=settings', 'admin_scripts']
     236        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    228237        out, err = self.run_django_admin(args)
    229238        self.assertNoOutput(err)
    230239        self.assertOutput(out, 'CREATE TABLE')
    class DjangoAdminDefaultSettings(AdminScriptTestCase):  
    232241    def test_builtin_with_environment(self):
    233242        "default: django-admin builtin commands succeed if settings are provided in the environment"
    234243        args = ['sqlall','admin_scripts']
    235         out, err = self.run_django_admin(args,'settings')
     244        out, err = self.run_django_admin(args,'regressiontests.settings')
    236245        self.assertNoOutput(err)
    237246        self.assertOutput(out, 'CREATE TABLE')
    238247
    class DjangoAdminDefaultSettings(AdminScriptTestCase):  
    259268
    260269    def test_custom_command_with_settings(self):
    261270        "default: django-admin can execute user commands if settings are provided as argument"
    262         args = ['noargs_command', '--settings=settings']
     271        args = ['noargs_command', '--settings=regressiontests.settings']
    263272        out, err = self.run_django_admin(args)
    264273        self.assertNoOutput(err)
    265274        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    class DjangoAdminDefaultSettings(AdminScriptTestCase):  
    267276    def test_custom_command_with_environment(self):
    268277        "default: django-admin can execute user commands if settings are provided in environment"
    269278        args = ['noargs_command']
    270         out, err = self.run_django_admin(args,'settings')
     279        out, err = self.run_django_admin(args,'regressiontests.settings')
    271280        self.assertNoOutput(err)
    272281        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    273282
    class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):  
    290299
    291300    def test_builtin_with_settings(self):
    292301        "fulldefault: django-admin builtin commands succeed if a settings file is provided"
    293         args = ['sqlall','--settings=settings', 'admin_scripts']
     302        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    294303        out, err = self.run_django_admin(args)
    295304        self.assertNoOutput(err)
    296305        self.assertOutput(out, 'CREATE TABLE')
    class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):  
    298307    def test_builtin_with_environment(self):
    299308        "fulldefault: django-admin builtin commands succeed if the environment contains settings"
    300309        args = ['sqlall','admin_scripts']
    301         out, err = self.run_django_admin(args,'settings')
     310        out, err = self.run_django_admin(args,'regressiontests.settings')
    302311        self.assertNoOutput(err)
    303312        self.assertOutput(out, 'CREATE TABLE')
    304313
    class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):  
    325334
    326335    def test_custom_command_with_settings(self):
    327336        "fulldefault: django-admin can execute user commands if settings are provided as argument"
    328         args = ['noargs_command', '--settings=settings']
     337        args = ['noargs_command', '--settings=regressiontests.settings']
    329338        out, err = self.run_django_admin(args)
    330339        self.assertNoOutput(err)
    331340        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):  
    333342    def test_custom_command_with_environment(self):
    334343        "fulldefault: django-admin can execute user commands if settings are provided in environment"
    335344        args = ['noargs_command']
    336         out, err = self.run_django_admin(args,'settings')
     345        out, err = self.run_django_admin(args,'regressiontests.settings')
    337346        self.assertNoOutput(err)
    338347        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    339348
    class DjangoAdminMinimalSettings(AdminScriptTestCase):  
    356365
    357366    def test_builtin_with_settings(self):
    358367        "minimal: django-admin builtin commands fail if settings are provided as argument"
    359         args = ['sqlall','--settings=settings', 'admin_scripts']
     368        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    360369        out, err = self.run_django_admin(args)
    361370        self.assertNoOutput(out)
    362371        self.assertOutput(err, 'App with label admin_scripts could not be found')
    class DjangoAdminMinimalSettings(AdminScriptTestCase):  
    364373    def test_builtin_with_environment(self):
    365374        "minimal: django-admin builtin commands fail if settings are provided in the environment"
    366375        args = ['sqlall','admin_scripts']
    367         out, err = self.run_django_admin(args,'settings')
     376        out, err = self.run_django_admin(args,'regressiontests.settings')
    368377        self.assertNoOutput(out)
    369378        self.assertOutput(err, 'App with label admin_scripts could not be found')
    370379
    class DjangoAdminMinimalSettings(AdminScriptTestCase):  
    391400
    392401    def test_custom_command_with_settings(self):
    393402        "minimal: django-admin can't execute user commands, even if settings are provided as argument"
    394         args = ['noargs_command', '--settings=settings']
     403        args = ['noargs_command', '--settings=regressiontests.settings']
    395404        out, err = self.run_django_admin(args)
    396405        self.assertNoOutput(out)
    397406        self.assertOutput(err, "Unknown command: 'noargs_command'")
    class DjangoAdminMinimalSettings(AdminScriptTestCase):  
    399408    def test_custom_command_with_environment(self):
    400409        "minimal: django-admin can't execute user commands, even if settings are provided in environment"
    401410        args = ['noargs_command']
    402         out, err = self.run_django_admin(args,'settings')
     411        out, err = self.run_django_admin(args,'regressiontests.settings')
    403412        self.assertNoOutput(out)
    404413        self.assertOutput(err, "Unknown command: 'noargs_command'")
    405414
    class DjangoAdminAlternateSettings(AdminScriptTestCase):  
    422431
    423432    def test_builtin_with_settings(self):
    424433        "alternate: django-admin builtin commands succeed if settings are provided as argument"
    425         args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
     434        args = ['sqlall','--settings=regressiontests.alternate_settings', 'admin_scripts']
    426435        out, err = self.run_django_admin(args)
    427436        self.assertNoOutput(err)
    428437        self.assertOutput(out, 'CREATE TABLE')
    class DjangoAdminAlternateSettings(AdminScriptTestCase):  
    430439    def test_builtin_with_environment(self):
    431440        "alternate: django-admin builtin commands succeed if settings are provided in the environment"
    432441        args = ['sqlall','admin_scripts']
    433         out, err = self.run_django_admin(args,'alternate_settings')
     442        out, err = self.run_django_admin(args,'regressiontests.alternate_settings')
    434443        self.assertNoOutput(err)
    435444        self.assertOutput(out, 'CREATE TABLE')
    436445
    class DjangoAdminAlternateSettings(AdminScriptTestCase):  
    457466
    458467    def test_custom_command_with_settings(self):
    459468        "alternate: django-admin can execute user commands if settings are provided as argument"
    460         args = ['noargs_command', '--settings=alternate_settings']
     469        args = ['noargs_command', '--settings=regressiontests.alternate_settings']
    461470        out, err = self.run_django_admin(args)
    462471        self.assertNoOutput(err)
    463472        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    class DjangoAdminAlternateSettings(AdminScriptTestCase):  
    465474    def test_custom_command_with_environment(self):
    466475        "alternate: django-admin can execute user commands if settings are provided in environment"
    467476        args = ['noargs_command']
    468         out, err = self.run_django_admin(args,'alternate_settings')
     477        out, err = self.run_django_admin(args,'regressiontests.alternate_settings')
    469478        self.assertNoOutput(err)
    470479        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    471480
    class DjangoAdminMultipleSettings(AdminScriptTestCase):  
    493502
    494503    def test_builtin_with_settings(self):
    495504        "alternate: django-admin builtin commands succeed if settings are provided as argument"
    496         args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
     505        args = ['sqlall','--settings=regressiontests.alternate_settings', 'admin_scripts']
    497506        out, err = self.run_django_admin(args)
    498507        self.assertNoOutput(err)
    499508        self.assertOutput(out, 'CREATE TABLE')
    class DjangoAdminMultipleSettings(AdminScriptTestCase):  
    501510    def test_builtin_with_environment(self):
    502511        "alternate: django-admin builtin commands succeed if settings are provided in the environment"
    503512        args = ['sqlall','admin_scripts']
    504         out, err = self.run_django_admin(args,'alternate_settings')
     513        out, err = self.run_django_admin(args,'regressiontests.alternate_settings')
    505514        self.assertNoOutput(err)
    506515        self.assertOutput(out, 'CREATE TABLE')
    507516
    class DjangoAdminMultipleSettings(AdminScriptTestCase):  
    526535        self.assertOutput(err, "Unknown command: 'noargs_command'")
    527536
    528537    def test_custom_command_with_settings(self):
    529         "alternate: django-admin can't execute user commands, even if settings are provided as argument"
    530         args = ['noargs_command', '--settings=alternate_settings']
     538        "alternate: django-admin can execute user commands if settings are provided as argument"
     539        args = ['noargs_command', '--settings=regressiontests.alternate_settings']
    531540        out, err = self.run_django_admin(args)
    532541        self.assertNoOutput(err)
    533542        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    534543
    535544    def test_custom_command_with_environment(self):
    536         "alternate: django-admin can't execute user commands, even if settings are provided in environment"
     545        "alternate: django-admin can execute user commands if settings are provided in environment"
    537546        args = ['noargs_command']
    538         out, err = self.run_django_admin(args,'alternate_settings')
     547        out, err = self.run_django_admin(args,'regressiontests.alternate_settings')
    539548        self.assertNoOutput(err)
    540549        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    541550
    class DjangoAdminSettingsDirectory(AdminScriptTestCase):  
    557566        test_dir = os.path.dirname(os.path.dirname(__file__))
    558567        args = ['startapp','settings_test']
    559568        app_path = os.path.join(test_dir, 'settings_test')
    560         out, err = self.run_django_admin(args,'settings')
     569        out, err = self.run_django_admin(args,'regressiontests.settings')
    561570        self.addCleanup(shutil.rmtree, app_path)
    562571        self.assertNoOutput(err)
    563572        self.assertTrue(os.path.exists(app_path))
    class DjangoAdminSettingsDirectory(AdminScriptTestCase):  
    591600
    592601    def test_builtin_with_settings(self):
    593602        "directory: django-admin builtin commands succeed if settings are provided as argument"
    594         args = ['sqlall','--settings=settings', 'admin_scripts']
     603        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    595604        out, err = self.run_django_admin(args)
    596605        self.assertNoOutput(err)
    597606        self.assertOutput(out, 'CREATE TABLE')
    class DjangoAdminSettingsDirectory(AdminScriptTestCase):  
    599608    def test_builtin_with_environment(self):
    600609        "directory: django-admin builtin commands succeed if settings are provided in the environment"
    601610        args = ['sqlall','admin_scripts']
    602         out, err = self.run_django_admin(args,'settings')
     611        out, err = self.run_django_admin(args,'regressiontests.settings')
    603612        self.assertNoOutput(err)
    604613        self.assertOutput(out, 'CREATE TABLE')
    605614
    class ManageNoSettings(AdminScriptTestCase):  
    618627        args = ['sqlall','admin_scripts']
    619628        out, err = self.run_manage(args)
    620629        self.assertNoOutput(out)
    621         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     630        self.assertOutput(err, "Could not import settings 'regressiontests.settings'")
    622631
    623632    def test_builtin_with_bad_settings(self):
    624633        "no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist"
    625634        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
    626635        out, err = self.run_manage(args)
    627636        self.assertNoOutput(out)
    628         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     637        self.assertOutput(err, "Could not import settings 'bad_settings'")
    629638
    630639    def test_builtin_with_bad_environment(self):
    631640        "no settings: manage.py builtin commands fail if settings file (from environment) doesn't exist"
    632641        args = ['sqlall','admin_scripts']
    633642        out, err = self.run_manage(args,'bad_settings')
    634643        self.assertNoOutput(out)
    635         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     644        self.assertOutput(err, "Could not import settings 'bad_settings'")
    636645
    637646
    638647class ManageDefaultSettings(AdminScriptTestCase):
    class ManageDefaultSettings(AdminScriptTestCase):  
    654663
    655664    def test_builtin_with_settings(self):
    656665        "default: manage.py builtin commands succeed if settings are provided as argument"
    657         args = ['sqlall','--settings=settings', 'admin_scripts']
     666        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    658667        out, err = self.run_manage(args)
    659668        self.assertNoOutput(err)
    660669        self.assertOutput(out, 'CREATE TABLE')
    class ManageDefaultSettings(AdminScriptTestCase):  
    662671    def test_builtin_with_environment(self):
    663672        "default: manage.py builtin commands succeed if settings are provided in the environment"
    664673        args = ['sqlall','admin_scripts']
    665         out, err = self.run_manage(args,'settings')
     674        out, err = self.run_manage(args,'regressiontests.settings')
    666675        self.assertNoOutput(err)
    667676        self.assertOutput(out, 'CREATE TABLE')
    668677
    class ManageDefaultSettings(AdminScriptTestCase):  
    689698
    690699    def test_custom_command_with_settings(self):
    691700        "default: manage.py can execute user commands when settings are provided as argument"
    692         args = ['noargs_command', '--settings=settings']
     701        args = ['noargs_command', '--settings=regressiontests.settings']
    693702        out, err = self.run_manage(args)
    694703        self.assertNoOutput(err)
    695704        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    class ManageDefaultSettings(AdminScriptTestCase):  
    697706    def test_custom_command_with_environment(self):
    698707        "default: manage.py can execute user commands when settings are provided in environment"
    699708        args = ['noargs_command']
    700         out, err = self.run_manage(args,'settings')
     709        out, err = self.run_manage(args,'regressiontests.settings')
    701710        self.assertNoOutput(err)
    702711        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    703712
    class ManageFullPathDefaultSettings(AdminScriptTestCase):  
    721730
    722731    def test_builtin_with_settings(self):
    723732        "fulldefault: manage.py builtin commands succeed if settings are provided as argument"
    724         args = ['sqlall','--settings=settings', 'admin_scripts']
     733        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    725734        out, err = self.run_manage(args)
    726735        self.assertNoOutput(err)
    727736        self.assertOutput(out, 'CREATE TABLE')
    class ManageFullPathDefaultSettings(AdminScriptTestCase):  
    729738    def test_builtin_with_environment(self):
    730739        "fulldefault: manage.py builtin commands succeed if settings are provided in the environment"
    731740        args = ['sqlall','admin_scripts']
    732         out, err = self.run_manage(args,'settings')
     741        out, err = self.run_manage(args,'regressiontests.settings')
    733742        self.assertNoOutput(err)
    734743        self.assertOutput(out, 'CREATE TABLE')
    735744
    class ManageFullPathDefaultSettings(AdminScriptTestCase):  
    756765
    757766    def test_custom_command_with_settings(self):
    758767        "fulldefault: manage.py can execute user commands when settings are provided as argument"
    759         args = ['noargs_command', '--settings=settings']
     768        args = ['noargs_command', '--settings=regressiontests.settings']
    760769        out, err = self.run_manage(args)
    761770        self.assertNoOutput(err)
    762771        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    class ManageFullPathDefaultSettings(AdminScriptTestCase):  
    764773    def test_custom_command_with_environment(self):
    765774        "fulldefault: manage.py can execute user commands when settings are provided in environment"
    766775        args = ['noargs_command']
    767         out, err = self.run_manage(args,'settings')
     776        out, err = self.run_manage(args,'regressiontests.settings')
    768777        self.assertNoOutput(err)
    769778        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    770779
    class ManageMinimalSettings(AdminScriptTestCase):  
    787796
    788797    def test_builtin_with_settings(self):
    789798        "minimal: manage.py builtin commands fail if settings are provided as argument"
    790         args = ['sqlall','--settings=settings', 'admin_scripts']
     799        args = ['sqlall','--settings=regressiontests.settings', 'admin_scripts']
    791800        out, err = self.run_manage(args)
    792801        self.assertNoOutput(out)
    793802        self.assertOutput(err, 'App with label admin_scripts could not be found')
    class ManageMinimalSettings(AdminScriptTestCase):  
    795804    def test_builtin_with_environment(self):
    796805        "minimal: manage.py builtin commands fail if settings are provided in the environment"
    797806        args = ['sqlall','admin_scripts']
    798         out, err = self.run_manage(args,'settings')
     807        out, err = self.run_manage(args,'regressiontests.settings')
    799808        self.assertNoOutput(out)
    800809        self.assertOutput(err, 'App with label admin_scripts could not be found')
    801810
    class ManageMinimalSettings(AdminScriptTestCase):  
    822831
    823832    def test_custom_command_with_settings(self):
    824833        "minimal: manage.py can't execute user commands, even if settings are provided as argument"
    825         args = ['noargs_command', '--settings=settings']
     834        args = ['noargs_command', '--settings=regressiontests.settings']
    826835        out, err = self.run_manage(args)
    827836        self.assertNoOutput(out)
    828837        self.assertOutput(err, "Unknown command: 'noargs_command'")
    class ManageMinimalSettings(AdminScriptTestCase):  
    830839    def test_custom_command_with_environment(self):
    831840        "minimal: manage.py can't execute user commands, even if settings are provided in environment"
    832841        args = ['noargs_command']
    833         out, err = self.run_manage(args,'settings')
     842        out, err = self.run_manage(args,'regressiontests.settings')
    834843        self.assertNoOutput(out)
    835844        self.assertOutput(err, "Unknown command: 'noargs_command'")
    836845
    class ManageAlternateSettings(AdminScriptTestCase):  
    849858        args = ['sqlall','admin_scripts']
    850859        out, err = self.run_manage(args)
    851860        self.assertNoOutput(out)
    852         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     861        self.assertOutput(err, "Could not import settings 'regressiontests.settings'")
    853862
    854863    def test_builtin_with_settings(self):
    855         "alternate: manage.py builtin commands fail if settings are provided as argument but no defaults"
     864        "alternate: manage.py builtin commands work with settings provided as argument"
    856865        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
    857866        out, err = self.run_manage(args)
    858         self.assertNoOutput(out)
    859         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     867        self.assertOutput(out, 'CREATE TABLE "admin_scripts_article"')
     868        self.assertNoOutput(err)
    860869
    861870    def test_builtin_with_environment(self):
    862         "alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults"
     871        "alternate: manage.py builtin commands work if settings are provided in the environment"
    863872        args = ['sqlall','admin_scripts']
    864873        out, err = self.run_manage(args,'alternate_settings')
    865         self.assertNoOutput(out)
    866         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     874        self.assertOutput(out, 'CREATE TABLE "admin_scripts_article"')
     875        self.assertNoOutput(err)
    867876
    868877    def test_builtin_with_bad_settings(self):
    869878        "alternate: manage.py builtin commands fail if settings file (from argument) doesn't exist"
    870879        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
    871880        out, err = self.run_manage(args)
    872881        self.assertNoOutput(out)
    873         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     882        self.assertOutput(err, "Could not import settings 'bad_settings'")
    874883
    875884    def test_builtin_with_bad_environment(self):
    876885        "alternate: manage.py builtin commands fail if settings file (from environment) doesn't exist"
    877886        args = ['sqlall','admin_scripts']
    878887        out, err = self.run_manage(args,'bad_settings')
    879888        self.assertNoOutput(out)
    880         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     889        self.assertOutput(err, "Could not import settings 'bad_settings'")
    881890
    882891    def test_custom_command(self):
    883         "alternate: manage.py can't execute user commands"
     892        "alternate: manage.py can't execute user commands without settings"
    884893        args = ['noargs_command']
    885894        out, err = self.run_manage(args)
    886895        self.assertNoOutput(out)
    887         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     896        self.assertOutput(err, "Unknown command: 'noargs_command'")
    888897
    889898    def test_custom_command_with_settings(self):
    890         "alternate: manage.py can't execute user commands, even if settings are provided as argument"
     899        "alternate: manage.py can execute user commands if settings are provided as argument"
    891900        args = ['noargs_command', '--settings=alternate_settings']
    892901        out, err = self.run_manage(args)
    893         self.assertNoOutput(out)
    894         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     902        self.assertOutput(out, "EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
     903        self.assertNoOutput(err)
    895904
    896905    def test_custom_command_with_environment(self):
    897         "alternate: manage.py can't execute user commands, even if settings are provided in environment"
     906        "alternate: manage.py can execute user commands if settings are provided in environment"
    898907        args = ['noargs_command']
    899908        out, err = self.run_manage(args,'alternate_settings')
    900         self.assertNoOutput(out)
    901         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     909        self.assertOutput(out, "EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
     910        self.assertNoOutput(err)
    902911
    903912
    904913class ManageMultipleSettings(AdminScriptTestCase):
    class ManageSettingsWithImportError(AdminScriptTestCase):  
    9991008        args = ['sqlall','admin_scripts']
    10001009        out, err = self.run_manage(args)
    10011010        self.assertNoOutput(out)
    1002         self.assertOutput(err, "ImportError: No module named foo42bar")
     1011        self.assertOutput(err, "No module named foo42bar")
    10031012
    10041013class ManageValidate(AdminScriptTestCase):
    10051014    def tearDown(self):
  • tests/regressiontests/test_runner/tests.py

    diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
    index cb4d27a..d2f064e 100644
    a b class CustomTestRunnerOptionsTests(AdminScriptTestCase):  
    188188        self.remove_settings('settings.py')
    189189
    190190    def test_default_options(self):
    191         args = ['test', '--settings=settings']
     191        args = ['test', '--settings=regressiontests.settings']
    192192        out, err = self.run_django_admin(args)
    193193        self.assertNoOutput(err)
    194194        self.assertOutput(out, '1:2:3')
    195195
    196196    def test_default_and_given_options(self):
    197         args = ['test', '--settings=settings', '--option_b=foo']
     197        args = ['test', '--settings=regressiontests.settings', '--option_b=foo']
    198198        out, err = self.run_django_admin(args)
    199199        self.assertNoOutput(err)
    200200        self.assertOutput(out, '1:foo:3')
    201201
    202202    def test_option_name_and_value_separated(self):
    203         args = ['test', '--settings=settings', '--option_b', 'foo']
     203        args = ['test', '--settings=regressiontests.settings', '--option_b', 'foo']
    204204        out, err = self.run_django_admin(args)
    205205        self.assertNoOutput(err)
    206206        self.assertOutput(out, '1:foo:3')
    207207
    208208    def test_all_options_given(self):
    209         args = ['test', '--settings=settings', '--option_a=bar', '--option_b=foo', '--option_c=31337']
     209        args = ['test', '--settings=regressiontests.settings', '--option_a=bar', '--option_b=foo', '--option_c=31337']
    210210        out, err = self.run_django_admin(args)
    211211        self.assertNoOutput(err)
    212212        self.assertOutput(out, 'bar:foo:31337')
Back to Top