|
1 import os |
|
2 import sys |
|
3 import warnings |
|
4 import ConfigParser # ConfigParser is not a virtualenv module, so we can use it to find the stdlib |
|
5 |
|
6 dirname = os.path.dirname |
|
7 |
|
8 distutils_path = os.path.join(os.path.dirname(ConfigParser.__file__), 'distutils') |
|
9 if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)): |
|
10 warnings.warn( |
|
11 "The virtualenv distutils package at %s appears to be in the same location as the system distutils?") |
|
12 else: |
|
13 __path__.insert(0, distutils_path) |
|
14 exec open(os.path.join(distutils_path, '__init__.py')).read() |
|
15 |
|
16 import dist |
|
17 import sysconfig |
|
18 |
|
19 |
|
20 ## patch build_ext (distutils doesn't know how to get the libs directory |
|
21 ## path on windows - it hardcodes the paths around the patched sys.prefix) |
|
22 |
|
23 if sys.platform == 'win32': |
|
24 from distutils.command.build_ext import build_ext as old_build_ext |
|
25 class build_ext(old_build_ext): |
|
26 def finalize_options (self): |
|
27 if self.library_dirs is None: |
|
28 self.library_dirs = [] |
|
29 |
|
30 self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs")) |
|
31 old_build_ext.finalize_options(self) |
|
32 |
|
33 from distutils.command import build_ext as build_ext_module |
|
34 build_ext_module.build_ext = build_ext |
|
35 |
|
36 ## distutils.dist patches: |
|
37 |
|
38 old_find_config_files = dist.Distribution.find_config_files |
|
39 def find_config_files(self): |
|
40 found = old_find_config_files(self) |
|
41 system_distutils = os.path.join(distutils_path, 'distutils.cfg') |
|
42 #if os.path.exists(system_distutils): |
|
43 # found.insert(0, system_distutils) |
|
44 # What to call the per-user config file |
|
45 if os.name == 'posix': |
|
46 user_filename = ".pydistutils.cfg" |
|
47 else: |
|
48 user_filename = "pydistutils.cfg" |
|
49 user_filename = os.path.join(sys.prefix, user_filename) |
|
50 if os.path.isfile(user_filename): |
|
51 for item in list(found): |
|
52 if item.endswith('pydistutils.cfg'): |
|
53 found.remove(item) |
|
54 found.append(user_filename) |
|
55 return found |
|
56 dist.Distribution.find_config_files = find_config_files |
|
57 |
|
58 ## distutils.sysconfig patches: |
|
59 |
|
60 old_get_python_inc = sysconfig.get_python_inc |
|
61 def sysconfig_get_python_inc(plat_specific=0, prefix=None): |
|
62 if prefix is None: |
|
63 prefix = sys.real_prefix |
|
64 return old_get_python_inc(plat_specific, prefix) |
|
65 sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__ |
|
66 sysconfig.get_python_inc = sysconfig_get_python_inc |
|
67 |
|
68 old_get_python_lib = sysconfig.get_python_lib |
|
69 def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None): |
|
70 if standard_lib and prefix is None: |
|
71 prefix = sys.real_prefix |
|
72 return old_get_python_lib(plat_specific, standard_lib, prefix) |
|
73 sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__ |
|
74 sysconfig.get_python_lib = sysconfig_get_python_lib |
|
75 |
|
76 old_get_config_vars = sysconfig.get_config_vars |
|
77 def sysconfig_get_config_vars(*args): |
|
78 real_vars = old_get_config_vars(*args) |
|
79 if sys.platform == 'win32': |
|
80 lib_dir = os.path.join(sys.real_prefix, "libs") |
|
81 if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars: |
|
82 real_vars['LIBDIR'] = lib_dir # asked for all |
|
83 elif isinstance(real_vars, list) and 'LIBDIR' in args: |
|
84 real_vars = real_vars + [lib_dir] # asked for list |
|
85 return real_vars |
|
86 sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__ |
|
87 sysconfig.get_config_vars = sysconfig_get_config_vars |