Skip to content

Commit cc48838

Browse files
committed
Update/backport distutils with version from CPython-2.7.10
1 parent 7daeef6 commit cc48838

28 files changed

+550
-681
lines changed

Lib/distutils/ccompiler.py

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Contains CCompiler, an abstract base class that defines the interface
44
for the Distutils compiler abstraction model."""
55

6-
__revision__ = "$Id: ccompiler.py 86238 2010-11-06 04:06:18Z eric.araujo $"
6+
__revision__ = "$Id$"
77

88
import sys
99
import os
@@ -17,58 +17,8 @@
1717
from distutils.dep_util import newer_group
1818
from distutils.util import split_quoted, execute
1919
from distutils import log
20-
21-
_sysconfig = __import__('sysconfig')
22-
23-
def customize_compiler(compiler):
24-
"""Do any platform-specific customization of a CCompiler instance.
25-
26-
Mainly needed on Unix, so we can plug in the information that
27-
varies across Unices and is stored in Python's Makefile.
28-
"""
29-
if compiler.compiler_type == "unix":
30-
(cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
31-
_sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
32-
'CCSHARED', 'LDSHARED', 'SO', 'AR',
33-
'ARFLAGS')
34-
35-
if 'CC' in os.environ:
36-
cc = os.environ['CC']
37-
if 'CXX' in os.environ:
38-
cxx = os.environ['CXX']
39-
if 'LDSHARED' in os.environ:
40-
ldshared = os.environ['LDSHARED']
41-
if 'CPP' in os.environ:
42-
cpp = os.environ['CPP']
43-
else:
44-
cpp = cc + " -E" # not always
45-
if 'LDFLAGS' in os.environ:
46-
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
47-
if 'CFLAGS' in os.environ:
48-
cflags = opt + ' ' + os.environ['CFLAGS']
49-
ldshared = ldshared + ' ' + os.environ['CFLAGS']
50-
if 'CPPFLAGS' in os.environ:
51-
cpp = cpp + ' ' + os.environ['CPPFLAGS']
52-
cflags = cflags + ' ' + os.environ['CPPFLAGS']
53-
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
54-
if 'AR' in os.environ:
55-
ar = os.environ['AR']
56-
if 'ARFLAGS' in os.environ:
57-
archiver = ar + ' ' + os.environ['ARFLAGS']
58-
else:
59-
archiver = ar + ' ' + ar_flags
60-
61-
cc_cmd = cc + ' ' + cflags
62-
compiler.set_executables(
63-
preprocessor=cpp,
64-
compiler=cc_cmd,
65-
compiler_so=cc_cmd + ' ' + ccshared,
66-
compiler_cxx=cxx,
67-
linker_so=ldshared,
68-
linker_exe=cc,
69-
archiver=archiver)
70-
71-
compiler.shared_lib_extension = so_ext
20+
# following import is for backward compatibility
21+
from distutils.sysconfig import customize_compiler
7222

7323
class CCompiler:
7424
"""Abstract base class to define the interface that must be implemented

Lib/distutils/command/bdist.py

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@
33
Implements the Distutils 'bdist' command (create a built [binary]
44
distribution)."""
55

6-
# This module should be kept compatible with Python 2.1.
7-
8-
__revision__ = "$Id: bdist.py 62197 2008-04-07 01:53:39Z mark.hammond $"
6+
__revision__ = "$Id$"
97

108
import os
11-
from types import *
12-
from distutils.core import Command
13-
from distutils.errors import *
9+
1410
from distutils.util import get_platform
11+
from distutils.core import Command
12+
from distutils.errors import DistutilsPlatformError, DistutilsOptionError
1513

1614

17-
def show_formats ():
15+
def show_formats():
1816
"""Print list of available formats (arguments to "--format" option).
1917
"""
2018
from distutils.fancy_getopt import FancyGetopt
21-
formats=[]
19+
formats = []
2220
for format in bdist.format_commands:
2321
formats.append(("formats=" + format, None,
2422
bdist.format_command[format][1]))
2523
pretty_printer = FancyGetopt(formats)
2624
pretty_printer.print_help("List of available distribution formats:")
2725

2826

29-
class bdist (Command):
27+
class bdist(Command):
3028

3129
description = "create a built (binary) distribution"
3230

@@ -42,6 +40,12 @@ class bdist (Command):
4240
"[default: dist]"),
4341
('skip-build', None,
4442
"skip rebuilding everything (for testing/debugging)"),
43+
('owner=', 'u',
44+
"Owner name used when creating a tar file"
45+
" [default: current user]"),
46+
('group=', 'g',
47+
"Group name used when creating a tar file"
48+
" [default: current group]"),
4549
]
4650

4751
boolean_options = ['skip-build']
@@ -52,50 +56,42 @@ class bdist (Command):
5256
]
5357

5458
# The following commands do not take a format option from bdist
55-
no_format_option = ('bdist_rpm',
56-
#'bdist_sdux', 'bdist_pkgtool'
57-
)
59+
no_format_option = ('bdist_rpm',)
5860

5961
# This won't do in reality: will need to distinguish RPM-ish Linux,
6062
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
61-
default_format = { 'posix': 'gztar',
62-
'java': 'gztar',
63-
'nt': 'zip',
64-
'os2': 'zip', }
63+
default_format = {'posix': 'gztar',
64+
'java': 'gztar',
65+
'nt': 'zip',
66+
'os2': 'zip'}
6567

6668
# Establish the preferred order (for the --help-formats option).
6769
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
68-
'wininst', 'zip',
69-
#'pkgtool', 'sdux'
70-
]
70+
'wininst', 'zip', 'msi']
7171

7272
# And the real information.
73-
format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
74-
'zip': ('bdist_dumb', "ZIP file"),
75-
'gztar': ('bdist_dumb', "gzip'ed tar file"),
76-
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
77-
'ztar': ('bdist_dumb', "compressed tar file"),
78-
'tar': ('bdist_dumb', "tar file"),
79-
'wininst': ('bdist_wininst',
80-
"Windows executable installer"),
81-
'zip': ('bdist_dumb', "ZIP file"),
82-
#'pkgtool': ('bdist_pkgtool',
83-
# "Solaris pkgtool distribution"),
84-
#'sdux': ('bdist_sdux', "HP-UX swinstall depot"),
73+
format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
74+
'gztar': ('bdist_dumb', "gzip'ed tar file"),
75+
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
76+
'ztar': ('bdist_dumb', "compressed tar file"),
77+
'tar': ('bdist_dumb', "tar file"),
78+
'wininst': ('bdist_wininst',
79+
"Windows executable installer"),
80+
'zip': ('bdist_dumb', "ZIP file"),
81+
'msi': ('bdist_msi', "Microsoft Installer")
8582
}
8683

8784

88-
def initialize_options (self):
85+
def initialize_options(self):
8986
self.bdist_base = None
9087
self.plat_name = None
9188
self.formats = None
9289
self.dist_dir = None
9390
self.skip_build = 0
91+
self.group = None
92+
self.owner = None
9493

95-
# initialize_options()
96-
97-
98-
def finalize_options (self):
94+
def finalize_options(self):
9995
# have to finalize 'plat_name' before 'bdist_base'
10096
if self.plat_name is None:
10197
if self.skip_build:
@@ -123,10 +119,7 @@ def finalize_options (self):
123119
if self.dist_dir is None:
124120
self.dist_dir = "dist"
125121

126-
# finalize_options()
127-
128-
def run (self):
129-
122+
def run(self):
130123
# Figure out which sub-commands we need to run.
131124
commands = []
132125
for format in self.formats:
@@ -142,12 +135,13 @@ def run (self):
142135
if cmd_name not in self.no_format_option:
143136
sub_cmd.format = self.formats[i]
144137

138+
# passing the owner and group names for tar archiving
139+
if cmd_name == 'bdist_dumb':
140+
sub_cmd.owner = self.owner
141+
sub_cmd.group = self.group
142+
145143
# If we're going to need to run this command again, tell it to
146144
# keep its temporary files around so subsequent runs go faster.
147145
if cmd_name in commands[i+1:]:
148146
sub_cmd.keep_temp = 1
149147
self.run_command(cmd_name)
150-
151-
# run()
152-
153-
# class bdist

Lib/distutils/command/bdist_dumb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
distribution -- i.e., just an archive to be unpacked under $prefix or
55
$exec_prefix)."""
66

7-
__revision__ = "$Id: bdist_dumb.py 77761 2010-01-26 22:46:15Z tarek.ziade $"
7+
__revision__ = "$Id$"
88

99
import os
1010

@@ -50,7 +50,7 @@ class bdist_dumb (Command):
5050
default_format = { 'posix': 'gztar',
5151
'java': 'gztar',
5252
'nt': 'zip',
53-
'os2': 'zip' }
53+
'os2': 'zip'}
5454

5555

5656
def initialize_options (self):
@@ -59,7 +59,7 @@ def initialize_options (self):
5959
self.format = None
6060
self.keep_temp = 0
6161
self.dist_dir = None
62-
self.skip_build = 0
62+
self.skip_build = None
6363
self.relative = 0
6464
self.owner = None
6565
self.group = None
@@ -79,7 +79,8 @@ def finalize_options(self):
7979

8080
self.set_undefined_options('bdist',
8181
('dist_dir', 'dist_dir'),
82-
('plat_name', 'plat_name'))
82+
('plat_name', 'plat_name'),
83+
('skip_build', 'skip_build'))
8384

