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

Skip to content

Commit 3679727

Browse files
author
Tarek Ziadé
committed
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
1 parent 5db0c94 commit 3679727

64 files changed

Lines changed: 1632 additions & 1684 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lib/distutils/archive_util.py

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,15 @@
1414
from distutils.dir_util import mkpath
1515
from distutils import log
1616

17-
try:
18-
from pwd import getpwnam
19-
except ImportError:
20-
getpwnam = None
21-
22-
try:
23-
from grp import getgrnam
24-
except ImportError:
25-
getgrnam = None
26-
27-
def _get_gid(name):
28-
"""Returns a gid, given a group name."""
29-
if getgrnam is None or name is None:
30-
return None
31-
try:
32-
result = getgrnam(name)
33-
except KeyError:
34-
result = None
35-
if result is not None:
36-
return result[2]
37-
return None
38-
39-
def _get_uid(name):
40-
"""Returns an uid, given a user name."""
41-
if getpwnam is None or name is None:
42-
return None
43-
try:
44-
result = getpwnam(name)
45-
except KeyError:
46-
result = None
47-
if result is not None:
48-
return result[2]
49-
return None
50-
51-
def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
52-
owner=None, group=None):
17+
def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0):
5318
"""Create a (possibly compressed) tar file from all the files under
5419
'base_dir'.
5520
5621
'compress' must be "gzip" (the default), "compress", "bzip2", or None.
57-
(compress will be deprecated in Python 3.2)
58-
59-
'owner' and 'group' can be used to define an owner and a group for the
60-
archive that is being built. If not provided, the current owner and group
61-
will be used.
62-
22+
Both "tar" and the compression utility named by 'compress' must be on
23+
the default program search path, so this is probably Unix-specific.
6324
The output tar file will be named 'base_dir' + ".tar", possibly plus
6425
the appropriate compression extension (".gz", ".bz2" or ".Z").
65-
6626
Returns the output filename.
6727
"""
6828
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: '', 'compress': ''}
@@ -84,23 +44,10 @@ def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
8444
import tarfile # late import so Python build itself doesn't break
8545

8646
log.info('Creating tar archive')
87-
88-
uid = _get_uid(owner)
89-
gid = _get_gid(group)
90-
91-
def _set_uid_gid(tarinfo):
92-
if gid is not None:
93-
tarinfo.gid = gid
94-
tarinfo.gname = group
95-
if uid is not None:
96-
tarinfo.uid = uid
97-
tarinfo.uname = owner
98-
return tarinfo
99-
10047
if not dry_run:
10148
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
10249
try:
103-
tar.add(base_dir, filter=_set_uid_gid)
50+
tar.add(base_dir)
10451
finally:
10552
tar.close()
10653

@@ -190,7 +137,7 @@ def check_archive_formats(formats):
190137
return None
191138

192139
def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
193-
dry_run=0, owner=None, group=None):
140+
dry_run=0):
194141
"""Create an archive file (eg. zip or tar).
195142
196143
'base_name' is the name of the file to create, minus any format-specific
@@ -203,9 +150,6 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
203150
ie. 'base_dir' will be the common prefix of all files and
204151
directories in the archive. 'root_dir' and 'base_dir' both default
205152
to the current directory. Returns the name of the archive file.
206-
207-
'owner' and 'group' are used when creating a tar archive. By default,
208-
uses the current owner and group.
209153
"""
210154
save_cwd = os.getcwd()
211155
if root_dir is not None:
@@ -227,11 +171,6 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
227171
func = format_info[0]
228172
for arg, val in format_info[1]:
229173
kwargs[arg] = val
230-
231-
if format != 'zip':
232-
kwargs['owner'] = owner
233-
kwargs['group'] = group
234-
235174
try:
236175
filename = func(base_name, base_dir, **kwargs)
237176
finally:

Lib/distutils/bcppcompiler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
__revision__ = "$Id$"
1515

16-
import os
1716

18-
from distutils.errors import (DistutilsExecError, CompileError, LibError,
19-
LinkError, UnknownFileError)
20-
from distutils.ccompiler import CCompiler, gen_preprocess_options
17+
import os
18+
from distutils.errors import \
19+
DistutilsExecError, DistutilsPlatformError, \
20+
CompileError, LibError, LinkError, UnknownFileError
21+
from distutils.ccompiler import \
22+
CCompiler, gen_preprocess_options, gen_lib_options
2123
from distutils.file_util import write_file
2224
from distutils.dep_util import newer
2325
from distutils import log

