Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38e3d51

Browse files
author
Tarek Ziadé
committed
Merged revisions 70017 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70017 | tarek.ziade | 2009-02-27 13:53:34 +0100 (Fri, 27 Feb 2009) | 1 line Issue #5052: make Distutils compatible with 2.3 again. ........
1 parent 89fc2b7 commit 38e3d51

7 files changed

Lines changed: 186 additions & 38 deletions

File tree

Lib/distutils/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ The Distutils-SIG web page is also a good starting point:
88

99
http://www.python.org/sigs/distutils-sig/
1010

11+
WARNING : Distutils must remain compatible with 2.3
12+
1113
$Id$

Lib/distutils/command/build_ext.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
__revision__ = "$Id$"
88

99
import sys, os, re
10-
from site import USER_BASE
1110
from distutils.core import Command
1211
from distutils.errors import *
1312
from distutils.sysconfig import customize_compiler, get_python_version
@@ -16,6 +15,14 @@
1615
from distutils.util import get_platform
1716
from distutils import log
1817

18+
# this keeps compatibility from 2.3 to 2.5
19+
if sys.version < "2.6":
20+
USER_BASE = None
21+
HAS_USER_SITE = False
22+
else:
23+
from site import USER_BASE
24+
HAS_USER_SITE = True
25+
1926
if os.name == 'nt':
2027
from distutils.msvccompiler import get_build_version
2128
MSVC_VERSION = int(get_build_version())
@@ -91,11 +98,14 @@ class build_ext(Command):
9198
"list of SWIG command line options"),
9299
('swig=', None,
93100
"path to the SWIG executable"),
94-
('user', None,
95-
"add user include, library and rpath"),
96101
]
97102

98-
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user']
103+
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
104+
105+
if HAS_USER_SITE:
106+
user_options.append(('user', None,
107+
"add user include, library and rpath"))
108+
boolean_options.append('user')
99109

100110
help_options = [
101111
('help-compiler', None,

Lib/distutils/command/install.py

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@
1515
from distutils.util import convert_path, subst_vars, change_root
1616
from distutils.util import get_platform
1717
from distutils.errors import DistutilsOptionError
18-
from site import USER_BASE
19-
from site import USER_SITE
2018

19+
# this keeps compatibility from 2.3 to 2.5
20+
if sys.version < "2.6":
21+
USER_BASE = None
22+
USER_SITE = None
23+
HAS_USER_SITE = False
24+
else:
25+
from site import USER_BASE
26+
from site import USER_SITE
27+
HAS_USER_SITE = True
2128

2229
if sys.version < "2.2":
2330
WINDOWS_SCHEME = {
@@ -51,50 +58,57 @@
5158
'scripts': '$base/bin',
5259
'data' : '$base',
5360
},
54-
'unix_user': {
55-
'purelib': '$usersite',
56-
'platlib': '$usersite',
57-
'headers': '$userbase/include/python$py_version_short/$dist_name',
58-
'scripts': '$userbase/bin',
59-
'data' : '$userbase',
60-
},
6161
'nt': WINDOWS_SCHEME,
62-
'nt_user': {
63-
'purelib': '$usersite',
64-
'platlib': '$usersite',
65-
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
66-
'scripts': '$userbase/Scripts',
67-
'data' : '$userbase',
68-
},
6962
'mac': {
7063
'purelib': '$base/Lib/site-packages',
7164
'platlib': '$base/Lib/site-packages',
7265
'headers': '$base/Include/$dist_name',
7366
'scripts': '$base/Scripts',
7467
'data' : '$base',
7568
},
76-
'mac_user': {
77-
'purelib': '$usersite',
78-
'platlib': '$usersite',
79-
'headers': '$userbase/$py_version_short/include/$dist_name',
80-
'scripts': '$userbase/bin',
81-
'data' : '$userbase',
82-
},
69+
8370
'os2': {
8471
'purelib': '$base/Lib/site-packages',
8572
'platlib': '$base/Lib/site-packages',
8673
'headers': '$base/Include/$dist_name',
8774
'scripts': '$base/Scripts',
8875
'data' : '$base',
8976
},
90-
'os2_home': {
77+
}
78+
79+
# user site schemes
80+
if HAS_USER_SITE:
81+
INSTALL_SCHEMES['nt_user'] = {
82+
'purelib': '$usersite',
83+
'platlib': '$usersite',
84+
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
85+
'scripts': '$userbase/Scripts',
86+
'data' : '$userbase',
87+
}
88+
89+
INSTALL_SCHEMES['unix_user'] = {
9190
'purelib': '$usersite',
9291
'platlib': '$usersite',
9392
'headers': '$userbase/include/python$py_version_short/$dist_name',
9493
'scripts': '$userbase/bin',
9594
'data' : '$userbase',
96-
},
97-
}
95+
}
96+
97+
INSTALL_SCHEMES['mac_user'] = {
98+
'purelib': '$usersite',
99+
'platlib': '$usersite',
100+
'headers': '$userbase/$py_version_short/include/$dist_name',
101+
'scripts': '$userbase/bin',
102+
'data' : '$userbase',
103+
}
104+
105+
INSTALL_SCHEMES['os2_home'] = {
106+
'purelib': '$usersite',
107+
'platlib': '$usersite',
108+
'headers': '$userbase/include/python$py_version_short/$dist_name',
109+
'scripts': '$userbase/bin',
110+
'data' : '$userbase',
111+
}
98112