8485
def run(self):
8586
if not self.skip_build:

Lib/distutils/command/build.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ def finalize_options(self):
115115
'scripts-' + sys.version[0:3])
116116

117117
if self.executable is None:
118-
if not sys.executable is None:
119-
self.executable = os.path.normpath(sys.executable)
120-
else:
121-
from org.python.core import Py
122-
self.executable = Py.getDefaultExecutableName()
118+
self.executable = os.path.normpath(sys.executable)
123119

124120
def run(self):
125121
# Run all relevant sub-commands. This will be some subset of:

Lib/distutils/command/build_scripts.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
33
Implements the Distutils 'build_scripts' command."""
44

5-
# This module should be kept compatible with Python 2.1.
5+
__revision__ = "$Id$"
66

7-
__revision__ = "$Id: build_scripts.py 59668 2008-01-02 18:59:36Z guido.van.rossum $"
8-
9-
import sys, os, re
7+
import os, re
108
from stat import ST_MODE
11-
from distutils import sysconfig
129
from distutils.core import Command
1310
from distutils.dep_util import newer
1411
from distutils.util import convert_path
@@ -59,6 +56,7 @@ def copy_scripts (self):
5956
ie. starts with "\#!" and contains "python"), then adjust the first
6057
line to refer to the current Python interpreter as we copy.
6158
"""
59+
_sysconfig = __import__('sysconfig')
6260
self.mkpath(self.build_dir)
6361
outfiles = []
6462
for script in self.scripts:
@@ -94,18 +92,23 @@ def copy_scripts (self):
9492
if adjust:
9593
log.info("copying and adjusting %s -> %s", script,
9694
self.build_dir)
97-
if not sysconfig.python_build:
98-
executable = self.executable
99-
else:
100-
executable = os.path.join(
101-
sysconfig.get_config_var("BINDIR"),
102-
"python" + sysconfig.get_config_var("EXE"))
95+
print "###############"
96+
print executable
10397
executable = fix_jython_executable(executable, post_interp)
98+
print executable
10499
if not self.dry_run:
105100
outf = open(outfile, "w")
106-
outf.write("#!%s%s\n" %
107-
(executable,
108-
post_interp))
101+
if not _sysconfig.is_python_build():
102+
outf.write("#!%s%s\n" %
103+
(self.executable,
104+
post_interp))
105+
else:
106+
outf.write("#!%s%s\n" %
107+
(os.path.join(
108+
_sysconfig.get_config_var("BINDIR"),
109+
"python%s%s" % (_sysconfig.get_config_var("VERSION"),
110+
_sysconfig.get_config_var("EXE"))),
111+
post_interp))
109112
outf.writelines(f.readlines())
110113
outf.close()
111114
if f:
@@ -115,7 +118,7 @@ def copy_scripts (self):
115118
f.close()
116119
self.copy_file(script, outfile)
117120

118-
if hasattr(os, 'chmod'):
121+
if os.name == 'posix':
119122
for file in outfiles:
120123
if self.dry_run:
121124
log.info("changing mode of %s", file)
@@ -150,9 +153,9 @@ def fix_jython_executable(executable, options):
150153
if options:
151154
# Can't apply the workaround, leave it broken
152155
log.warn("WARNING: Unable to adapt shebang line for Jython,"
153-
" the following script is NOT executable\n"
156+
" the following script is NOT executable\n"
154157
" see http://bugs.jython.org/issue1112 for"
155-
" more information.")
158+
" more information.")
156159
else:
157160
return '/usr/bin/env %s' % executable
158-
return executable
161+
return executable

Lib/distutils/command/install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ def finalize_options (self):
279279

280280
if self.user and (self.prefix or self.exec_prefix or self.home or
281281
self.install_base or self.install_platbase):
282-
raise DistutilsOptionError("can't combine user with with prefix/"
283-
"exec_prefix/home or install_(plat)base")
282+
raise DistutilsOptionError("can't combine user with prefix, "
283+
"exec_prefix/home, or install_(plat)base")
284284

285285
# Next, stuff that's wrong (or dubious) only on certain platforms.
286286
if os.name != "posix":

Lib/distutils/command/install_scripts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# contributed by Bastian Kleineidam
77

8-
__revision__ = "$Id: install_scripts.py 68943 2009-01-25 22:09:10Z tarek.ziade $"
8+
__revision__ = "$Id$"
99

1010
import os
1111
from distutils.core import Command
@@ -44,7 +44,7 @@ def run (self):
4444
if not self.skip_build:
4545
self.run_command('build_scripts')
4646
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
47-
if hasattr(os, 'chmod'):
47+
if os.name == 'posix':
4848
# Set the executable bits (owner, group, and world) on
4949
# all the scripts we just installed.
5050
for file in self.get_outputs():

0 commit comments

Comments
 (0)