Missing basedir/apps in sys.path?

Dirk Wallenstein halsmit at t-online.de
Fri Feb 4 01:34:02 EST 2011


On Thu, Feb 03, 2011 at 11:47:56AM -0200, Guilherme Salgado wrote:
> On Thu, 2011-02-03 at 12:04 +0100, Dirk Wallenstein wrote:
> [...]
> > > 
> > > --- a/lib/apache2/patchwork.wsgi
> > > +++ b/lib/apache2/patchwork.wsgi
> > > @@ -11,6 +11,7 @@ import sys
> > >  
> > >  basedir = os.path.dirname(__file__)
> > >  sys.path.append(basedir)
> > > +sys.path.append(os.path.join(basedir, 'apps'))
> > >  
> > >  os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
> > >  import django.core.handlers.wsgi
> > 
> > Looks good.
> > However, I find it a bit confusing to construct a path that relies on
> > the fact that this module is found through a symlink.  I would hardcode
> > '/srv/patchwork' and '/srv/patchwork/apps' like in the mod_python
> 
> That means one more place people will have to remember to change when
> deploying/moving an instance, so I don't think it's a good idea.
> 
> > config.  Or would it be possible to get rid of the symlink
> > '/srv/patchwork/patchwork.wsgi' when changing it in
> > apache2/patchwork.wsgi.conf and then optionally construct the paths
> > relative from the real location?
> 
> Yes, it's possible to use the real path to patchwork.wsgi in the apache
> config and then have patchwork.wsgi construct the path from its real
> location, but using the symlink may be a good idea because it provides
> some flexibility in case there's ever a need to move patchwork.wsgi to a
> different place.  That flexibility may never be used, though.

Currently, only one can be used unless os.path.realpath is added into
the mix.  I would favor to remove duplication here -- if it was broken
anyway, that is.

> This is what the diff looks like:
> 
> diff --git a/lib/apache2/patchwork.wsgi b/lib/apache2/patchwork.wsgi
> index 0488b48..869bb9d 100644
> --- a/lib/apache2/patchwork.wsgi
> +++ b/lib/apache2/patchwork.wsgi
> @@ -9,8 +9,10 @@
>  import os
>  import sys
>  
> -basedir = os.path.dirname(__file__)
> +basedir = os.path.join(
> +    os.path.dirname(__file__), os.path.pardir, os.path.pardir)
>  sys.path.append(basedir)
> +sys.path.append(os.path.join(basedir, 'apps'))
>  
>  os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
>  import django.core.handlers.wsgi
> diff --git a/lib/apache2/patchwork.wsgi.conf b/lib/apache2/patchwork.wsgi.conf
> index e99f8c6..3756e5a 100644
> --- a/lib/apache2/patchwork.wsgi.conf
> +++ b/lib/apache2/patchwork.wsgi.conf
> @@ -16,5 +16,5 @@
>          </Directory>
>  </IfModule>
>  
> -WSGIScriptAlias / "/srv/patchwork/patchwork.wsgi"
> +WSGIScriptAlias / "/srv/patchwork/lib/apache2/patchwork.wsgi"
>  WSGIPassAuthorization On

Wonderful.

-- 
Greetings,
Dirk


More information about the Patchwork mailing list