summary refs log tree commit diff
path: root/pkgs/development/python-modules/virtualenv-change-prefix.patch
blob: 958187f982fe95d4999494b50dcf204d97bb340f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Without this patch `virtualenv --python=python2.7 .` fails with an
error because it notices that the python readline.so is not in the
same path as python2.7. I assume this is to avoid copying the wrong
file on systems where it is possible to find incompatible libraries by
accident. Adding "/nix/store" to the prefix fixes this problem.

A sitecustomize.py is created in the virtualenv which makes libraries
from the python specified by the --python argument available to the
virtualenv. For example, this makes readline and sqlite3 available
when a wrapped python is specified. If no --python argument is passed,
it will only add the path to the python used when building
`virtualenv`, which is the unwrapped python, so sqlite3 won't be
available.


diff --git a/virtualenv.py b/virtualenv.py
index d3e76a7..cb307fa 100755
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -1051,17 +1051,7 @@ def path_locations(home_dir):
 
 
 def change_prefix(filename, dst_prefix):
-    prefixes = [sys.prefix]
-
-    if is_darwin:
-        prefixes.extend((
-            os.path.join("/Library/Python", sys.version[:3], "site-packages"),
-            os.path.join(sys.prefix, "Extras", "lib", "python"),
-            os.path.join("~", "Library", "Python", sys.version[:3], "site-packages"),
-            # Python 2.6 no-frameworks
-            os.path.join("~", ".local", "lib","python", sys.version[:3], "site-packages"),
-            # System Python 2.7 on OSX Mountain Lion
-            os.path.join("~", "Library", "Python", sys.version[:3], "lib", "python", "site-packages")))
+    prefixes = ["/nix/store", sys.prefix]
 
     if hasattr(sys, 'real_prefix'):
         prefixes.append(sys.real_prefix)
@@ -1078,6 +1068,8 @@ def change_prefix(filename, dst_prefix):
             if src_prefix != os.sep: # sys.prefix == "/"
                 assert relpath[0] == os.sep
                 relpath = relpath[1:]
+                if src_prefix == "/nix/store":
+                    relpath = "/".join(relpath.split("/")[1:])
             return join(dst_prefix, relpath)
     assert False, "Filename %s does not start with any of these prefixes: %s" % \
         (filename, prefixes)
@@ -1190,6 +1182,11 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
     site_filename_dst = change_prefix(site_filename, home_dir)
     site_dir = os.path.dirname(site_filename_dst)
     writefile(site_filename_dst, SITE_PY)
+    wrapper_path = join(prefix, "lib", py_version, "site-packages")
+    writefile(
+        join(site_dir, 'sitecustomize.py',),
+        "import sys; sys.path.append('%s')" % wrapper_path
+    )
     writefile(join(site_dir, 'orig-prefix.txt'), prefix)
     site_packages_filename = join(site_dir, 'no-global-site-packages.txt')
     if not site_packages: