[SciPy-dev] PYTHONINCLUDE and sitecustomize.py

Pearu Peterson pearu at cens.ioc.ee
Mon Dec 30 02:22:21 CST 2002


On Sun, 29 Dec 2002, eric jones wrote:

> Hey Pearu,
> 
> The script wasn't attached.  Is this a mailing list issue, or just an
> oversight?  Anyway, I'd like to have a look at it.

It wasn't oversight. I guess mailman stripped the attachment.
Anyway, the script is inserted below.
Additional comment on the script:
  OSDIR should be renamed to PYTHONPREFIX or MYPYTHONPREFIX or similar.

Pearu

#!/usr/bin/env python
#
# Purpose:
#   Facilitate installing/using Python extension modules to/from
#   non-standard locations when installation is carried out as
#     python setup.py install --prefix=$HOME
#   or
#     python setup.py install --prefix=$OSDIR
#   where the environment variable OSDIR contains arbitrary path.
#
# Recommended but optional environment (as defined in ~/.bashrc):
#  OSDIR=~/plat/`python -c 'import string;from distutils.util \
#           import get_platform;print string.replace(get_platform()," ","_")'`
#  export OSDIR
#  export PYTHONPATH=.:$HOME/site-python
#  export PATH=$OSDIR/bin:$PATH
#
# Usage:
#  Copy sitecustomize.py to location (e.g. to $HOME/site-python/)
#  where Python can import it.
#
# Features:
#  * Add <prefix>/lib/python<version>/site-packages to sys.path
#  * Add <prefix>/include/python<version> to the list of include_dirs
#    of distutils.build_ext.build_ext class
#  * Fix distutils.util.get_platform bug on Mac OS X
#
# Author: Pearu Peterson, Dec 2002
#

import os
import sys
import site
import string


########

from distutils.sysconfig import get_python_inc

l=len(sys.path)
prefixes = [os.environ.get('OSDIR'),os.environ.get('HOME')]
extra_include_dirs = {}

for prefix in prefixes:
    if prefix:
        if os.sep == '/':
            sitedirs = [os.path.join(prefix,
                                     "lib",
                                     "python" + sys.version[:3],
                                     "site-packages"),
                        os.path.join(prefix, "lib", "site-python")]
        else:
            sitedirs = [prefix, os.path.join(prefix, "lib", "site-packages")]
        for sitedir in sitedirs:
            if os.path.isdir(sitedir):
                site.addsitedir(sitedir)
        incdir = get_python_inc(prefix=prefix)
        if os.path.isdir(incdir):
            extra_include_dirs[incdir] = 1

extra_include_dirs = extra_include_dirs.keys()
sys.path = sys.path[l:] + sys.path[:l]

###########

from distutils.command import build_ext
old_build_ext = build_ext.build_ext
class site_build_ext(old_build_ext):
    def finalize_options (self):
        old_build_ext.finalize_options(self)
        l = len(self.include_dirs) - 1
        for d in extra_include_dirs:
            try:
                self.include_dirs.index(d)
            except ValueError:
                # insert just before system include_dir
                self.include_dirs.insert(l,d)
                l = l - 1
build_ext.build_ext = site_build_ext

###########

from distutils import util
old_get_platform = util.get_platform
def get_platform():
    return string.replace(old_get_platform()," ","_")
util.get_platform = get_platform

###########

if __name__=='__main__':
    site._test()




More information about the Scipy-dev mailing list