ramkrishanbhatt / modwsgi

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

Slightly more automatic way of re-ordering paths for django + apache #266

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I've made a slightly more automatic version of the code here:
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

By assuming anything not in sys.prefix is in your virtualenv you can avoid 
having to hard code it's location.

New code looks like this:

from itertools import ifilterfalse
import site
import sys

# Assume any directories not in sys.prefix are from our virtualenv
ALLDIRS = list(ifilterfalse(lambda x: x.startswith(sys.prefix), sys.path))

# Remember original sys.path.
prev_sys_path = list(sys.path) 

# Add each new site-packages directory.
for directory in ALLDIRS:
   site.addsitedir(directory)

# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

Original issue reported on code.google.com by stu.a...@gmail.com on 24 May 2012 at 2:19

GoogleCodeExporter commented 8 years ago
Closing as the need for all this sort of mucking around was superseded through 
better configuration options in subsequent mod_wsgi releases.

Original comment by Graham.Dumpleton@gmail.com on 16 Sep 2014 at 7:01