Commit 8ac6d0fd authored by Tarek Ziadé's avatar Tarek Ziadé

Issue #5052: make Distutils compatible with 2.3 again.

parent 9daeb929
...@@ -8,4 +8,6 @@ The Distutils-SIG web page is also a good starting point: ...@@ -8,4 +8,6 @@ The Distutils-SIG web page is also a good starting point:
http://www.python.org/sigs/distutils-sig/ http://www.python.org/sigs/distutils-sig/
WARNING : Distutils must remain compatible with 2.3
$Id$ $Id$
...@@ -8,7 +8,6 @@ __revision__ = "$Id$" ...@@ -8,7 +8,6 @@ __revision__ = "$Id$"
import sys, os, string, re import sys, os, string, re
from types import * from types import *
from site import USER_BASE
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.sysconfig import customize_compiler, get_python_version from distutils.sysconfig import customize_compiler, get_python_version
...@@ -17,6 +16,14 @@ from distutils.extension import Extension ...@@ -17,6 +16,14 @@ from distutils.extension import Extension
from distutils.util import get_platform from distutils.util import get_platform
from distutils import log from distutils import log
# this keeps compatibility from 2.3 to 2.5
if sys.version < "2.6":
USER_BASE = None
HAS_USER_SITE = False
else:
from site import USER_BASE
HAS_USER_SITE = True
if os.name == 'nt': if os.name == 'nt':
from distutils.msvccompiler import get_build_version from distutils.msvccompiler import get_build_version
MSVC_VERSION = int(get_build_version()) MSVC_VERSION = int(get_build_version())
...@@ -92,11 +99,14 @@ class build_ext (Command): ...@@ -92,11 +99,14 @@ class build_ext (Command):
"list of SWIG command line options"), "list of SWIG command line options"),
('swig=', None, ('swig=', None,
"path to the SWIG executable"), "path to the SWIG executable"),
('user', None,
"add user include, library and rpath"),
] ]
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user'] boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
if HAS_USER_SITE:
user_options.append(('user', None,
"add user include, library and rpath"))
boolean_options.append('user')
help_options = [ help_options = [
('help-compiler', None, ('help-compiler', None,
......
...@@ -16,9 +16,16 @@ from distutils.file_util import write_file ...@@ -16,9 +16,16 @@ from distutils.file_util import write_file
from distutils.util import convert_path, subst_vars, change_root from distutils.util import convert_path, subst_vars, change_root
from distutils.util import get_platform from distutils.util import get_platform
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
from site import USER_BASE
from site import USER_SITE
# this keeps compatibility from 2.3 to 2.5
if sys.version < "2.6":
USER_BASE = None
USER_SITE = None
HAS_USER_SITE = False
else:
from site import USER_BASE
from site import USER_SITE
HAS_USER_SITE = True
if sys.version < "2.2": if sys.version < "2.2":
WINDOWS_SCHEME = { WINDOWS_SCHEME = {
...@@ -52,21 +59,7 @@ INSTALL_SCHEMES = { ...@@ -52,21 +59,7 @@ INSTALL_SCHEMES = {
'scripts': '$base/bin', 'scripts': '$base/bin',
'data' : '$base', 'data' : '$base',
}, },
'unix_user': {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/include/python$py_version_short/$dist_name',
'scripts': '$userbase/bin',
'data' : '$userbase',
},
'nt': WINDOWS_SCHEME, 'nt': WINDOWS_SCHEME,
'nt_user': {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
'scripts': '$userbase/Scripts',
'data' : '$userbase',
},
'mac': { 'mac': {
'purelib': '$base/Lib/site-packages', 'purelib': '$base/Lib/site-packages',
'platlib': '$base/Lib/site-packages', 'platlib': '$base/Lib/site-packages',
...@@ -74,13 +67,7 @@ INSTALL_SCHEMES = { ...@@ -74,13 +67,7 @@ INSTALL_SCHEMES = {
'scripts': '$base/Scripts', 'scripts': '$base/Scripts',
'data' : '$base', 'data' : '$base',
}, },
'mac_user': {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/$py_version_short/include/$dist_name',
'scripts': '$userbase/bin',
'data' : '$userbase',
},
'os2': { 'os2': {
'purelib': '$base/Lib/site-packages', 'purelib': '$base/Lib/site-packages',
'platlib': '$base/Lib/site-packages', 'platlib': '$base/Lib/site-packages',
...@@ -88,13 +75,40 @@ INSTALL_SCHEMES = { ...@@ -88,13 +75,40 @@ INSTALL_SCHEMES = {
'scripts': '$base/Scripts', 'scripts': '$base/Scripts',
'data' : '$base', 'data' : '$base',
}, },
'os2_home': { }
# user site schemes
if HAS_USER_SITE:
INSTALL_SCHEMES['nt_user'] = {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
'scripts': '$userbase/Scripts',
'data' : '$userbase',
}
INSTALL_SCHEMES['unix_user'] = {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/include/python$py_version_short/$dist_name',
'scripts': '$userbase/bin',
'data' : '$userbase',
}
INSTALL_SCHEMES['mac_user'] = {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/$py_version_short/include/$dist_name',
'scripts': '$userbase/bin',
'data' : '$userbase',
}
INSTALL_SCHEMES['os2_home'] = {
'purelib': '$usersite', 'purelib': '$usersite',
'platlib': '$usersite', 'platlib': '$usersite',
'headers': '$userbase/include/python$py_version_short/$dist_name', 'headers': '$userbase/include/python$py_version_short/$dist_name',
'scripts': '$userbase/bin', 'scripts': '$userbase/bin',
'data' : '$userbase', 'data' : '$userbase',
},
} }
# The keys to an installation scheme; if any new types of files are to be # The keys to an installation scheme; if any new types of files are to be
...@@ -115,8 +129,6 @@ class install (Command): ...@@ -115,8 +129,6 @@ class install (Command):
"(Unix only) prefix for platform-specific files"), "(Unix only) prefix for platform-specific files"),
('home=', None, ('home=', None,
"(Unix only) home directory to install under"), "(Unix only) home directory to install under"),
('user', None,
"install in user site-package '%s'" % USER_SITE),
# Or, just set the base director(y|ies) # Or, just set the base director(y|ies)
('install-base=', None, ('install-base=', None,
...@@ -168,7 +180,13 @@ class install (Command): ...@@ -168,7 +180,13 @@ class install (Command):
"filename in which to record list of installed files"), "filename in which to record list of installed files"),
] ]
boolean_options = ['compile', 'force', 'skip-build', 'user'] boolean_options = ['compile', 'force', 'skip-build']
if HAS_USER_SITE:
user_options.append(('user', None,
"install in user site-package '%s'" % USER_SITE))
boolean_options.append('user')
negative_opt = {'no-compile' : 'compile'} negative_opt = {'no-compile' : 'compile'}
...@@ -320,9 +338,12 @@ class install (Command): ...@@ -320,9 +338,12 @@ class install (Command):
'prefix': prefix, 'prefix': prefix,
'sys_exec_prefix': exec_prefix, 'sys_exec_prefix': exec_prefix,
'exec_prefix': exec_prefix, 'exec_prefix': exec_prefix,
'userbase': self.install_userbase,
'usersite': self.install_usersite,
} }
if HAS_USER_SITE:
self.config_vars['userbase'] = self.install_userbase
self.config_vars['usersite'] = self.install_usersite
self.expand_basedirs() self.expand_basedirs()
self.dump_dirs("post-expand_basedirs()") self.dump_dirs("post-expand_basedirs()")
......
...@@ -6,7 +6,7 @@ from distutils.errors import * ...@@ -6,7 +6,7 @@ from distutils.errors import *
from distutils.core import PyPIRCCommand from distutils.core import PyPIRCCommand
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils import log from distutils import log
from hashlib import md5 import sys
import os import os
import socket import socket
import platform import platform
...@@ -16,6 +16,11 @@ import urlparse ...@@ -16,6 +16,11 @@ import urlparse
import cStringIO as StringIO import cStringIO as StringIO
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
# this keeps compatibility for 2.3 and 2.4
if sys.version < "2.5":
from md5 import md5
else:
from hashlib import md5
class upload(PyPIRCCommand): class upload(PyPIRCCommand):
......
...@@ -24,11 +24,17 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase): ...@@ -24,11 +24,17 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase):
def setUp(self): def setUp(self):
# Create a simple test environment # Create a simple test environment
# Note that we're making changes to sys.path # Note that we're making changes to sys.path
support.TempdirManager.setUp(self) super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp() self.tmp_dir = self.mkdtemp()
self.sys_path = sys.path[:] self.sys_path = sys.path[:]
sys.path.append(self.tmp_dir) sys.path.append(self.tmp_dir)
shutil.copy(_get_source_filename(), self.tmp_dir) shutil.copy(_get_source_filename(), self.tmp_dir)
if sys.version > "2.6":
import site
self.old_user_base = site.USER_BASE
site.USER_BASE = self.mkdtemp()
from distutils.command import build_ext
build_ext.USER_BASE = site.USER_BASE
def test_build_ext(self): def test_build_ext(self):
global ALREADY_TESTED global ALREADY_TESTED
...@@ -76,7 +82,13 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase): ...@@ -76,7 +82,13 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase):
# Get everything back to normal # Get everything back to normal
test_support.unload('xx') test_support.unload('xx')
sys.path = self.sys_path sys.path = self.sys_path
support.TempdirManager.tearDown(self) if sys.version > "2.6":
import site
site.USER_BASE = self.old_user_base
from distutils.command import build_ext
build_ext.USER_BASE = self.old_user_base
super(BuildExtTestCase, self).tearDown()
def test_solaris_enable_shared(self): def test_solaris_enable_shared(self):
dist = Distribution({'name': 'xx'}) dist = Distribution({'name': 'xx'})
...@@ -99,6 +111,37 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase): ...@@ -99,6 +111,37 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase):
# make sur we get some lobrary dirs under solaris # make sur we get some lobrary dirs under solaris
self.assert_(len(cmd.library_dirs) > 0) self.assert_(len(cmd.library_dirs) > 0)
def test_user_site(self):
# site.USER_SITE was introduced in 2.6
if sys.version < '2.6':
return
import site
dist = Distribution({'name': 'xx'})
cmd = build_ext(dist)
# making sure the suer option is there
options = [name for name, short, lable in
cmd.user_options]
self.assert_('user' in options)
# setting a value
cmd.user = 1
# setting user based lib and include
lib = os.path.join(site.USER_BASE, 'lib')
incl = os.path.join(site.USER_BASE, 'include')
os.mkdir(lib)
os.mkdir(incl)
# let's run finalize
cmd.ensure_finalized()
# see if include_dirs and library_dirs
# were set
self.assert_(lib in cmd.library_dirs)
self.assert_(incl in cmd.include_dirs)
def test_suite(): def test_suite():
src = _get_source_filename() src = _get_source_filename()
if not os.path.exists(src): if not os.path.exists(src):
......
"""Tests for distutils.command.install.""" """Tests for distutils.command.install."""
import os import os
import os.path
import sys
import unittest import unittest
import site
from distutils.command.install import install from distutils.command.install import install
from distutils.command import install as install_module
from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Distribution from distutils.core import Distribution
from distutils.tests import support from distutils.tests import support
...@@ -47,6 +52,65 @@ class InstallTestCase(support.TempdirManager, unittest.TestCase): ...@@ -47,6 +52,65 @@ class InstallTestCase(support.TempdirManager, unittest.TestCase):
check_path(cmd.install_scripts, os.path.join(destination, "bin")) check_path(cmd.install_scripts, os.path.join(destination, "bin"))
check_path(cmd.install_data, destination) check_path(cmd.install_data, destination)
def test_user_site(self):
# site.USER_SITE was introduced in 2.6
if sys.version < '2.6':
return
# preparing the environement for the test
self.old_user_base = site.USER_BASE
self.old_user_site = site.USER_SITE
self.tmpdir = self.mkdtemp()
self.user_base = os.path.join(self.tmpdir, 'B')
self.user_site = os.path.join(self.tmpdir, 'S')
site.USER_BASE = self.user_base
site.USER_SITE = self.user_site
install_module.USER_BASE = self.user_base
install_module.USER_SITE = self.user_site
def _expanduser(path):
return self.tmpdir
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
try:
# this is the actual test
self._test_user_site()
finally:
site.USER_BASE = self.old_user_base
site.USER_SITE = self.old_user_site
install_module.USER_BASE = self.old_user_base
install_module.USER_SITE = self.old_user_site
os.path.expanduser = self.old_expand
def _test_user_site(self):
for key in ('nt_user', 'unix_user', 'os2_home'):
self.assert_(key in INSTALL_SCHEMES)
dist = Distribution({'name': 'xx'})
cmd = install(dist)
# making sure the user option is there
options = [name for name, short, lable in
cmd.user_options]
self.assert_('user' in options)
# setting a value
cmd.user = 1
# user base and site shouldn't be created yet
self.assert_(not os.path.exists(self.user_base))
self.assert_(not os.path.exists(self.user_site))
# let's run finalize
cmd.ensure_finalized()
# now they should
self.assert_(os.path.exists(self.user_base))
self.assert_(os.path.exists(self.user_site))
self.assert_('userbase' in cmd.config_vars)
self.assert_('usersite' in cmd.config_vars)
def test_suite(): def test_suite():
return unittest.makeSuite(InstallTestCase) return unittest.makeSuite(InstallTestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment