Description: distutils: Add an option --install-layout=deb
 This option:
  - installs into $prefix/dist-packages instead of $prefix/site-packages.
  - doesn't encode the python version into the egg name.
Origin: cpython Debian packaging
Author: Matthias Klose <doko@debian.org>
Author: Stefano Rivera <stefanor@debian.org>
Last-Update: 2012-01-07

--- a/lib-python/modified-2.7/distutils/command/install.py
+++ b/lib-python/modified-2.7/distutils/command/install.py
@@ -41,9 +41,23 @@
 
 INSTALL_SCHEMES = {
     'unix_prefix': {
-        'purelib': '$base/lib/python$py_version_short/site-packages',
-        'platlib': '$platbase/lib/python$py_version_short/site-packages',
-        'headers': '$base/include/python$py_version_short/$dist_name',
+        'purelib': '$base/lib/pypy$py_version_short/site-packages',
+        'platlib': '$platbase/lib/pypy$py_version_short/site-packages',
+        'headers': '$base/include/pypy$py_version_short/$dist_name',
+        'scripts': '$base/bin',
+        'data'   : '$base',
+        },
+    'unix_local': {
+        'purelib': '$base/local/lib/pypy$py_version_short/dist-packages',
+        'platlib': '$platbase/local/lib/pypy$py_version_short/dist-packages',
+        'headers': '$base/local/include/pypy$py_version_short/$dist_name',
+        'scripts': '$base/local/bin',
+        'data'   : '$base/local',
+        },
+    'deb_system': {
+        'purelib': '$base/lib/pypy/dist-packages',
+        'platlib': '$platbase/lib/pypy/dist-packages',
+        'headers': '$base/include/pypy$py_version_short/$dist_name',
         'scripts': '$base/bin',
         'data'   : '$base',
         },
@@ -57,7 +71,7 @@
     'unix_user': {
         'purelib': '$usersite',
         'platlib': '$usersite',
-        'headers': '$userbase/include/python$py_version_short/$dist_name',
+        'headers': '$userbase/include/pypy$py_version_short/$dist_name',
         'scripts': '$userbase/bin',
         'data'   : '$userbase',
         },
@@ -161,6 +175,9 @@
 
         ('record=', None,
          "filename in which to record list of installed files"),
+
+        ('install-layout=', None,
+         "installation layout to choose (known values: deb, unix)"),
         ]
 
     boolean_options = ['compile', 'force', 'skip-build', 'user']
@@ -175,6 +192,7 @@
         self.exec_prefix = None
         self.home = None
         self.user = 0
+        self.prefix_option = None
 
         # These select only the installation base; it's up to the user to
         # specify the installation scheme (currently, that means supplying
@@ -196,6 +214,9 @@
         self.install_userbase = USER_BASE
         self.install_usersite = USER_SITE
 
+        # enable custom installation, known values: deb
+        self.install_layout = None
+
         self.compile = None
         self.optimize = None
 
@@ -428,6 +449,7 @@
             self.install_base = self.install_platbase = self.home
             self.select_scheme("unix_home")
         else:
+            self.prefix_option = self.prefix
             if self.prefix is None:
                 if self.exec_prefix is not None:
                     raise DistutilsOptionError, \
@@ -442,7 +464,24 @@
 
             self.install_base = self.prefix
             self.install_platbase = self.exec_prefix
-            self.select_scheme("unix_prefix")
+            if self.install_layout:
+                if self.install_layout.lower() in ['deb']:
+                    self.select_scheme("deb_system")
+                elif self.install_layout.lower() in ['unix']:
+                    self.select_scheme("unix_prefix")
+                else:
+                    raise DistutilsOptionError(
+                        "unknown value for --install-layout")
+            elif (self.prefix_option and os.path.normpath(self.prefix) != '/usr/local') \
+                    or 'PYTHONUSERBASE' in os.environ \
+                    or 'real_prefix' in sys.__dict__:
+                self.select_scheme("unix_prefix")
+            else:
+                if os.path.normpath(self.prefix) == '/usr/local':
+                    self.prefix = self.exec_prefix = '/usr'
+                    self.install_base = self.install_platbase = '/usr'
+                self.select_scheme("unix_local")
+
 
     # finalize_unix ()
 
@@ -474,8 +513,10 @@
 
     def select_scheme (self, name):
         # it's the caller's problem if they supply a bad name!
-        if hasattr(sys, 'pypy_version_info'):
-            name = 'pypy'
+
+        # We don't use pypy's upstream scheme
+        #if hasattr(sys, 'pypy_version_info'):
+        #    name = 'pypy'
         scheme = INSTALL_SCHEMES[name]
         for key in SCHEME_KEYS:
             attrname = 'install_' + key
--- a/lib-python/modified-2.7/distutils/command/install_egg_info.py
+++ b/lib-python/modified-2.7/distutils/command/install_egg_info.py
@@ -14,18 +14,38 @@
     description = "Install package's PKG-INFO metadata as an .egg-info file"
     user_options = [
         ('install-dir=', 'd', "directory to install to"),
+        ('install-layout', None, "custom installation layout"),
     ]
 
     def initialize_options(self):
         self.install_dir = None
+        self.install_layout = None
+        self.prefix_option = None
 
     def finalize_options(self):
         self.set_undefined_options('install_lib',('install_dir','install_dir'))
-        basename = "%s-%s-py%s.egg-info" % (
-            to_filename(safe_name(self.distribution.get_name())),
-            to_filename(safe_version(self.distribution.get_version())),
-            sys.version[:3]
-        )
+        self.set_undefined_options('install',('install_layout','install_layout'))
+        self.set_undefined_options('install',('prefix_option','prefix_option'))
+        if self.install_layout:
+            if not self.install_layout.lower() in ['deb', 'unix']:
+                raise DistutilsOptionError(
+                    "unknown value for --install-layout")
+            no_pyver = (self.install_layout.lower() == 'deb')
+        elif self.prefix_option:
+            no_pyver = False
+        else:
+            no_pyver = True
+        if no_pyver:
+            basename = "%s-%s.egg-info" % (
+                to_filename(safe_name(self.distribution.get_name())),
+                to_filename(safe_version(self.distribution.get_version()))
+                )
+        else:
+            basename = "%s-%s-py%s.egg-info" % (
+                to_filename(safe_name(self.distribution.get_name())),
+                to_filename(safe_version(self.distribution.get_version())),
+                sys.version[:3]
+                )
         self.target = os.path.join(self.install_dir, basename)
         self.outputs = [self.target]
 
--- a/lib-python/modified-2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/modified-2.7/distutils/sysconfig_pypy.py
@@ -46,11 +46,15 @@
     if standard_lib:
         raise DistutilsPlatformError(
             "calls to get_python_lib(standard_lib=1) cannot succeed")
+    is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
     if prefix is None:
         prefix = PREFIX
 
     # Installed layout:
-    path = os.path.join(prefix, 'lib', 'pypy', 'site-packages')
+    if is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__:
+        path = os.path.join(prefix, 'lib', 'pypy', 'dist-packages')
+    else:
+        path = os.path.join(prefix, 'lib', 'pypy', 'site-packages')
     if os.path.exists(path):
         return path
     else:
--- a/lib-python/modified-2.7/site.py
+++ b/lib-python/modified-2.7/site.py
@@ -12,13 +12,19 @@
 
 This will append site-specific paths to the module search path.  On
 Unix (including Mac OSX), it starts with sys.prefix and
-sys.exec_prefix (if different) and appends
-lib/python<version>/site-packages as well as lib/site-python.
+sys.exec_prefix (if different) and appends lib/pypy/dist-packages,
+lib/pypy<version>/dist-packages as well as lib/dist-pypy.
 On other platforms (such as Windows), it tries each of the
 prefixes directly, as well as with lib/site-packages appended.  The
 resulting directories, if they exist, are appended to sys.path, and
 also inspected for path configuration files.
 