Lib/distutils/ccompiler.py

Lines changed: 82 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,15 @@
55

66
__revision__ = "$Id$"
77

8-
import sys
9-
import os
10-
import re
11-
12-
from distutils.errors import (CompileError, LinkError, UnknownFileError,
13-
DistutilsPlatformError, DistutilsModuleError)
8+
import sys, os, re
9+
from distutils.errors import *
1410
from distutils.spawn import spawn
1511
from distutils.file_util import move_file
1612
from distutils.dir_util import mkpath
17-
from distutils.dep_util import newer_group
13+
from distutils.dep_util import newer_pairwise, newer_group
1814
from distutils.util import split_quoted, execute
1915
from distutils import log
2016

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
72-
7317
class CCompiler:
7418
"""Abstract base class to define the interface that must be implemented
7519
by real compiler classes. Also has some utility methods used by
@@ -449,6 +393,22 @@ def _fix_compile_args(self, output_dir, macros, include_dirs):
449393

450394
return output_dir, macros, include_dirs
451395

396+
def _prep_compile(self, sources, output_dir, depends=None):
397+
"""Decide which souce files must be recompiled.
398+
399+
Determine the list of object files corresponding to 'sources',
400+
and figure out which ones really need to be recompiled.
401+
Return a list of all object files and a dictionary telling
402+
which source files can be skipped.
403+
"""
404+
# Get the list of expected output (object) files
405+
objects = self.object_filenames(sources, output_dir=output_dir)
406+
assert len(objects) == len(sources)
407+
408+
# Return an empty dict for the "which source files can be skipped"
409+
# return value to preserve API compatibility.
410+
return objects, {}
411+
452412
def _fix_object_args(self, objects, output_dir):
453413
"""Typecheck and fix up some arguments supplied to various methods.
454414
Specifically: ensure that 'objects' is a list; if output_dir is
@@ -650,15 +610,26 @@ def create_static_lib(self, objects, output_libname, output_dir=None,
650610
"""
651611
pass
652612

613+
653614
# values for target_desc parameter in link()
654615
SHARED_OBJECT = "shared_object"
655616
SHARED_LIBRARY = "shared_library"
656617
EXECUTABLE = "executable"
657618

658-
def link(self, target_desc, objects, output_filename, output_dir=None,
659-
libraries=None, library_dirs=None, runtime_library_dirs=None,
660-
export_symbols=None, debug=0, extra_preargs=None,
661-
extra_postargs=None, build_temp=None, target_lang=None):
619+
def link(self,
620+
target_desc,
621+
objects,
622+
output_filename,
623+
output_dir=None,
624+
libraries=None,
625+
library_dirs=None,
626+
runtime_library_dirs=None,
627+
export_symbols=None,
628+
debug=0,
629+
extra_preargs=None,
630+
extra_postargs=None,
631+
build_temp=None,
632+
target_lang=None):
662633
"""Link a bunch of stuff together to create an executable or
663634
shared library file.
664635
@@ -707,11 +678,19 @@ def link(self, target_desc, objects, output_filename, output_dir=None,
707678

708679
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
709680

710-
def link_shared_lib(self, objects, output_libname, output_dir=None,
711-
libraries=None, library_dirs=None,
712-
runtime_library_dirs=None, export_symbols=None,
713-
debug=0, extra_preargs=None, extra_postargs=None,
714-
build_temp=None, target_lang=None):
681+
def link_shared_lib(self,
682+
objects,
683+
output_libname,
684+
output_dir=None,
685+
libraries=None,
686+
library_dirs=None,
687+
runtime_library_dirs=None,
688+
export_symbols=None,
689+
debug=0,
690+
extra_preargs=None,
691+
extra_postargs=None,
692+
build_temp=None,
693+
target_lang=None):
715694
self.link(CCompiler.SHARED_LIBRARY, objects,
716695
self.library_filename(output_libname, lib_type='shared'),
717696
output_dir,
@@ -720,22 +699,37 @@ def link_shared_lib(self, objects, output_libname, output_dir=None,
720699
extra_preargs, extra_postargs, build_temp, target_lang)
721700

722701

723-
def link_shared_object(self, objects, output_filename, output_dir=None,
724-
libraries=None, library_dirs=None,
725-
runtime_library_dirs=None, export_symbols=None,
726-
debug=0, extra_preargs=None, extra_postargs=None,
727-
build_temp=None, target_lang=None):
702+
def link_shared_object(self,
703+
objects,
704+
output_filename,
705+
output_dir=None,
706+
libraries=None,
707+
library_dirs=None,
708+
runtime_library_dirs=None,
709+
export_symbols=None,
710+
debug=0,
711+
extra_preargs=None,
712+
extra_postargs=None,
713+
build_temp=None,
714+
target_lang=None):
728715
self.link(CCompiler.SHARED_OBJECT, objects,
729716
output_filename, output_dir,
730717
libraries, library_dirs, runtime_library_dirs,
731718
export_symbols, debug,
732719
extra_preargs, extra_postargs, build_temp, target_lang)
733720

734721

735-
def link_executable(self, objects, output_progname, output_dir=None,
736-
libraries=None, library_dirs=None,
737-
runtime_library_dirs=None, debug=0, extra_preargs=None,
738-
extra_postargs=None, target_lang=None):
722+
def link_executable(self,
723+
objects,
724+
output_progname,
725+
output_dir=None,
726+
libraries=None,
727+
library_dirs=None,
728+
runtime_library_dirs=None,
729+
debug=0,
730+
extra_preargs=None,
731+
extra_postargs=None,
732+
target_lang=None):
739733
self.link(CCompiler.EXECUTABLE, objects,
740734
self.executable_filename(output_progname), output_dir,
741735
libraries, library_dirs, runtime_library_dirs, None,
@@ -917,7 +911,7 @@ def spawn(self, cmd):
917911
def move_file(self, src, dst):
918912
return move_file(src, dst, dry_run=self.dry_run)
919913

920-
def mkpath(self, name, mode=0o777):
914+
def mkpath (self, name, mode=0o777):
921915
mkpath(name, mode, dry_run=self.dry_run)
922916

923917

@@ -1085,14 +1079,12 @@ def gen_preprocess_options(macros, include_dirs):
10851079
return pp_opts
10861080

10871081

1088-
def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
1082+
def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
10891083
"""Generate linker options for searching library directories and
1090-
linking with specific libraries.
1091-
1092-
'libraries' and 'library_dirs' are, respectively, lists of library names
1093-
(not filenames!) and search directories. Returns a list of command-line
1094-
options suitable for use with some compiler (depending on the two format
1095-
strings passed in).
1084+
linking with specific libraries. 'libraries' and 'library_dirs' are,
1085+
respectively, lists of library names (not filenames!) and search
1086+
directories. Returns a list of command-line options suitable for use
1087+
with some compiler (depending on the two format strings passed in).
10961088
"""
10971089
lib_opts = []
10981090

@@ -1102,7 +1094,7 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
11021094
for dir in runtime_library_dirs:
11031095
opt = compiler.runtime_library_dir_option(dir)
11041096
if isinstance(opt, list):
1105-
lib_opts.extend(opt)
1097+
lib_opts = lib_opts + opt
11061098
else:
11071099
lib_opts.append(opt)
11081100

@@ -1113,14 +1105,14 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
11131105
# pretty nasty way to arrange your C code.
11141106

11151107
for lib in libraries:
1116-
lib_dir, lib_name = os.path.split(lib)
1117-
if lib_dir != '':
1108+
(lib_dir, lib_name) = os.path.split(lib)
1109+
if lib_dir:
11181110
lib_file = compiler.find_library_file([lib_dir], lib_name)
1119-
if lib_file is not None:
1111+
if lib_file:
11201112
lib_opts.append(lib_file)
11211113
else:
11221114
compiler.warn("no library file corresponding to "
11231115
"'%s' found (skipping)" % lib)
11241116
else:
1125-
lib_opts.append(compiler.library_option(lib))
1117+
lib_opts.append(compiler.library_option (lib))
11261118
return lib_opts

0 commit comments

Comments
 (0)