99113
# The keys to an installation scheme; if any new types of files are to be
100114
# installed, be sure to add an entry to every installation scheme above,
@@ -114,8 +128,6 @@ class install (Command):
114128
"(Unix only) prefix for platform-specific files"),
115129
('home=', None,
116130
"(Unix only) home directory to install under"),
117-
('user', None,
118-
"install in user site-package '%s'" % USER_SITE),
119131

120132
# Or, just set the base director(y|ies)
121133
('install-base=', None,
@@ -167,7 +179,13 @@ class install (Command):
167179
"filename in which to record list of installed files"),
168180
]
169181

170-
boolean_options = ['compile', 'force', 'skip-build', 'user']
182+
boolean_options = ['compile', 'force', 'skip-build']
183+
184+
if HAS_USER_SITE:
185+
user_options.append(('user', None,
186+
"install in user site-package '%s'" % USER_SITE))
187+
boolean_options.append('user')
188+
171189
negative_opt = {'no-compile' : 'compile'}
172190

173191

@@ -319,9 +337,12 @@ def finalize_options(self):
319337
'prefix': prefix,
320338
'sys_exec_prefix': exec_prefix,
321339
'exec_prefix': exec_prefix,
322-
'userbase': self.install_userbase,
323-
'usersite': self.install_usersite,
324340
}
341+
342+
if HAS_USER_SITE:
343+
self.config_vars['userbase'] = self.install_userbase
344+
self.config_vars['usersite'] = self.install_usersite
345+
325346
self.expand_basedirs()
326347

327348
self.dump_dirs("post-expand_basedirs()")

Lib/distutils/command/upload.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from distutils.core import PyPIRCCommand
77
from distutils.spawn import spawn
88
from distutils import log
9-
from hashlib import md5
9+
import sys
1010
import os, io
1111
import socket
1212
import platform
@@ -15,6 +15,12 @@
1515
import base64
1616
import urllib.parse
1717

18+
# this keeps compatibility for 2.3 and 2.4
19+
if sys.version < "2.5":
20+
from md5 import md5
21+
else:
22+
from hashlib import md5
23+
1824
class upload(PyPIRCCommand):
1925

2026
description = "upload binary package to PyPI"

Lib/distutils/tests/test_build_ext.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ class BuildExtTestCase(TempdirManager, unittest.TestCase):
2424
def setUp(self):
2525
# Create a simple test environment
2626
# Note that we're making changes to sys.path
27-
TempdirManager.setUp(self)
27+
super(BuildExtTestCase, self).setUp()
2828
self.tmp_dir = self.mkdtemp()
2929
self.sys_path = sys.path[:]
3030
sys.path.append(self.tmp_dir)
3131
shutil.copy(_get_source_filename(), self.tmp_dir)
32+
if sys.version > "2.6":
33+
import site
34+
self.old_user_base = site.USER_BASE
35+
site.USER_BASE = self.mkdtemp()
36+
from distutils.command import build_ext
37+
build_ext.USER_BASE = site.USER_BASE
3238

3339
def test_build_ext(self):
3440
global ALREADY_TESTED
@@ -76,7 +82,12 @@ def tearDown(self):
7682
# Get everything back to normal
7783
support.unload('xx')
7884
sys.path = self.sys_path
79-
TempdirManager.tearDown(self)
85+
if sys.version > "2.6":
86+
import site
87+
site.USER_BASE = self.old_user_base
88+
from distutils.command import build_ext
89+
build_ext.USER_BASE = self.old_user_base
90+
super(BuildExtTestCase, self).tearDown()
8091