+For Debian and derivatives, this sys.path is augmented with directories
+for packages distributed within the distribution. Local addons go
+into /usr/local/lib/python<version>/dist-packages, Debian addons
+install into /usr/{lib,share}/python<version>/dist-packages.
+/usr/lib/python<version>/site-packages is not used.
+
 A path configuration file is a file whose name has the form
 <package>.pth; its contents are additional directories (one per line)
 to be added to sys.path.  Non-existing directories (or
@@ -265,6 +271,13 @@
 
     if ENABLE_USER_SITE and os.path.isdir(user_site):
         addsitedir(user_site, known_paths)
+    if ENABLE_USER_SITE:
+        for dist_libdir in ("local/lib", "lib"):
+            user_site = os.path.join(USER_BASE, dist_libdir,
+                                     "pypy" + sys.version[:3],
+                                     "dist-packages")
+            if os.path.isdir(user_site):
+                addsitedir(user_site, known_paths)
     return known_paths
 
 def getsitepackages():
@@ -286,15 +299,17 @@
 
         if sys.platform in ('os2emx', 'riscos'):
             sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
-        elif is_pypy:
-            from distutils.sysconfig import get_python_lib
-            sitedir = get_python_lib(standard_lib=False, prefix=prefix)
-            sitepackages.append(sitedir)
         elif os.sep == '/':
+            sitepackages.append(os.path.join(prefix, "local/lib",
+                                        "pypy" + sys.version[:3],
+                                        "dist-packages"))
+            sitepackages.append(os.path.join(prefix, "lib",
+                                        "pypy",
+                                        "dist-packages"))
             sitepackages.append(os.path.join(prefix, "lib",
-                                        "python" + sys.version[:3],
-                                        "site-packages"))
-            sitepackages.append(os.path.join(prefix, "lib", "site-python"))
+                                        "pypy" + sys.version[:3],
+                                        "dist-packages"))
+            sitepackages.append(os.path.join(prefix, "lib", "dist-pypy"))
         else:
             sitepackages.append(prefix)
             sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
--- a/lib-python/modified-2.7/sysconfig.py
+++ b/lib-python/modified-2.7/sysconfig.py
@@ -7,12 +7,32 @@
 
 _INSTALL_SCHEMES = {
     'posix_prefix': {
-        'stdlib': '{base}/lib/python{py_version_short}',
-        'platstdlib': '{platbase}/lib/python{py_version_short}',
-        'purelib': '{base}/lib/python{py_version_short}/site-packages',
-        'platlib': '{platbase}/lib/python{py_version_short}/site-packages',
-        'include': '{base}/include/python{py_version_short}',
-        'platinclude': '{platbase}/include/python{py_version_short}',
+        'stdlib': '{base}/lib/pypy{py_version_short}',
+        'platstdlib': '{platbase}/lib/pypy{py_version_short}',
+        'purelib': '{base}/lib/pypy{py_version_short}/site-packages',
+        'platlib': '{platbase}/lib/pypy{py_version_short}/site-packages',
+        'include': '{base}/include/pypy{py_version_short}',
+        'platinclude': '{platbase}/include/pypy{py_version_short}',
+        'scripts': '{base}/bin',
+        'data': '{base}',
+        },
+    'posix_local': {
+        'stdlib': '{base}/local/lib/pypy{py_version_short}',
+        'platstdlib': '{platbase}/local/lib/pypy{py_version_short}',
+        'purelib': '{base}/local/lib/pypy{py_version_short}/dist-packages',
+        'platlib': '{platbase}/local/lib/pypy{py_version_short}/dist-packages',
+        'include': '{base}/local/include/pypy{py_version_short}',
+        'platinclude': '{platbase}/local/include/pypy{py_version_short}',
+        'scripts': '{base}/local/bin',
+        'data': '{base}/local',
+        },
+    'deb_system': {
+        'stdlib': '{base}/lib/pypy/lib-python',
+        'platstdlib': '{platbase}/lib/pypy/lib-python',
+        'purelib': '{base}/lib/pypy/dist-packages',
+        'platlib': '{platbase}/lib/pypy/dist-packages',
+        'include': '{base}/include/pypy',
+        'platinclude': '{platbase}/include/pypy',
         'scripts': '{base}/bin',
         'data': '{base}',
         },
@@ -75,11 +95,11 @@
         'data'   : '{userbase}',
         },
     'posix_user': {
-        'stdlib': '{userbase}/lib/python{py_version_short}',
-        'platstdlib': '{userbase}/lib/python{py_version_short}',
-        'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
-        'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
-        'include': '{userbase}/include/python{py_version_short}',
+        'stdlib': '{userbase}/lib/pypy{py_version_short}',
+        'platstdlib': '{userbase}/lib/pypy{py_version_short}',
+        'purelib': '{userbase}/lib/pypy{py_version_short}/site-packages',
+        'platlib': '{userbase}/lib/pypy{py_version_short}/site-packages',
+        'include': '{userbase}/include/pypy{py_version_short}',
         'scripts': '{userbase}/bin',
         'data'   : '{userbase}',
         },
