Statistics
| Branch: | Revision:

root / env / lib / python2.7 / distutils / __init__.py @ 1a305335

History | View | Annotate | Download (3.72 KB)

1
import os
2
import sys
3
import warnings 
4
import opcode # opcode is not a virtualenv module, so we can use it to find the stdlib
5
              # Important! To work on pypy, this must be a module that resides in the
6
              # lib-python/modified-x.y.z directory
7

    
8
dirname = os.path.dirname
9

    
10
distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
11
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
12
    warnings.warn(
13
        "The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
14
else:
15
    __path__.insert(0, distutils_path)
16
    exec(open(os.path.join(distutils_path, '__init__.py')).read())
17

    
18
try:
19
    import dist
20
    import sysconfig
21
except ImportError:
22
    from distutils import dist, sysconfig
23
try:
24
    basestring
25
except NameError:
26
    basestring = str
27

    
28
## patch build_ext (distutils doesn't know how to get the libs directory
29
## path on windows - it hardcodes the paths around the patched sys.prefix)
30

    
31
if sys.platform == 'win32':
32
    from distutils.command.build_ext import build_ext as old_build_ext
33
    class build_ext(old_build_ext):
34
        def finalize_options (self):
35
            if self.library_dirs is None:
36
                self.library_dirs = []
37
            elif isinstance(self.library_dirs, basestring):
38
                self.library_dirs = self.library_dirs.split(os.pathsep)
39
            
40
            self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
41
            old_build_ext.finalize_options(self)
42
            
43
    from distutils.command import build_ext as build_ext_module 
44
    build_ext_module.build_ext = build_ext
45

    
46
## distutils.dist patches:
47

    
48
old_find_config_files = dist.Distribution.find_config_files
49
def find_config_files(self):
50
    found = old_find_config_files(self)
51
    system_distutils = os.path.join(distutils_path, 'distutils.cfg')
52
    #if os.path.exists(system_distutils):
53
    #    found.insert(0, system_distutils)
54
        # What to call the per-user config file
55
    if os.name == 'posix':
56
        user_filename = ".pydistutils.cfg"
57
    else:
58
        user_filename = "pydistutils.cfg"
59
    user_filename = os.path.join(sys.prefix, user_filename)
60
    if os.path.isfile(user_filename):
61
        for item in list(found):
62
            if item.endswith('pydistutils.cfg'):
63
                found.remove(item)
64
        found.append(user_filename)
65
    return found
66
dist.Distribution.find_config_files = find_config_files
67

    
68
## distutils.sysconfig patches:
69

    
70
old_get_python_inc = sysconfig.get_python_inc
71
def sysconfig_get_python_inc(plat_specific=0, prefix=None):
72
    if prefix is None:
73
        prefix = sys.real_prefix
74
    return old_get_python_inc(plat_specific, prefix)
75
sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__
76
sysconfig.get_python_inc = sysconfig_get_python_inc
77

    
78
old_get_python_lib = sysconfig.get_python_lib
79
def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
80
    if standard_lib and prefix is None:
81
        prefix = sys.real_prefix
82
    return old_get_python_lib(plat_specific, standard_lib, prefix)
83
sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__
84
sysconfig.get_python_lib = sysconfig_get_python_lib
85

    
86
old_get_config_vars = sysconfig.get_config_vars
87
def sysconfig_get_config_vars(*args):
88
    real_vars = old_get_config_vars(*args)
89
    if sys.platform == 'win32':
90
        lib_dir = os.path.join(sys.real_prefix, "libs")
91
        if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars:
92
            real_vars['LIBDIR'] = lib_dir # asked for all
93
        elif isinstance(real_vars, list) and 'LIBDIR' in args:
94
            real_vars = real_vars + [lib_dir] # asked for list
95
    return real_vars
96
sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__
97
sysconfig.get_config_vars = sysconfig_get_config_vars