8192
def test_solaris_enable_shared(self):
8293
dist = Distribution({'name': 'xx'})
@@ -99,6 +110,37 @@ def test_solaris_enable_shared(self):
99110
# make sur we get some lobrary dirs under solaris
100111
self.assert_(len(cmd.library_dirs) > 0)
101112

113+
def test_user_site(self):
114+
# site.USER_SITE was introduced in 2.6
115+
if sys.version < '2.6':
116+
return
117+
118+
import site
119+
dist = Distribution({'name': 'xx'})
120+
cmd = build_ext(dist)
121+
122+
# making sure the suer option is there
123+
options = [name for name, short, lable in
124+
cmd.user_options]
125+
self.assert_('user' in options)
126+
127+
# setting a value
128+
cmd.user = 1
129+
130+
# setting user based lib and include
131+
lib = os.path.join(site.USER_BASE, 'lib')
132+
incl = os.path.join(site.USER_BASE, 'include')
133+
os.mkdir(lib)
134+
os.mkdir(incl)
135+
136+
# let's run finalize
137+
cmd.ensure_finalized()
138+
139+
# see if include_dirs and library_dirs
140+
# were set
141+
self.assert_(lib in cmd.library_dirs)
142+
self.assert_(incl in cmd.include_dirs)
143+
102144
def test_suite():
103145
src = _get_source_filename()
104146
if not os.path.exists(src):

Lib/distutils/tests/test_install.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
"""Tests for distutils.command.install."""
22

33
import os
4+
import os.path
5+
import sys
46
import unittest
7+
import site
58

69
from distutils.command.install import install
10+
from distutils.command import install as install_module
11+
from distutils.command.install import INSTALL_SCHEMES
712
from distutils.core import Distribution
813

914
from distutils.tests import support
@@ -47,6 +52,65 @@ def check_path(got, expected):
4752
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
4853
check_path(cmd.install_data, destination)
4954

55+
def test_user_site(self):
56+
# site.USER_SITE was introduced in 2.6
57+
if sys.version < '2.6':
58+
return
59+
60+
# preparing the environement for the test
61+
self.old_user_base = site.USER_BASE
62+
self.old_user_site = site.USER_SITE
63+
self.tmpdir = self.mkdtemp()
64+
self.user_base = os.path.join(self.tmpdir, 'B')
65+
self.user_site = os.path.join(self.tmpdir, 'S')
66+
site.USER_BASE = self.user_base
67+
site.USER_SITE = self.user_site
68+
install_module.USER_BASE = self.user_base
69+
install_module.USER_SITE = self.user_site
70+
71+
def _expanduser(path):
72+
return self.tmpdir
73+
self.old_expand = os.path.expanduser
74+
os.path.expanduser = _expanduser
75+
76+
try:
77+
# this is the actual test
78+
self._test_user_site()
79+
finally:
80+
site.USER_BASE = self.old_user_base
81+
site.USER_SITE = self.old_user_site
82+
install_module.USER_BASE = self.old_user_base
83+
install_module.USER_SITE = self.old_user_site
84+
os.path.expanduser = self.old_expand
85+
86+
def _test_user_site(self):
87+
for key in ('nt_user', 'unix_user', 'os2_home'):
88+
self.assert_(key in INSTALL_SCHEMES)
89+
90+
dist = Distribution({'name': 'xx'})
91+
cmd = install(dist)
92+
93+
# making sure the user option is there
94+
options = [name for name, short, lable in
95+
cmd.user_options]
96+
self.assert_('user' in options)
97+
98+
# setting a value
99+
cmd.user = 1
100+
101+
# user base and site shouldn't be created yet
102+
self.assert_(not os.path.exists(self.user_base))
103+
self.assert_(not os.path.exists(self.user_site))
104+
105+
# let's run finalize
106+
cmd.ensure_finalized()
107+
108+
# now they should
109+
self.assert_(os.path.exists(self.user_base))
110+
self.assert_(os.path.exists(self.user_site))
111+
112+
self.assert_('userbase' in cmd.config_vars)
113+
self.assert_('usersite' in cmd.config_vars)
50114

51115
def test_suite():
52116
return unittest.makeSuite(InstallTestCase)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ Core and Builtins
172172

173173
Library
174174
-------
175+
176+
- Issue #5052: make Distutils compatible with 2.3 again.
177+
175178
- Issue #5316: Fixed buildbot failures introduced by multiple inheritance
176179
in Distutils tests.
177180

0 commit comments

Comments
 (0)