@@ -137,9 +157,9 @@
 _PYTHON_BUILD = is_python_build()
 
 if _PYTHON_BUILD:
-    for scheme in ('posix_prefix', 'posix_home'):
-        _INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/Include'
-        _INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}'
+    for scheme in ('posix_prefix', 'posix_home', 'posix_local', 'deb_system'):
+        _INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/include'
+        _INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}/include'
 
 def _subst_vars(s, local_vars):
     try:
@@ -171,7 +191,7 @@
 
 def _get_default_scheme():
     if '__pypy__' in sys.builtin_module_names:
-        return 'pypy'
+        return 'posix_local'
     elif os.name == 'posix':
         # the default scheme for posix is posix_prefix
         return 'posix_prefix'
@@ -253,7 +273,7 @@
         else:
             inc_dir = _PROJECT_BASE
     else:
-        inc_dir = get_path('platinclude')
+        inc_dir = get_path('platinclude', 'deb_system')
     return os.path.join(inc_dir, 'pyconfig.h')
 
 def get_scheme_names():
--- a/lib-python/modified-2.7/test/test_import.py
+++ b/lib-python/modified-2.7/test/test_import.py
@@ -259,7 +259,7 @@
         with check_warnings(('', ImportWarning)):
             # Just a random non-package directory we always expect to be
             # somewhere in sys.path...
-            self.assertRaises(ImportError, __import__, "site-packages")
+            self.assertRaises(ImportError, __import__, "dist-packages")
 
     def test_import_by_filename(self):
         path = os.path.abspath(TESTFN)
--- a/lib-python/modified-2.7/test/test_site.py
+++ b/lib-python/modified-2.7/test/test_site.py
@@ -169,13 +169,14 @@
             wanted = os.path.join('xoxo', 'Lib', 'site-packages')
             self.assertEqual(dirs[0], wanted)
         elif '__pypy__' in sys.builtin_module_names:
-            self.assertEquals(len(dirs), 1)
-            wanted = os.path.join('xoxo', 'site-packages')
+            self.assertEquals(len(dirs), 4)
+            wanted = os.path.join('xoxo', 'local', 'lib',
+                                  'pypy' + sys.version[:3], 'dist-packages')
             self.assertEquals(dirs[0], wanted)
         elif os.sep == '/':
             self.assertEqual(len(dirs), 2)
             wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
-                                  'site-packages')
+                                  'dist-packages')
             self.assertEqual(dirs[0], wanted)
             wanted = os.path.join('xoxo', 'lib', 'site-python')
             self.assertEqual(dirs[1], wanted)
--- a/lib-python/modified-2.7/test/test_sysconfig.py
+++ b/lib-python/modified-2.7/test/test_sysconfig.py
@@ -244,8 +244,8 @@
         self.assertTrue(os.path.isfile(config_h), config_h)
 
     def test_get_scheme_names(self):
-        wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
-                  'posix_home', 'posix_prefix', 'posix_user', 'pypy')
+        wanted = ('deb_system', 'nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
+                  'posix_home', 'posix_local', 'posix_prefix', 'posix_user', 'pypy')
         self.assertEqual(get_scheme_names(), wanted)
 
     def test_symlink(self):
