jvandal / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

It would be nice if the WSGIPythonPath directive could be used in Directory context #154

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to move some web.py apps from from mod_pyton3 to mod_wsgi.  With
mod_pyton3, I can put python modules in the same directory as codep.py. But
with mod_wsgi, that directory doesn't seem to be part of the PYTHONPATH.
Since WSGIPythonPath is only valid in global server config context, it
doesn't seem to be possible to python modules with the same name but
different code in different applications.

So: it would be very handy to be able to use WSGIPythonPath in Directory
context, e.g.:

<VirtualHost ...>
    WSGIScriptAlias /app1 /www/app1/codep.py/
    <Directory "/www/app1/">
        WSGIPythonPath /www/app1
    </Directory>

    WSGIScriptAlias /app2 /www/app2/codep.py/
    <Directory "/www/app2/">
        WSGIPythonPath /www/app2
    </Directory>
</VirtualHost>

Original issue reported on code.google.com by craigle...@gmail.com on 2 Sep 2009 at 4:45

GoogleCodeExporter commented 8 years ago
The directory isn't part of PYTHONPATH (sys.path) on mod_python any more as 
that causes lots of problems. See:

  http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken

To fix the problems mod_python has a custom import hook that intercepts import 
and does special magic. In 
doing that though there are various restrictions. For example, you can't put 
packages in the document directory 
and be able to import them. If you fiddle things and explicitly add the 
directory using PythonPath, then you can 
cause other problems with double imports.

It is because of all the problems that can come up with trying to maintain 
separate sys.path per 
location/directory context that mod_wsgi doesn't attempt to do the same. So, 
will not be changing 
WSGIPythonPath behaviour. Also be aware that that directive only applies to 
embedded mode anyway and not 
daemon mode.

If you want a solution, go ask your question about what you want to achieve on 
the mod_wsgi mailing list on 
Google Groups and I will give you a description there of how you can achieve 
what you want. I don't want to do it 
here as it will be of general interest as I haven't necessarily explained it 
previously on the list nor is it 
documented.

Original comment by Graham.Dumpleton@gmail.com on 2 Sep 2009 at 5:25