title: Python fabric "local" function does not respect environment variable DJANGO_SETTINGS_MODULE
body: <p>I have the following scheme for my project's settings:</p>
  
  <pre><code>myproject/
     app1/
     app2/
     appN/
     settings/
        __init__.py
        base.py
        devel.py
        production.py
  </code></pre>
  
  <p>In my local environment I have inside the virtualenvwrapper's <code>postactivate</code> script:</p>
  
  <pre><code>myproject_root=/home/rantanplan/Projects/repos/myproject
  cd $myproject_root
  export DJANGO_SETTINGS_MODULE=myproject.settings.devel
  </code></pre>
  
  <p>So that when I do <code>workon myproject</code> it will change to the project's root dir and
  set the active <code>DJANGO_SETTINGS_MODULE</code> I want.</p>
  
  <p>This is fine for django and all the commands(like <code>python manage.py syncdb</code>) work.</p>
  
  <p>Now on the other hand I have this fabric task:</p>
  
  <pre><code>@task
  def syncdb():
      local('python manage.py syncdb --noinput')
  </code></pre>
  
  <p>This used to work fine when I had a simple <code>settings.py</code> file, but when I changed
  to the above scheme it raises this exception:</p>
  
  <pre><code>django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
  
  Fatal error: local() encountered an error (return code 1) while executing 'python manage.py syncdb --noinput'
  
  Aborting.
  </code></pre>
  
  <p>Some additional notes:</p>
  
  <ul>
  <li><a href="http://docs.fabfile.org/en/1.5/api/contrib/django.html#fabric.contrib.django.project" rel="nofollow">project</a> function is not applicable here since it falsely assumes(internally) that all django settings modules are named as "settings".</li>
  <li>I tried the <a href="http://docs.fabfile.org/en/1.5/api/contrib/django.html#fabric.contrib.django.settings_module" rel="nofollow">settings_module</a> function to no avail. It uses <code>os.environ</code> internally to set the environment variable but to no effect.</li>
  <li>If I print the <code>os.environ['DJANGO_SETTINGS_MODULE']</code> just before my task definition, it correctly prints "myproject.settings.devel".</li>
  </ul>
  
  <p>So what am I doing wrong here and how do you propose I should go about solving this issue?</p>
  
  <hr>
  
  <p>To spare you the trouble I should say that I know I can solve this by doing:</p>
  
  <pre><code>def syncdb():
      with prefix('export DJANGO_SETTINGS_MODULE=myproject.settings.devel'):
          local('python manage.py syncdb --noinput')
  </code></pre>
  
  <p>but I'd rather avoid the use of <code>prefix</code> if I can.</p>
  
  <p>Also I know I could do, as hynekcer suggests:</p>
  
  <pre><code>@task
  def syncdb():
      local('python manage.py syncdb --settings=myproject.settings.devel --noinput')
  </code></pre>
  
  <p>but I really want to know why <code>local</code> does not respect the <code>DJANGO_SETTINGS_MODULE</code> and
  why <code>settings_module</code> does not work as advertised.</p>