dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

__init__.py (3762B)


      1 import imp
      2 import os
      3 import sys
      4 import warnings
      5 
      6 # opcode is not a virtualenv module, so we can use it to find the stdlib
      7 # Important! To work on pypy, this must be a module that resides in the
      8 # lib-python/modified-x.y.z directory
      9 import opcode
     10 
     11 dirname = os.path.dirname
     12 
     13 distutils_path = os.path.join(os.path.dirname(opcode.__file__), "distutils")
     14 if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
     15     warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
     16 else:
     17     __path__.insert(0, distutils_path)  # noqa: F821
     18     real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ("", "", imp.PKG_DIRECTORY))
     19     # Copy the relevant attributes
     20     try:
     21         __revision__ = real_distutils.__revision__
     22     except AttributeError:
     23         pass
     24     __version__ = real_distutils.__version__
     25 
     26 from distutils import dist, sysconfig  # isort:skip
     27 
     28 try:
     29     basestring
     30 except NameError:
     31     basestring = str
     32 
     33 # patch build_ext (distutils doesn't know how to get the libs directory
     34 # path on windows - it hardcodes the paths around the patched sys.prefix)
     35 
     36 if sys.platform == "win32":
     37     from distutils.command.build_ext import build_ext as old_build_ext
     38 
     39     class build_ext(old_build_ext):
     40         def finalize_options(self):
     41             if self.library_dirs is None:
     42                 self.library_dirs = []
     43             elif isinstance(self.library_dirs, basestring):
     44                 self.library_dirs = self.library_dirs.split(os.pathsep)
     45 
     46             self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
     47             old_build_ext.finalize_options(self)
     48 
     49     from distutils.command import build_ext as build_ext_module
     50 
     51     build_ext_module.build_ext = build_ext
     52 
     53 # distutils.dist patches:
     54 
     55 old_find_config_files = dist.Distribution.find_config_files
     56 
     57 
     58 def find_config_files(self):
     59     found = old_find_config_files(self)
     60     if os.name == "posix":
     61         user_filename = ".pydistutils.cfg"
     62     else:
     63         user_filename = "pydistutils.cfg"
     64     user_filename = os.path.join(sys.prefix, user_filename)
     65     if os.path.isfile(user_filename):
     66         for item in list(found):
     67             if item.endswith("pydistutils.cfg"):
     68                 found.remove(item)
     69         found.append(user_filename)
     70     return found
     71 
     72 
     73 dist.Distribution.find_config_files = find_config_files
     74 
     75 # distutils.sysconfig patches:
     76 
     77 old_get_python_inc = sysconfig.get_python_inc
     78 
     79 
     80 def sysconfig_get_python_inc(plat_specific=0, prefix=None):
     81     if prefix is None:
     82         prefix = sys.real_prefix
     83     return old_get_python_inc(plat_specific, prefix)
     84 
     85 
     86 sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__
     87 sysconfig.get_python_inc = sysconfig_get_python_inc
     88 
     89 old_get_python_lib = sysconfig.get_python_lib
     90 
     91 
     92 def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
     93     if standard_lib and prefix is None:
     94         prefix = sys.real_prefix
     95     return old_get_python_lib(plat_specific, standard_lib, prefix)
     96 
     97 
     98 sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__
     99 sysconfig.get_python_lib = sysconfig_get_python_lib
    100 
    101 old_get_config_vars = sysconfig.get_config_vars
    102 
    103 
    104 def sysconfig_get_config_vars(*args):
    105     real_vars = old_get_config_vars(*args)
    106     if sys.platform == "win32":
    107         lib_dir = os.path.join(sys.real_prefix, "libs")
    108         if isinstance(real_vars, dict) and "LIBDIR" not in real_vars:
    109             real_vars["LIBDIR"] = lib_dir  # asked for all
    110         elif isinstance(real_vars, list) and "LIBDIR" in args:
    111             real_vars = real_vars + [lib_dir]  # asked for list
    112     return real_vars
    113 
    114 
    115 sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__
    116 sysconfig.get_config_vars = sysconfig_get_config_vars