From: <pj...@us...> - 2008-07-14 19:27:04
|
Revision: 4933 http://jython.svn.sourceforge.net/jython/?rev=4933&view=rev Author: pjenvey Date: 2008-07-14 12:26:58 -0700 (Mon, 14 Jul 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/distutils@64955 Modified Paths: -------------- branches/asm/Lib/distutils/ccompiler.py branches/asm/Lib/distutils/command/bdist.py branches/asm/Lib/distutils/command/bdist_dumb.py branches/asm/Lib/distutils/command/install.py branches/asm/Lib/distutils/command/sdist.py branches/asm/Lib/distutils/file_util.py branches/asm/Lib/distutils/spawn.py branches/asm/Lib/distutils/sysconfig.py branches/asm/Lib/distutils/util.py Added Paths: ----------- branches/asm/Lib/distutils/tests/ branches/asm/Lib/distutils/tests/test_build_py.py Modified: branches/asm/Lib/distutils/ccompiler.py =================================================================== --- branches/asm/Lib/distutils/ccompiler.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/ccompiler.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -3,9 +3,9 @@ Contains CCompiler, an abstract base class that defines the interface for the Distutils compiler abstraction model.""" -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: ccompiler.py 37185 2004-08-29 16:45:13Z loewis $" +__revision__ = "$Id: ccompiler.py 46331 2006-05-26 14:07:23Z bob.ippolito $" import sys, os, re from types import * @@ -15,7 +15,6 @@ from distutils.file_util import move_file from distutils.dir_util import mkpath from distutils.dep_util import newer_pairwise, newer_group -from distutils.sysconfig import python_build from distutils.util import split_quoted, execute from distutils import log @@ -368,7 +367,7 @@ # Get the list of expected output (object) files objects = self.object_filenames(sources, - strip_dir=python_build, + strip_dir=0, output_dir=outdir) assert len(objects) == len(sources) @@ -475,8 +474,7 @@ which source files can be skipped. """ # Get the list of expected output (object) files - objects = self.object_filenames(sources, strip_dir=python_build, - output_dir=output_dir) + objects = self.object_filenames(sources, output_dir=output_dir) assert len(objects) == len(sources) if self.force: @@ -685,13 +683,17 @@ # A concrete compiler class can either override this method # entirely or implement _compile(). - + macros, objects, extra_postargs, pp_opts, build = \ self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs) cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) - for obj, (src, ext) in build.items(): + for obj in objects: + try: + src, ext = build[obj] + except KeyError: + continue self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) # Return *all* object filenames, not just the ones we just built. @@ -699,7 +701,7 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): """Compile 'src' to product 'obj'.""" - + # A concrete compiler class that does not override compile() # should implement _compile(). pass @@ -1057,7 +1059,6 @@ # compiler ('cygwin.*', 'unix'), ('os2emx', 'emx'), - ('java.*', 'jython'), # OS name mappings ('posix', 'unix'), @@ -1106,8 +1107,6 @@ "MetroWerks CodeWarrior"), 'emx': ('emxccompiler', 'EMXCCompiler', "EMX port of GNU C Compiler for OS/2"), - 'jython': ('jythoncompiler', 'JythonCompiler', - "Compiling is not supported on Jython"), } def show_compilers(): Modified: branches/asm/Lib/distutils/command/bdist.py =================================================================== --- branches/asm/Lib/distutils/command/bdist.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/command/bdist.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -3,9 +3,9 @@ Implements the Distutils 'bdist' command (create a built [binary] distribution).""" -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: bdist.py 29762 2002-11-19 13:12:28Z akuchling $" +__revision__ = "$Id: bdist.py 37828 2004-11-10 22:23:15Z loewis $" import os, string from types import * @@ -59,7 +59,6 @@ # This won't do in reality: will need to distinguish RPM-ish Linux, # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. default_format = { 'posix': 'gztar', - 'java': 'gztar', 'nt': 'zip', 'os2': 'zip', } @@ -79,7 +78,7 @@ 'wininst': ('bdist_wininst', "Windows executable installer"), 'zip': ('bdist_dumb', "ZIP file"), - #'pkgtool': ('bdist_pkgtool', + #'pkgtool': ('bdist_pkgtool', # "Solaris pkgtool distribution"), #'sdux': ('bdist_sdux', "HP-UX swinstall depot"), } Modified: branches/asm/Lib/distutils/command/bdist_dumb.py =================================================================== --- branches/asm/Lib/distutils/command/bdist_dumb.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/command/bdist_dumb.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -4,15 +4,16 @@ distribution -- i.e., just an archive to be unpacked under $prefix or $exec_prefix).""" -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: bdist_dumb.py 29901 2002-11-26 17:45:19Z akuchling $" +__revision__ = "$Id: bdist_dumb.py 38697 2005-03-23 18:54:36Z loewis $" import os from distutils.core import Command from distutils.util import get_platform from distutils.dir_util import create_tree, remove_tree, ensure_relative from distutils.errors import * +from distutils.sysconfig import get_python_version from distutils import log class bdist_dumb (Command): @@ -41,7 +42,6 @@ boolean_options = ['keep-temp', 'skip-build', 'relative'] default_format = { 'posix': 'gztar', - 'java': 'gztar', 'nt': 'zip', 'os2': 'zip' } @@ -54,7 +54,7 @@ self.dist_dir = None self.skip_build = 0 self.relative = 0 - + # initialize_options() @@ -118,8 +118,14 @@ ensure_relative(install.install_base)) # Make the archive - self.make_archive(pseudoinstall_root, - self.format, root_dir=archive_root) + filename = self.make_archive(pseudoinstall_root, + self.format, root_dir=archive_root) + if self.distribution.has_ext_modules(): + pyversion = get_python_version() + else: + pyversion = 'any' + self.distribution.dist_files.append(('bdist_dumb', pyversion, + filename)) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) Modified: branches/asm/Lib/distutils/command/install.py =================================================================== --- branches/asm/Lib/distutils/command/install.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/command/install.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -4,9 +4,9 @@ from distutils import log -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: install.py 38351 2005-01-20 19:16:27Z theller $" +__revision__ = "$Id: install.py 43363 2006-03-27 21:55:21Z phillip.eby $" import sys, os, string from types import * @@ -65,13 +65,6 @@ 'headers': '$base/Include/$dist_name', 'scripts': '$base/Scripts', 'data' : '$base', - }, - 'java': { - 'purelib': '$base/Lib/site-packages', - 'platlib': '$base/Lib/site-packages', - 'headers': '$base/Include/$dist_name', - 'scripts': '$base/bin', - 'data' : '$base', } } @@ -244,19 +237,15 @@ ("must supply either prefix/exec-prefix/home or " + "install-base/install-platbase -- not both") + if self.home and (self.prefix or self.exec_prefix): + raise DistutilsOptionError, \ + "must supply either home or prefix/exec-prefix -- not both" + # Next, stuff that's wrong (or dubious) only on certain platforms. - if os.name == 'posix': - if self.home and (self.prefix or self.exec_prefix): - raise DistutilsOptionError, \ - ("must supply either home or prefix/exec-prefix -- " + - "not both") - else: + if os.name != "posix": if self.exec_prefix: self.warn("exec-prefix option ignored on this platform") self.exec_prefix = None - if self.home: - self.warn("home option ignored on this platform") - self.home = None # Now the interesting logic -- so interesting that we farm it out # to other methods. The goal of these methods is to set the final @@ -412,15 +401,19 @@ def finalize_other (self): # Windows and Mac OS for now - if self.prefix is None: - self.prefix = os.path.normpath(sys.prefix) + if self.home is not None: + self.install_base = self.install_platbase = self.home + self.select_scheme("unix_home") + else: + if self.prefix is None: + self.prefix = os.path.normpath(sys.prefix) - self.install_base = self.install_platbase = self.prefix - try: - self.select_scheme(os.name) - except KeyError: - raise DistutilsPlatformError, \ - "I don't know how to install stuff on '%s'" % os.name + self.install_base = self.install_platbase = self.prefix + try: + self.select_scheme(os.name) + except KeyError: + raise DistutilsPlatformError, \ + "I don't know how to install stuff on '%s'" % os.name # finalize_other () @@ -538,7 +531,7 @@ not (self.path_file and self.install_path_file) and install_lib not in sys_path): log.debug(("modules installed to '%s', which is not in " - "Python's module search path (sys.path) -- " + "Python's module search path (sys.path) -- " "you'll have to change the search path yourself"), self.install_lib) @@ -608,6 +601,7 @@ ('install_headers', has_headers), ('install_scripts', has_scripts), ('install_data', has_data), + ('install_egg_info', lambda self:True), ] # class install Modified: branches/asm/Lib/distutils/command/sdist.py =================================================================== --- branches/asm/Lib/distutils/command/sdist.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/command/sdist.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -2,9 +2,9 @@ Implements the Distutils 'sdist' command (create a source distribution).""" -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: sdist.py 37012 2004-08-16 12:15:00Z doko $" +__revision__ = "$Id: sdist.py 61268 2008-03-06 07:14:26Z martin.v.loewis $" import sys, os, string from types import * @@ -80,7 +80,6 @@ 'no-prune': 'prune' } default_format = { 'posix': 'gztar', - 'java': 'gztar', 'nt': 'zip' } def initialize_options (self): @@ -348,14 +347,14 @@ * the build tree (typically "build") * the release tree itself (only an issue if we ran "sdist" previously with --keep-temp, or it aborted) - * any RCS or CVS directories + * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories """ build = self.get_finalized_command('build') base_dir = self.distribution.get_fullname() self.filelist.exclude_pattern(None, prefix=build.build_base) self.filelist.exclude_pattern(None, prefix=base_dir) - self.filelist.exclude_pattern(r'/(RCS|CVS|\.svn)/.*', is_regex=1) + self.filelist.exclude_pattern(r'(^|/)(RCS|CVS|\.svn|\.hg|\.git|\.bzr|_darcs)/.*', is_regex=1) def write_manifest (self): @@ -377,16 +376,13 @@ """ log.info("reading manifest file '%s'", self.manifest) manifest = open(self.manifest) - try: - while 1: - line = manifest.readline() - if line == '': # end of file - break - if line[-1] == '\n': - line = line[0:-1] - self.filelist.append(line) - finally: - manifest.close() + while 1: + line = manifest.readline() + if line == '': # end of file + break + if line[-1] == '\n': + line = line[0:-1] + self.filelist.append(line) # read_manifest () @@ -453,6 +449,7 @@ for fmt in self.formats: file = self.make_archive(base_name, fmt, base_dir=base_dir) archive_files.append(file) + self.distribution.dist_files.append(('sdist', '', file)) self.archive_files = archive_files Modified: branches/asm/Lib/distutils/file_util.py =================================================================== --- branches/asm/Lib/distutils/file_util.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/file_util.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -3,9 +3,9 @@ Utility functions for operating on single files. """ -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: file_util.py 29762 2002-11-19 13:12:28Z akuchling $" +__revision__ = "$Id: file_util.py 37828 2004-11-10 22:23:15Z loewis $" import os from distutils.errors import DistutilsFileError @@ -42,7 +42,7 @@ except os.error, (errno, errstr): raise DistutilsFileError, \ "could not delete '%s': %s" % (dst, errstr) - + try: fdst = open(dst, 'wb') except os.error, (errno, errstr): @@ -170,7 +170,7 @@ # before chmod() (at least under NT). if preserve_times: os.utime(dst, (st[ST_ATIME], st[ST_MTIME])) - if preserve_mode and hasattr(os, 'chmod'): + if preserve_mode: os.chmod(dst, S_IMODE(st[ST_MODE])) return (dst, 1) Modified: branches/asm/Lib/distutils/spawn.py =================================================================== --- branches/asm/Lib/distutils/spawn.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/spawn.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -6,9 +6,9 @@ executable name. """ -# This module should be kept compatible with Python 1.5.2. +# This module should be kept compatible with Python 2.1. -__revision__ = "$Id: spawn.py 29801 2002-11-21 20:41:07Z akuchling $" +__revision__ = "$Id: spawn.py 37828 2004-11-10 22:23:15Z loewis $" import sys, os, string from distutils.errors import * @@ -39,8 +39,6 @@ _spawn_nt(cmd, search_path, dry_run=dry_run) elif os.name == 'os2': _spawn_os2(cmd, search_path, dry_run=dry_run) - elif os.name == 'java': - _spawn_java(cmd, search_path, dry_run=dry_run) else: raise DistutilsPlatformError, \ "don't know how to spawn programs on platform '%s'" % os.name @@ -99,7 +97,7 @@ #cmd = _nt_quote_args(cmd) if search_path: # either we find one or it stays the same - executable = find_executable(executable) or executable + executable = find_executable(executable) or executable log.info(string.join([executable] + cmd[1:], ' ')) if not dry_run: # spawnv for OS/2 EMX requires a full path to the .exe @@ -146,7 +144,14 @@ # Loop until the child either exits or is terminated by a signal # (ie. keep waiting if it's merely stopped) while 1: - (pid, status) = os.waitpid(pid, 0) + try: + (pid, status) = os.waitpid(pid, 0) + except OSError, exc: + import errno + if exc.errno == errno.EINTR: + continue + raise DistutilsExecError, \ + "command '%s' failed: %s" % (cmd[0], exc[-1]) if os.WIFSIGNALED(status): raise DistutilsExecError, \ "command '%s' terminated by signal %d" % \ @@ -171,27 +176,6 @@ # _spawn_posix () -def _spawn_java(cmd, - search_path=1, - verbose=0, - dry_run=0): - executable = cmd[0] - cmd = ' '.join(_nt_quote_args(cmd)) - log.info(cmd) - if not dry_run: - try: - rc = os.system(cmd) >> 8 - except OSError, exc: - # this seems to happen when the command isn't found - raise DistutilsExecError, \ - "command '%s' failed: %s" % (executable, exc[-1]) - if rc != 0: - # and this reflects the command running but failing - print "command '%s' failed with exit status %d" % (executable, rc) - raise DistutilsExecError, \ - "command '%s' failed with exit status %d" % (executable, rc) - - def find_executable(executable, path=None): """Try to find 'executable' in the directories listed in 'path' (a string listing directories separated by 'os.pathsep'; defaults to Modified: branches/asm/Lib/distutils/sysconfig.py =================================================================== --- branches/asm/Lib/distutils/sysconfig.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/sysconfig.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -9,14 +9,14 @@ Email: <fd...@ac...> """ -__revision__ = "$Id: sysconfig.py 38269 2005-01-11 13:49:02Z jackjansen $" +__revision__ = "$Id: sysconfig.py 52234 2006-10-08 17:50:26Z ronald.oussoren $" import os import re import string import sys -from errors import DistutilsPlatformError +from distutils.errors import DistutilsPlatformError # These are needed in a couple of spots, so just compute them once. PREFIX = os.path.normpath(sys.prefix) @@ -31,10 +31,10 @@ python_build = os.path.isfile(landmark) -del argv0_path, landmark +del landmark -def get_python_version (): +def get_python_version(): """Return a string containing the major and minor Python version, leaving off the patchlevel. Sample return values could be '1.5' or '2.2'. @@ -65,15 +65,15 @@ if not os.path.exists(inc_dir): inc_dir = os.path.join(os.path.dirname(base), "Include") return inc_dir - return os.path.join(prefix, "include", "python" + sys.version[:3]) + return os.path.join(prefix, "include", "python" + get_python_version()) elif os.name == "nt": return os.path.join(prefix, "include") elif os.name == "mac": if plat_specific: - return os.path.join(prefix, "Mac", "Include") + return os.path.join(prefix, "Mac", "Include") else: - return os.path.join(prefix, "Include") - elif os.name == "os2" or os.name == "java": + return os.path.join(prefix, "Include") + elif os.name == "os2": return os.path.join(prefix, "Include") else: raise DistutilsPlatformError( @@ -110,7 +110,7 @@ if standard_lib: return os.path.join(prefix, "Lib") else: - if sys.version < "2.2": + if get_python_version() < "2.2": return prefix else: return os.path.join(PREFIX, "Lib", "site-packages") @@ -127,7 +127,7 @@ else: return os.path.join(prefix, "Lib", "site-packages") - elif os.name == "os2" or os.name == "java": + elif os.name == "os2": if standard_lib: return os.path.join(PREFIX, "Lib") else: @@ -146,30 +146,31 @@ varies across Unices and is stored in Python's Makefile. """ if compiler.compiler_type == "unix": - (cc, cxx, opt, basecflags, ccshared, ldshared, so_ext) = \ - get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO') + (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \ + get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', + 'CCSHARED', 'LDSHARED', 'SO') if os.environ.has_key('CC'): cc = os.environ['CC'] if os.environ.has_key('CXX'): cxx = os.environ['CXX'] + if os.environ.has_key('LDSHARED'): + ldshared = os.environ['LDSHARED'] if os.environ.has_key('CPP'): cpp = os.environ['CPP'] else: cpp = cc + " -E" # not always if os.environ.has_key('LDFLAGS'): ldshared = ldshared + ' ' + os.environ['LDFLAGS'] - if basecflags: - opt = basecflags + ' ' + opt if os.environ.has_key('CFLAGS'): - opt = opt + ' ' + os.environ['CFLAGS'] + cflags = opt + ' ' + os.environ['CFLAGS'] ldshared = ldshared + ' ' + os.environ['CFLAGS'] if os.environ.has_key('CPPFLAGS'): cpp = cpp + ' ' + os.environ['CPPFLAGS'] - opt = opt + ' ' + os.environ['CPPFLAGS'] + cflags = cflags + ' ' + os.environ['CPPFLAGS'] ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] - cc_cmd = cc + ' ' + opt + cc_cmd = cc + ' ' + cflags compiler.set_executables( preprocessor=cpp, compiler=cc_cmd, @@ -184,10 +185,10 @@ def get_config_h_filename(): """Return full pathname of installed pyconfig.h file.""" if python_build: - inc_dir = os.curdir + inc_dir = argv0_path else: inc_dir = get_python_inc(plat_specific=1) - if sys.version < '2.2': + if get_python_version() < '2.2': config_h = 'config.h' else: # The name of the config.h file changed in 2.2 @@ -212,8 +213,8 @@ """ if g is None: g = {} - define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n") - undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n") + define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n") + undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n") # while 1: line = fp.readline() @@ -275,25 +276,20 @@ m = _findvar1_rx.search(value) or _findvar2_rx.search(value) if m: n = m.group(1) + found = True if done.has_key(n): - after = value[m.end():] - value = value[:m.start()] + str(done[n]) + after - if "$" in after: - notdone[name] = value - else: - try: value = int(value) - except ValueError: - done[name] = string.strip(value) - else: - done[name] = value - del notdone[name] + item = str(done[n]) elif notdone.has_key(n): # get it on a subsequent round - pass + found = False + elif os.environ.has_key(n): + # do it like make: fall back to environment + item = os.environ[n] else: - done[n] = "" + done[n] = item = "" + if found: after = value[m.end():] - value = value[:m.start()] + after + value = value[:m.start()] + item + after if "$" in after: notdone[name] = value else: @@ -355,28 +351,39 @@ raise DistutilsPlatformError(my_msg) + # load the installed pyconfig.h: + try: + filename = get_config_h_filename() + parse_config_h(file(filename), g) + except IOError, msg: + my_msg = "invalid Python installation: unable to open %s" % filename + if hasattr(msg, "strerror"): + my_msg = my_msg + " (%s)" % msg.strerror + + raise DistutilsPlatformError(my_msg) + # On MacOSX we need to check the setting of the environment variable # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so # it needs to be compatible. # If it isn't set we set it to the configure-time value - if sys.platform == 'darwin' and g.has_key('CONFIGURE_MACOSX_DEPLOYMENT_TARGET'): - cfg_target = g['CONFIGURE_MACOSX_DEPLOYMENT_TARGET'] + if sys.platform == 'darwin' and g.has_key('MACOSX_DEPLOYMENT_TARGET'): + cfg_target = g['MACOSX_DEPLOYMENT_TARGET'] cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '') if cur_target == '': cur_target = cfg_target os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target) - if cfg_target != cur_target: + elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')): my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' % (cur_target, cfg_target)) raise DistutilsPlatformError(my_msg) - + # On AIX, there are wrong paths to the linker scripts in the Makefile # -- these paths are relative to the Python source, but when installed # the scripts are in another directory. if python_build: g['LDSHARED'] = g['BLDSHARED'] - elif sys.version < '2.1': + elif get_python_version() < '2.1': # The following two branches are for 1.5.2 compatibility. if sys.platform == 'aix4': # what about AIX 3.x ? # Linker script is in the config directory, not in Modules as the @@ -403,7 +410,7 @@ # it's taken care of for them by the 'build_ext.get_libraries()' # method.) g['LDSHARED'] = ("%s -L%s/lib -lpython%s" % - (linkerscript, PREFIX, sys.version[0:3])) + (linkerscript, PREFIX, get_python_version())) global _config_vars _config_vars = g @@ -469,13 +476,6 @@ _config_vars = g -def _init_jython(): - """Initialize the module as appropriate for Jython""" - # Stub out some values that build_ext expects; they don't matter - # anyway - _init_os2() - - def get_config_vars(*args): """With no arguments, return a dictionary of all configuration variables relevant for the current platform. Generally this includes @@ -488,12 +488,7 @@ """ global _config_vars if _config_vars is None: - if sys.platform.startswith('java'): - # Jython might pose as a different os.name, but we always - # want _init_jython regardless - func = _init_jython - else: - func = globals().get("_init_" + os.name) + func = globals().get("_init_" + os.name) if func: func() else: @@ -505,6 +500,25 @@ _config_vars['prefix'] = PREFIX _config_vars['exec_prefix'] = EXEC_PREFIX + if sys.platform == 'darwin': + kernel_version = os.uname()[2] # Kernel version (8.4.3) + major_version = int(kernel_version.split('.')[0]) + + if major_version < 8: + # On Mac OS X before 10.4, check if -arch and -isysroot + # are in CFLAGS or LDFLAGS and remove them if they are. + # This is needed when building extensions on a 10.3 system + # using a universal build of python. + for key in ('LDFLAGS', 'BASECFLAGS', + # a number of derived variables. These need to be + # patched up as well. + 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'): + + flags = _config_vars[key] + flags = re.sub('-arch\s+\w+\s', ' ', flags) + flags = re.sub('-isysroot [^ \t]*', ' ', flags) + _config_vars[key] = flags + if args: vals = [] for name in args: Added: branches/asm/Lib/distutils/tests/test_build_py.py =================================================================== --- branches/asm/Lib/distutils/tests/test_build_py.py (rev 0) +++ branches/asm/Lib/distutils/tests/test_build_py.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -0,0 +1,96 @@ +"""Tests for distutils.command.build_py.""" + +import os +import sys +import StringIO +import unittest + +from distutils.command.build_py import build_py +from distutils.core import Distribution +from distutils.errors import DistutilsFileError + +from distutils.tests import support + + +class BuildPyTestCase(support.TempdirManager, + support.LoggingSilencer, + unittest.TestCase): + + def test_package_data(self): + sources = self.mkdtemp() + f = open(os.path.join(sources, "__init__.py"), "w") + f.write("# Pretend this is a package.") + f.close() + f = open(os.path.join(sources, "README.txt"), "w") + f.write("Info about this package") + f.close() + + destination = self.mkdtemp() + + dist = Distribution({"packages": ["pkg"], + "package_dir": {"pkg": sources}}) + # script_name need not exist, it just need to be initialized + dist.script_name = os.path.join(sources, "setup.py") + dist.command_obj["build"] = support.DummyCommand( + force=0, + build_lib=destination) + dist.packages = ["pkg"] + dist.package_data = {"pkg": ["README.txt"]} + dist.package_dir = {"pkg": sources} + + cmd = build_py(dist) + cmd.compile = 1 + cmd.ensure_finalized() + self.assertEqual(cmd.package_data, dist.package_data) + + cmd.run() + + # This makes sure the list of outputs includes byte-compiled + # files for Python modules but not for package data files + # (there shouldn't *be* byte-code files for those!). + # + self.assertEqual(len(cmd.get_outputs()), 3) + pkgdest = os.path.join(destination, "pkg") + files = os.listdir(pkgdest) + self.assert_("__init__.py" in files) + self.assert_("__init__.pyc" in files) + self.assert_("README.txt" in files) + + def test_empty_package_dir (self): + # See SF 1668596/1720897. + cwd = os.getcwd() + + # create the distribution files. + sources = self.mkdtemp() + open(os.path.join(sources, "__init__.py"), "w").close() + + testdir = os.path.join(sources, "doc") + os.mkdir(testdir) + open(os.path.join(testdir, "testfile"), "w").close() + + os.chdir(sources) + sys.stdout = StringIO.StringIO() + + try: + dist = Distribution({"packages": ["pkg"], + "package_dir": {"pkg": ""}, + "package_data": {"pkg": ["doc/*"]}}) + # script_name need not exist, it just need to be initialized + dist.script_name = os.path.join(sources, "setup.py") + dist.script_args = ["build"] + dist.parse_command_line() + + try: + dist.run_commands() + except DistutilsFileError: + self.fail("failed package_data test when package_dir is ''") + finally: + # Restore state. + os.chdir(cwd) + sys.stdout = sys.__stdout__ + +def test_suite(): + return unittest.makeSuite(BuildPyTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") Modified: branches/asm/Lib/distutils/util.py =================================================================== --- branches/asm/Lib/distutils/util.py 2008-07-14 19:25:59 UTC (rev 4932) +++ branches/asm/Lib/distutils/util.py 2008-07-14 19:26:58 UTC (rev 4933) @@ -4,7 +4,7 @@ one of the other *util.py modules. """ -__revision__ = "$Id: util.py 30621 2003-01-06 13:28:12Z akuchling $" +__revision__ = "$Id: util.py 59116 2007-11-22 10:14:26Z ronald.oussoren $" import sys, os, string, re from distutils.errors import DistutilsPlatformError @@ -45,6 +45,7 @@ osname = string.lower(osname) osname = string.replace(osname, '/', '') machine = string.replace(machine, ' ', '_') + machine = string.replace(machine, '/', '-') if osname[:5] == "linux": # At least on Linux/Intel, 'machine' is the processor -- @@ -66,7 +67,55 @@ m = rel_re.match(release) if m: release = m.group() + elif osname[:6] == "darwin": + # + # For our purposes, we'll assume that the system version from + # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set + # to. This makes the compatibility story a bit more sane because the + # machine is going to compile and link as if it were + # MACOSX_DEPLOYMENT_TARGET. + from distutils.sysconfig import get_config_vars + cfgvars = get_config_vars() + macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET') + if not macver: + macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET') + + if not macver: + # Get the system version. Reading this plist is a documented + # way to get the system version (see the documentation for + # the Gestalt Manager) + try: + f = open('/System/Library/CoreServices/SystemVersion.plist') + except IOError: + # We're on a plain darwin box, fall back to the default + # behaviour. + pass + else: + m = re.search( + r'<key>ProductUserVisibleVersion</key>\s*' + + r'<string>(.*?)</string>', f.read()) + f.close() + if m is not None: + macver = '.'.join(m.group(1).split('.')[:2]) + # else: fall back to the default behaviour + + if macver: + from distutils.sysconfig import get_config_vars + release = macver + osname = "macosx" + + + if (release + '.') >= '10.4.' and \ + get_config_vars().get('UNIVERSALSDK', '').strip(): + # The universal build will build fat binaries, but not on + # systems before 10.4 + machine = 'fat' + + elif machine in ('PowerPC', 'Power_Macintosh'): + # Pick a sane name for the PPC architecture. + machine = 'ppc' + return "%s-%s-%s" % (osname, release, machine) # get_platform () @@ -106,7 +155,7 @@ Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. """ - if os.name == 'posix' or os.name == 'java': + if os.name == 'posix': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: @@ -209,9 +258,12 @@ # Needed by 'split_quoted()' -_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace) -_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") -_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') +_wordchars_re = _squote_re = _dquote_re = None +def _init_regex(): + global _wordchars_re, _squote_re, _dquote_re + _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace) + _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") + _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') def split_quoted (s): """Split a string up according to Unix shell-like rules for quotes and @@ -227,6 +279,7 @@ # This is a nice algorithm for splitting up a single string, since it # doesn't require character-by-character examination. It was a little # bit of a brain-bender to get it working right, though... + if _wordchars_re is None: _init_regex() s = string.strip(s) words = [] @@ -285,7 +338,7 @@ print. """ if msg is None: - msg = "%s%s" % (func.__name__, `args`) + msg = "%s%r" % (func.__name__, args) if msg[-2:] == ',)': # correct for singleton tuple msg = msg[0:-2] + ')' @@ -296,7 +349,7 @@ def strtobool (val): """Convert a string representation of truth to true (1) or false (0). - + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. @@ -307,7 +360,7 @@ elif val in ('n', 'no', 'f', 'false', 'off', '0'): return 0 else: - raise ValueError, "invalid truth value %s" % `val` + raise ValueError, "invalid truth value %r" % (val,) def byte_compile (py_files, @@ -394,11 +447,11 @@ script.write(string.join(map(repr, py_files), ",\n") + "]\n") script.write(""" -byte_compile(files, optimize=%s, force=%s, - prefix=%s, base_dir=%s, - verbose=%s, dry_run=0, +byte_compile(files, optimize=%r, force=%r, + prefix=%r, base_dir=%r, + verbose=%r, dry_run=0, direct=1) -""" % (`optimize`, `force`, `prefix`, `base_dir`, `verbose`)) +""" % (optimize, force, prefix, base_dir, verbose)) script.close() @@ -427,16 +480,13 @@ # Terminology from the py_compile module: # cfile - byte-compiled file # dfile - purported source filename (same as 'file' by default) - if sys.platform.startswith('java'): - cfile = file[:-3] + '$py.class' - else: - cfile = file + (__debug__ and "c" or "o") + cfile = file + (__debug__ and "c" or "o") dfile = file if prefix: if file[:len(prefix)] != prefix: raise ValueError, \ - ("invalid prefix: filename %s doesn't start with %s" - % (`file`, `prefix`)) + ("invalid prefix: filename %r doesn't start with %r" + % (file, prefix)) dfile = dfile[len(prefix):] if base_dir: dfile = os.path.join(base_dir, dfile) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |