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