Commit 5b7e9d76 authored by Collin Winter's avatar Collin Winter

General cleanup, raise normalization in Lib/distutils.

parent a73bfee7
...@@ -8,8 +8,6 @@ used from a setup script as ...@@ -8,8 +8,6 @@ used from a setup script as
setup (...) setup (...)
""" """
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
# Distutils version # Distutils version
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
Utility functions for creating archive files (tarballs, zip files, Utility functions for creating archive files (tarballs, zip files,
that sort of thing).""" that sort of thing)."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -39,8 +37,8 @@ def make_tarball (base_name, base_dir, compress="gzip", ...@@ -39,8 +37,8 @@ def make_tarball (base_name, base_dir, compress="gzip",
'bzip2': ['-f9']} 'bzip2': ['-f9']}
if compress is not None and compress not in compress_ext.keys(): if compress is not None and compress not in compress_ext.keys():
raise ValueError, \ raise ValueError(
"bad value for 'compress': must be None, 'gzip', or 'compress'" "bad value for 'compress': must be None, 'gzip', or 'compress'")
archive_name = base_name + ".tar" archive_name = base_name + ".tar"
mkpath(os.path.dirname(archive_name), dry_run=dry_run) mkpath(os.path.dirname(archive_name), dry_run=dry_run)
...@@ -86,10 +84,9 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): ...@@ -86,10 +84,9 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
except DistutilsExecError: except DistutilsExecError:
# XXX really should distinguish between "couldn't find # XXX really should distinguish between "couldn't find
# external 'zip' command" and "zip failed". # external 'zip' command" and "zip failed".
raise DistutilsExecError, \ raise DistutilsExecError(("unable to create zip file '%s': "
("unable to create zip file '%s': "
"could neither import the 'zipfile' module nor " "could neither import the 'zipfile' module nor "
"find a standalone zip utility") % zip_filename "find a standalone zip utility") % zip_filename)
else: else:
log.info("creating '%s' and adding '%s' to it", log.info("creating '%s' and adding '%s' to it",
...@@ -157,7 +154,7 @@ def make_archive (base_name, format, ...@@ -157,7 +154,7 @@ def make_archive (base_name, format,
try: try:
format_info = ARCHIVE_FORMATS[format] format_info = ARCHIVE_FORMATS[format]
except KeyError: except KeyError:
raise ValueError, "unknown archive format '%s'" % format raise ValueError("unknown archive format '%s'" % format)
func = format_info[0] func = format_info[0]
for (arg,val) in format_info[1]: for (arg,val) in format_info[1]:
......
...@@ -11,8 +11,6 @@ for the Borland C++ compiler. ...@@ -11,8 +11,6 @@ for the Borland C++ compiler.
# someone should sit down and factor out the common code as # someone should sit down and factor out the common code as
# WindowsCCompiler! --GPW # WindowsCCompiler! --GPW
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
...@@ -116,7 +114,7 @@ class BCPPCompiler(CCompiler) : ...@@ -116,7 +114,7 @@ class BCPPCompiler(CCompiler) :
try: try:
self.spawn (["brcc32", "-fo", obj, src]) self.spawn (["brcc32", "-fo", obj, src])
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
continue # the 'for' loop continue # the 'for' loop
# The next two are both for the real compiler. # The next two are both for the real compiler.
...@@ -140,7 +138,7 @@ class BCPPCompiler(CCompiler) : ...@@ -140,7 +138,7 @@ class BCPPCompiler(CCompiler) :
[input_opt, output_opt] + [input_opt, output_opt] +
extra_postargs + [src]) extra_postargs + [src])
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
return objects return objects
...@@ -165,7 +163,7 @@ class BCPPCompiler(CCompiler) : ...@@ -165,7 +163,7 @@ class BCPPCompiler(CCompiler) :
try: try:
self.spawn ([self.lib] + lib_args) self.spawn ([self.lib] + lib_args)
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise LibError, msg raise LibError(msg)
else: else:
log.debug("skipping %s (up-to-date)", output_filename) log.debug("skipping %s (up-to-date)", output_filename)
...@@ -299,7 +297,7 @@ class BCPPCompiler(CCompiler) : ...@@ -299,7 +297,7 @@ class BCPPCompiler(CCompiler) :
try: try:
self.spawn ([self.linker] + ld_args) self.spawn ([self.linker] + ld_args)
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise LinkError, msg raise LinkError(msg)
else: else:
log.debug("skipping %s (up-to-date)", output_filename) log.debug("skipping %s (up-to-date)", output_filename)
...@@ -345,9 +343,8 @@ class BCPPCompiler(CCompiler) : ...@@ -345,9 +343,8 @@ class BCPPCompiler(CCompiler) :
# use normcase to make sure '.rc' is really '.rc' and not '.RC' # use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name)) (base, ext) = os.path.splitext (os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc','.res']): if ext not in (self.src_extensions + ['.rc','.res']):
raise UnknownFileError, \ raise UnknownFileError("unknown file type '%s' (from '%s')" % \
"unknown file type '%s' (from '%s')" % \ (ext, src_name))
(ext, src_name)
if strip_dir: if strip_dir:
base = os.path.basename (base) base = os.path.basename (base)
if ext == '.res': if ext == '.res':
...@@ -393,6 +390,6 @@ class BCPPCompiler(CCompiler) : ...@@ -393,6 +390,6 @@ class BCPPCompiler(CCompiler) :
self.spawn(pp_args) self.spawn(pp_args)
except DistutilsExecError as msg: except DistutilsExecError as msg:
print(msg) print(msg)
raise CompileError, msg raise CompileError(msg)
# preprocess() # preprocess()
This diff is collapsed.
This diff is collapsed.
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
Package containing implementation of all the standard Distutils Package containing implementation of all the standard Distutils
commands.""" commands."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
__all__ = ['build', __all__ = ['build',
......
...@@ -3,22 +3,19 @@ ...@@ -3,22 +3,19 @@
Implements the Distutils 'bdist' command (create a built [binary] Implements the Distutils 'bdist' command (create a built [binary]
distribution).""" distribution)."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from types import *
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.util import get_platform from distutils.util import get_platform
def show_formats (): def show_formats():
"""Print list of available formats (arguments to "--format" option). """Print list of available formats (arguments to "--format" option).
""" """
from distutils.fancy_getopt import FancyGetopt from distutils.fancy_getopt import FancyGetopt
formats=[] formats = []
for format in bdist.format_commands: for format in bdist.format_commands:
formats.append(("formats=" + format, None, formats.append(("formats=" + format, None,
bdist.format_command[format][1])) bdist.format_command[format][1]))
...@@ -26,7 +23,7 @@ def show_formats (): ...@@ -26,7 +23,7 @@ def show_formats ():
pretty_printer.print_help("List of available distribution formats:") pretty_printer.print_help("List of available distribution formats:")
class bdist (Command): class bdist(Command):
description = "create a built (binary) distribution" description = "create a built (binary) distribution"
...@@ -84,17 +81,14 @@ class bdist (Command): ...@@ -84,17 +81,14 @@ class bdist (Command):
} }
def initialize_options (self): def initialize_options(self):
self.bdist_base = None self.bdist_base = None
self.plat_name = None self.plat_name = None
self.formats = None self.formats = None
self.dist_dir = None self.dist_dir = None
self.skip_build = 0 self.skip_build = 0
# initialize_options() def finalize_options(self):
def finalize_options (self):
# have to finalize 'plat_name' before 'bdist_base' # have to finalize 'plat_name' before 'bdist_base'
if self.plat_name is None: if self.plat_name is None:
self.plat_name = get_platform() self.plat_name = get_platform()
...@@ -112,25 +106,21 @@ class bdist (Command): ...@@ -112,25 +106,21 @@ class bdist (Command):
try: try:
self.formats = [self.default_format[os.name]] self.formats = [self.default_format[os.name]]
except KeyError: except KeyError:
raise DistutilsPlatformError, \ raise DistutilsPlatformError(
"don't know how to create built distributions " + \ "don't know how to create built distributions "
"on platform %s" % os.name "on platform %s" % os.name)
if self.dist_dir is None: if self.dist_dir is None:
self.dist_dir = "dist" self.dist_dir = "dist"
# finalize_options() def run(self):
def run (self):
# Figure out which sub-commands we need to run. # Figure out which sub-commands we need to run.
commands = [] commands = []
for format in self.formats: for format in self.formats:
try: try:
commands.append(self.format_command[format][0]) commands.append(self.format_command[format][0])
except KeyError: except KeyError:
raise DistutilsOptionError, "invalid format '%s'" % format raise DistutilsOptionError("invalid format '%s'" % format)
# Reinitialize and run each command. # Reinitialize and run each command.
for i in range(len(self.formats)): for i in range(len(self.formats)):
...@@ -144,7 +134,3 @@ class bdist (Command): ...@@ -144,7 +134,3 @@ class bdist (Command):
if cmd_name in commands[i+1:]: if cmd_name in commands[i+1:]:
sub_cmd.keep_temp = 1 sub_cmd.keep_temp = 1
self.run_command(cmd_name) self.run_command(cmd_name)
# run()
# class bdist
...@@ -4,8 +4,6 @@ Implements the Distutils 'bdist_dumb' command (create a "dumb" built ...@@ -4,8 +4,6 @@ Implements the Distutils 'bdist_dumb' command (create a "dumb" built
distribution -- i.e., just an archive to be unpacked under $prefix or distribution -- i.e., just an archive to be unpacked under $prefix or
$exec_prefix).""" $exec_prefix)."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -16,7 +14,7 @@ from distutils.errors import * ...@@ -16,7 +14,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version from distutils.sysconfig import get_python_version
from distutils import log from distutils import log
class bdist_dumb (Command): class bdist_dumb(Command):
description = "create a \"dumb\" built distribution" description = "create a \"dumb\" built distribution"
...@@ -45,8 +43,7 @@ class bdist_dumb (Command): ...@@ -45,8 +43,7 @@ class bdist_dumb (Command):
'nt': 'zip', 'nt': 'zip',
'os2': 'zip' } 'os2': 'zip' }
def initialize_options(self):
def initialize_options (self):
self.bdist_dir = None self.bdist_dir = None
self.plat_name = None self.plat_name = None
self.format = None self.format = None
...@@ -55,11 +52,7 @@ class bdist_dumb (Command): ...@@ -55,11 +52,7 @@ class bdist_dumb (Command):
self.skip_build = 0 self.skip_build = 0
self.relative = 0 self.relative = 0
# initialize_options() def finalize_options(self):
def finalize_options (self):
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'dumb') self.bdist_dir = os.path.join(bdist_base, 'dumb')
...@@ -68,19 +61,15 @@ class bdist_dumb (Command): ...@@ -68,19 +61,15 @@ class bdist_dumb (Command):
try: try:
self.format = self.default_format[os.name] self.format = self.default_format[os.name]
except KeyError: except KeyError:
raise DistutilsPlatformError, \ raise DistutilsPlatformError(
("don't know how to create dumb built distributions " + "don't know how to create dumb built distributions "
"on platform %s") % os.name "on platform %s" % os.name)
self.set_undefined_options('bdist', self.set_undefined_options('bdist',
('dist_dir', 'dist_dir'), ('dist_dir', 'dist_dir'),
('plat_name', 'plat_name')) ('plat_name', 'plat_name'))
# finalize_options() def run(self):
def run (self):
if not self.skip_build: if not self.skip_build:
self.run_command('build') self.run_command('build')
...@@ -108,8 +97,8 @@ class bdist_dumb (Command): ...@@ -108,8 +97,8 @@ class bdist_dumb (Command):
else: else:
if (self.distribution.has_ext_modules() and if (self.distribution.has_ext_modules() and
(install.install_base != install.install_platbase)): (install.install_base != install.install_platbase)):
raise DistutilsPlatformError, \ raise DistutilsPlatformError(
("can't make a dumb built distribution where " "can't make a dumb built distribution where "
"base and platbase are different (%s, %s)" "base and platbase are different (%s, %s)"
% (repr(install.install_base), % (repr(install.install_base),
repr(install.install_platbase))) repr(install.install_platbase)))
...@@ -129,7 +118,3 @@ class bdist_dumb (Command): ...@@ -129,7 +118,3 @@ class bdist_dumb (Command):
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
# run()
# class bdist_dumb
...@@ -81,7 +81,7 @@ class PyDialog(Dialog): ...@@ -81,7 +81,7 @@ class PyDialog(Dialog):
Return the button, so that events can be associated""" Return the button, so that events can be associated"""
return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next) return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next)
class bdist_msi (Command): class bdist_msi(Command):
description = "create a Microsoft Installer (.msi) binary distribution" description = "create a Microsoft Installer (.msi) binary distribution"
...@@ -114,7 +114,7 @@ class bdist_msi (Command): ...@@ -114,7 +114,7 @@ class bdist_msi (Command):
boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize', boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
'skip-build'] 'skip-build']
def initialize_options (self): def initialize_options(self):
self.bdist_dir = None self.bdist_dir = None
self.keep_temp = 0 self.keep_temp = 0
self.no_target_compile = 0 self.no_target_compile = 0
...@@ -125,7 +125,7 @@ class bdist_msi (Command): ...@@ -125,7 +125,7 @@ class bdist_msi (Command):
self.install_script = None self.install_script = None
self.pre_install_script = None self.pre_install_script = None
def finalize_options (self): def finalize_options(self):
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'msi') self.bdist_dir = os.path.join(bdist_base, 'msi')
...@@ -133,30 +133,29 @@ class bdist_msi (Command): ...@@ -133,30 +133,29 @@ class bdist_msi (Command):
if self.target_version: if self.target_version:
if not self.skip_build and self.distribution.has_ext_modules()\ if not self.skip_build and self.distribution.has_ext_modules()\
and self.target_version != short_version: and self.target_version != short_version:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"target version can only be %s, or the '--skip_build'" \ "target version can only be %s, or the '--skip_build'"
" option must be specified" % (short_version,) " option must be specified" % (short_version,))
else: else:
self.target_version = short_version self.target_version = short_version
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
if self.pre_install_script: if self.pre_install_script:
raise DistutilsOptionError, "the pre-install-script feature is not yet implemented" raise DistutilsOptionError(
"the pre-install-script feature is not yet implemented")
if self.install_script: if self.install_script:
for script in self.distribution.scripts: for script in self.distribution.scripts:
if self.install_script == os.path.basename(script): if self.install_script == os.path.basename(script):
break break
else: else:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"install_script '%s' not found in scripts" % \ "install_script '%s' not found in scripts"
self.install_script % self.install_script)
self.install_script_key = None self.install_script_key = None
# finalize_options()
def run(self):
def run (self):
if not self.skip_build: if not self.skip_build:
self.run_command('build') self.run_command('build')
...@@ -263,7 +262,8 @@ class bdist_msi (Command): ...@@ -263,7 +262,8 @@ class bdist_msi (Command):
key = dir.add_file(file) key = dir.add_file(file)
if file==self.install_script: if file==self.install_script:
if self.install_script_key: if self.install_script_key:
raise DistutilsOptionError, "Multiple files with name %s" % file raise DistutilsOptionError(
"Multiple files with name %s" % file)
self.install_script_key = '[#%s]' % key self.install_script_key = '[#%s]' % key
cab.commit(db) cab.commit(db)
......
...@@ -3,13 +3,10 @@ ...@@ -3,13 +3,10 @@
Implements the Distutils 'bdist_rpm' command (create RPM source and binary Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions).""" distributions)."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
import glob import glob
from types import *
from distutils.core import Command from distutils.core import Command
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.util import get_platform from distutils.util import get_platform
...@@ -18,7 +15,7 @@ from distutils.errors import * ...@@ -18,7 +15,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version from distutils.sysconfig import get_python_version
from distutils import log from distutils import log
class bdist_rpm (Command): class bdist_rpm(Command):
description = "create an RPM distribution" description = "create an RPM distribution"
...@@ -136,7 +133,7 @@ class bdist_rpm (Command): ...@@ -136,7 +133,7 @@ class bdist_rpm (Command):
'rpm2-mode': 'rpm3-mode'} 'rpm2-mode': 'rpm3-mode'}
def initialize_options (self): def initialize_options(self):
self.bdist_base = None self.bdist_base = None
self.rpm_base = None self.rpm_base = None
self.dist_dir = None self.dist_dir = None
...@@ -180,15 +177,12 @@ class bdist_rpm (Command): ...@@ -180,15 +177,12 @@ class bdist_rpm (Command):
self.force_arch = None self.force_arch = None
# initialize_options() def finalize_options(self):
def finalize_options (self):
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base')) self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
if self.rpm_base is None: if self.rpm_base is None:
if not self.rpm3_mode: if not self.rpm3_mode:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"you must specify --rpm-base in RPM 2 mode" "you must specify --rpm-base in RPM 2 mode")
self.rpm_base = os.path.join(self.bdist_base, "rpm") self.rpm_base = os.path.join(self.bdist_base, "rpm")
if self.python is None: if self.python is None:
...@@ -197,16 +191,15 @@ class bdist_rpm (Command): ...@@ -197,16 +191,15 @@ class bdist_rpm (Command):
else: else:
self.python = "python" self.python = "python"
elif self.fix_python: elif self.fix_python:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"--python and --fix-python are mutually exclusive options" "--python and --fix-python are mutually exclusive options")
if os.name != 'posix': if os.name != 'posix':
raise DistutilsPlatformError, \ raise DistutilsPlatformError("don't know how to create RPM "
("don't know how to create RPM "
"distributions on platform %s" % os.name) "distributions on platform %s" % os.name)
if self.binary_only and self.source_only: if self.binary_only and self.source_only:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"cannot supply both '--source-only' and '--binary-only'" "cannot supply both '--source-only' and '--binary-only'")
# don't pass CFLAGS to pure python distributions # don't pass CFLAGS to pure python distributions
if not self.distribution.has_ext_modules(): if not self.distribution.has_ext_modules():
...@@ -215,16 +208,14 @@ class bdist_rpm (Command): ...@@ -215,16 +208,14 @@ class bdist_rpm (Command):
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
self.finalize_package_data() self.finalize_package_data()
# finalize_options() def finalize_package_data(self):
def finalize_package_data (self):
self.ensure_string('group', "Development/Libraries") self.ensure_string('group', "Development/Libraries")
self.ensure_string('vendor', self.ensure_string('vendor',
"%s <%s>" % (self.distribution.get_contact(), "%s <%s>" % (self.distribution.get_contact(),
self.distribution.get_contact_email())) self.distribution.get_contact_email()))
self.ensure_string('packager') self.ensure_string('packager')
self.ensure_string_list('doc_files') self.ensure_string_list('doc_files')
if type(self.doc_files) is ListType: if isinstance(self.doc_files, list):
for readme in ('README', 'README.txt'): for readme in ('README', 'README.txt'):
if os.path.exists(readme) and readme not in self.doc_files: if os.path.exists(readme) and readme not in self.doc_files:
self.doc_files.append(readme) self.doc_files.append(readme)
...@@ -261,11 +252,8 @@ class bdist_rpm (Command): ...@@ -261,11 +252,8 @@ class bdist_rpm (Command):
self.ensure_string_list('obsoletes') self.ensure_string_list('obsoletes')
self.ensure_string('force_arch') self.ensure_string('force_arch')
# finalize_package_data ()
def run (self):
def run(self):
if DEBUG: if DEBUG:
print("before _get_package_data():") print("before _get_package_data():")
print("vendor =", self.vendor) print("vendor =", self.vendor)
...@@ -315,9 +303,8 @@ class bdist_rpm (Command): ...@@ -315,9 +303,8 @@ class bdist_rpm (Command):
if os.path.exists(self.icon): if os.path.exists(self.icon):
self.copy_file(self.icon, source_dir) self.copy_file(self.icon, source_dir)
else: else:
raise DistutilsFileError, \ raise DistutilsFileError(
"icon file '%s' does not exist" % self.icon "icon file '%s' does not exist" % self.icon)
# build package # build package
log.info("building RPMs") log.info("building RPMs")
...@@ -350,7 +337,7 @@ class bdist_rpm (Command): ...@@ -350,7 +337,7 @@ class bdist_rpm (Command):
out = os.popen(q_cmd) out = os.popen(q_cmd)
binary_rpms = [] binary_rpms = []
source_rpm = None source_rpm = None
while 1: while True:
line = out.readline() line = out.readline()
if not line: if not line:
break break
...@@ -378,7 +365,6 @@ class bdist_rpm (Command): ...@@ -378,7 +365,6 @@ class bdist_rpm (Command):
rpm = os.path.join(rpm_dir['RPMS'], rpm) rpm = os.path.join(rpm_dir['RPMS'], rpm)
if os.path.exists(rpm): if os.path.exists(rpm):
self.move_file(rpm, self.dist_dir) self.move_file(rpm, self.dist_dir)
# run()
def _dist_path(self, path): def _dist_path(self, path):
return os.path.join(self.dist_dir, os.path.basename(path)) return os.path.join(self.dist_dir, os.path.basename(path))
...@@ -438,7 +424,7 @@ class bdist_rpm (Command): ...@@ -438,7 +424,7 @@ class bdist_rpm (Command):
'Obsoletes', 'Obsoletes',
): ):
val = getattr(self, field.lower()) val = getattr(self, field.lower())
if type(val) is ListType: if isinstance(val, list):
spec_file.append('%s: %s' % (field, ' '.join(val))) spec_file.append('%s: %s' % (field, ' '.join(val)))
elif val is not None: elif val is not None:
spec_file.append('%s: %s' % (field, val)) spec_file.append('%s: %s' % (field, val))
...@@ -536,8 +522,6 @@ class bdist_rpm (Command): ...@@ -536,8 +522,6 @@ class bdist_rpm (Command):
return spec_file return spec_file
# _make_spec_file ()
def _format_changelog(self, changelog): def _format_changelog(self, changelog):
"""Format the changelog correctly and convert it to a list of strings """Format the changelog correctly and convert it to a list of strings
""" """
...@@ -558,7 +542,3 @@ class bdist_rpm (Command): ...@@ -558,7 +542,3 @@ class bdist_rpm (Command):
del new_changelog[0] del new_changelog[0]
return new_changelog return new_changelog
# _format_changelog()
# class bdist_rpm
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
Implements the Distutils 'bdist_wininst' command: create a windows installer Implements the Distutils 'bdist_wininst' command: create a windows installer
exe-program.""" exe-program."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
...@@ -15,7 +13,7 @@ from distutils.errors import * ...@@ -15,7 +13,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version from distutils.sysconfig import get_python_version
from distutils import log from distutils import log
class bdist_wininst (Command): class bdist_wininst(Command):
description = "create an executable installer for MS Windows" description = "create an executable installer for MS Windows"
...@@ -52,7 +50,7 @@ class bdist_wininst (Command): ...@@ -52,7 +50,7 @@ class bdist_wininst (Command):
boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize', boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
'skip-build'] 'skip-build']
def initialize_options (self): def initialize_options(self):
self.bdist_dir = None self.bdist_dir = None
self.keep_temp = 0 self.keep_temp = 0
self.no_target_compile = 0 self.no_target_compile = 0
...@@ -65,10 +63,8 @@ class bdist_wininst (Command): ...@@ -65,10 +63,8 @@ class bdist_wininst (Command):
self.install_script = None self.install_script = None
self.pre_install_script = None self.pre_install_script = None
# initialize_options()
def finalize_options (self): def finalize_options(self):
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'wininst') self.bdist_dir = os.path.join(bdist_base, 'wininst')
...@@ -77,9 +73,9 @@ class bdist_wininst (Command): ...@@ -77,9 +73,9 @@ class bdist_wininst (Command):
if not self.skip_build and self.distribution.has_ext_modules(): if not self.skip_build and self.distribution.has_ext_modules():
short_version = get_python_version() short_version = get_python_version()
if self.target_version and self.target_version != short_version: if self.target_version and self.target_version != short_version:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"target version can only be %s, or the '--skip_build'" \ "target version can only be %s, or the '--skip_build'" \
" option must be specified" % (short_version,) " option must be specified" % (short_version,))
self.target_version = short_version self.target_version = short_version
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
...@@ -89,13 +85,11 @@ class bdist_wininst (Command): ...@@ -89,13 +85,11 @@ class bdist_wininst (Command):
if self.install_script == os.path.basename(script): if self.install_script == os.path.basename(script):
break break
else: else:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"install_script '%s' not found in scripts" % \ "install_script '%s' not found in scripts"
self.install_script % self.install_script)
# finalize_options()
def run(self):
def run (self):
if (sys.platform != "win32" and if (sys.platform != "win32" and
(self.distribution.has_ext_modules() or (self.distribution.has_ext_modules() or
self.distribution.has_c_libraries())): self.distribution.has_c_libraries())):
...@@ -175,11 +169,8 @@ class bdist_wininst (Command): ...@@ -175,11 +169,8 @@ class bdist_wininst (Command):
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
# run() def get_inidata(self):
def get_inidata (self):
# Return data describing the installation. # Return data describing the installation.
lines = [] lines = []
metadata = self.distribution.metadata metadata = self.distribution.metadata
...@@ -222,9 +213,7 @@ class bdist_wininst (Command): ...@@ -222,9 +213,7 @@ class bdist_wininst (Command):
lines.append("build_info=%s" % build_info) lines.append("build_info=%s" % build_info)
return "\n".join(lines) return "\n".join(lines)
# get_inidata() def create_exe(self, arcname, fullname, bitmap=None):
def create_exe (self, arcname, fullname, bitmap=None):
import struct import struct
self.mkpath(self.dist_dir) self.mkpath(self.dist_dir)
...@@ -272,8 +261,6 @@ class bdist_wininst (Command): ...@@ -272,8 +261,6 @@ class bdist_wininst (Command):
file.write(header) file.write(header)
file.write(open(arcname, "rb").read()) file.write(open(arcname, "rb").read())
# create_exe()
def get_installer_filename(self, fullname): def get_installer_filename(self, fullname):
# Factored out to allow overriding in subclasses # Factored out to allow overriding in subclasses
if self.target_version: if self.target_version:
...@@ -286,9 +273,8 @@ class bdist_wininst (Command): ...@@ -286,9 +273,8 @@ class bdist_wininst (Command):
installer_name = os.path.join(self.dist_dir, installer_name = os.path.join(self.dist_dir,
"%s.win32.exe" % fullname) "%s.win32.exe" % fullname)
return installer_name return installer_name
# get_installer_filename()
def get_exe_bytes (self): def get_exe_bytes(self):
from distutils.msvccompiler import get_build_version from distutils.msvccompiler import get_build_version
# If a target-version other than the current version has been # If a target-version other than the current version has been
# specified, then using the MSVC version from *this* build is no good. # specified, then using the MSVC version from *this* build is no good.
...@@ -320,4 +306,3 @@ class bdist_wininst (Command): ...@@ -320,4 +306,3 @@ class bdist_wininst (Command):
# used for python. XXX What about mingw, borland, and so on? # used for python. XXX What about mingw, borland, and so on?
filename = os.path.join(directory, "wininst-%s.exe" % bv) filename = os.path.join(directory, "wininst-%s.exe" % bv)
return open(filename, "rb").read() return open(filename, "rb").read()
# class bdist_wininst
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
Implements the Distutils 'build' command.""" Implements the Distutils 'build' command."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
...@@ -11,12 +9,12 @@ from distutils.core import Command ...@@ -11,12 +9,12 @@ from distutils.core import Command
from distutils.util import get_platform from distutils.util import get_platform
def show_compilers (): def show_compilers():
from distutils.ccompiler import show_compilers from distutils.ccompiler import show_compilers
show_compilers() show_compilers()
class build (Command): class build(Command):
description = "build everything needed to install" description = "build everything needed to install"
...@@ -51,7 +49,7 @@ class build (Command): ...@@ -51,7 +49,7 @@ class build (Command):
"list available compilers", show_compilers), "list available compilers", show_compilers),
] ]
def initialize_options (self): def initialize_options(self):
self.build_base = 'build' self.build_base = 'build'
# these are decided only after 'build_base' has its final value # these are decided only after 'build_base' has its final value
# (unless overridden by the user or client) # (unless overridden by the user or client)
...@@ -65,8 +63,7 @@ class build (Command): ...@@ -65,8 +63,7 @@ class build (Command):
self.force = 0 self.force = 0
self.executable = None self.executable = None
def finalize_options (self): def finalize_options(self):
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3]) plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
# 'build_purelib' and 'build_platlib' just default to 'lib' and # 'build_purelib' and 'build_platlib' just default to 'lib' and
...@@ -98,11 +95,8 @@ class build (Command): ...@@ -98,11 +95,8 @@ class build (Command):
if self.executable is None: if self.executable is None:
self.executable = os.path.normpath(sys.executable) self.executable = os.path.normpath(sys.executable)
# finalize_options ()
def run (self):
def run(self):
# Run all relevant sub-commands. This will be some subset of: # Run all relevant sub-commands. This will be some subset of:
# - build_py - pure Python modules # - build_py - pure Python modules
# - build_clib - standalone C libraries # - build_clib - standalone C libraries
...@@ -114,16 +108,16 @@ class build (Command): ...@@ -114,16 +108,16 @@ class build (Command):
# -- Predicates for the sub-command list --------------------------- # -- Predicates for the sub-command list ---------------------------
def has_pure_modules (self): def has_pure_modules(self):
return self.distribution.has_pure_modules() return self.distribution.has_pure_modules()
def has_c_libraries (self): def has_c_libraries(self):
return self.distribution.has_c_libraries() return self.distribution.has_c_libraries()
def has_ext_modules (self): def has_ext_modules(self):
return self.distribution.has_ext_modules() return self.distribution.has_ext_modules()
def has_scripts (self): def has_scripts(self):
return self.distribution.has_scripts() return self.distribution.has_scripts()
...@@ -132,5 +126,3 @@ class build (Command): ...@@ -132,5 +126,3 @@ class build (Command):
('build_ext', has_ext_modules), ('build_ext', has_ext_modules),
('build_scripts', has_scripts), ('build_scripts', has_scripts),
] ]
# class build
...@@ -4,8 +4,6 @@ Implements the Distutils 'build_clib' command, to build a C/C++ library ...@@ -4,8 +4,6 @@ Implements the Distutils 'build_clib' command, to build a C/C++ library
that is included in the module distribution and needed by an extension that is included in the module distribution and needed by an extension
module.""" module."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
...@@ -19,18 +17,17 @@ __revision__ = "$Id$" ...@@ -19,18 +17,17 @@ __revision__ = "$Id$"
# cut 'n paste. Sigh. # cut 'n paste. Sigh.
import os import os
from types import *
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.sysconfig import customize_compiler from distutils.sysconfig import customize_compiler
from distutils import log from distutils import log
def show_compilers (): def show_compilers():
from distutils.ccompiler import show_compilers from distutils.ccompiler import show_compilers
show_compilers() show_compilers()
class build_clib (Command): class build_clib(Command):
description = "build C/C++ libraries used by Python extensions" description = "build C/C++ libraries used by Python extensions"
...@@ -54,7 +51,7 @@ class build_clib (Command): ...@@ -54,7 +51,7 @@ class build_clib (Command):
"list available compilers", show_compilers), "list available compilers", show_compilers),
] ]
def initialize_options (self): def initialize_options(self):
self.build_clib = None self.build_clib = None
self.build_temp = None self.build_temp = None
...@@ -69,11 +66,8 @@ class build_clib (Command): ...@@ -69,11 +66,8 @@ class build_clib (Command):
self.force = 0 self.force = 0
self.compiler = None self.compiler = None
# initialize_options()
def finalize_options (self):
def finalize_options(self):
# This might be confusing: both build-clib and build-temp default # This might be confusing: both build-clib and build-temp default
# to build-temp as defined by the "build" command. This is because # to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build # I think that C libraries are really just temporary build
...@@ -98,11 +92,8 @@ class build_clib (Command): ...@@ -98,11 +92,8 @@ class build_clib (Command):
# XXX same as for build_ext -- what about 'self.define' and # XXX same as for build_ext -- what about 'self.define' and
# 'self.undef' ? # 'self.undef' ?
# finalize_options()
def run (self):
def run(self):
if not self.libraries: if not self.libraries:
return return
...@@ -125,51 +116,41 @@ class build_clib (Command): ...@@ -125,51 +116,41 @@ class build_clib (Command):
self.build_libraries(self.libraries) self.build_libraries(self.libraries)
# run()
def check_library_list(self, libraries):
def check_library_list (self, libraries):
"""Ensure that the list of libraries (presumably provided as a """Ensure that the list of libraries (presumably provided as a
command option 'libraries') is valid, i.e. it is a list of command option 'libraries') is valid, i.e. it is a list of
2-tuples, where the tuples are (library_name, build_info_dict). 2-tuples, where the tuples are (library_name, build_info_dict).
Raise DistutilsSetupError if the structure is invalid anywhere; Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise.""" just returns otherwise."""
# Yechh, blecch, ackk: this is ripped straight out of build_ext.py, # Yechh, blecch, ackk: this is ripped straight out of build_ext.py,
# with only names changed to protect the innocent! # with only names changed to protect the innocent!
if not isinstance(libraries, list):
if type(libraries) is not ListType: raise DistutilsSetupError(
raise DistutilsSetupError, \ "'libraries' option must be a list of tuples")
"'libraries' option must be a list of tuples"
for lib in libraries: for lib in libraries:
if type(lib) is not TupleType and len(lib) != 2: if not isinstance(lib, tuple) and len(lib) != 2:
raise DistutilsSetupError, \ raise DistutilsSetupError(
"each element of 'libraries' must a 2-tuple" "each element of 'libraries' must a 2-tuple")
if isinstance(lib[0], basestring): if isinstance(lib[0], basestring):
raise DistutilsSetupError, \ raise DistutilsSetupError(
"first element of each tuple in 'libraries' " + \ "first element of each tuple in 'libraries' "
"must be a string (the library name)" "must be a string (the library name)")
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]): if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
raise DistutilsSetupError, \ raise DistutilsSetupError("bad library name '%s': "
("bad library name '%s': " + "may not contain directory separators" % lib[0])
"may not contain directory separators") % \
lib[0]
if type(lib[1]) is not DictionaryType:
raise DistutilsSetupError, \
"second element of each tuple in 'libraries' " + \
"must be a dictionary (build info)"
# for lib
# check_library_list () if not isinstance(lib[1], dict):
raise DistutilsSetupError(
"second element of each tuple in 'libraries' "
"must be a dictionary (build info)")
def get_library_names (self): def get_library_names(self):
# Assume the library list is valid -- 'check_library_list()' is # Assume the library list is valid -- 'check_library_list()' is
# called from 'finalize_options()', so it should be! # called from 'finalize_options()', so it should be!
if not self.libraries: if not self.libraries:
return None return None
...@@ -178,36 +159,30 @@ class build_clib (Command): ...@@ -178,36 +159,30 @@ class build_clib (Command):
lib_names.append(lib_name) lib_names.append(lib_name)
return lib_names return lib_names
# get_library_names ()
def get_source_files (self): def get_source_files(self):
self.check_library_list(self.libraries) self.check_library_list(self.libraries)
filenames = [] filenames = []
for (lib_name, build_info) in self.libraries: for (lib_name, build_info) in self.libraries:
sources = build_info.get('sources') sources = build_info.get('sources')
if (sources is None or if sources is None or not isinstance(sources, (list, tuple)):
type(sources) not in (ListType, TupleType) ): raise DistutilsSetupError(
raise DistutilsSetupError, \ "in 'libraries' option (library '%s'), "
("in 'libraries' option (library '%s'), "
"'sources' must be present and must be " "'sources' must be present and must be "
"a list of source filenames") % lib_name "a list of source filenames" % lib_name)
filenames.extend(sources) filenames.extend(sources)
return filenames return filenames
# get_source_files ()
def build_libraries (self, libraries):
def build_libraries(self, libraries):
for (lib_name, build_info) in libraries: for (lib_name, build_info) in libraries:
sources = build_info.get('sources') sources = build_info.get('sources')
if sources is None or type(sources) not in (ListType, TupleType): if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError, \ raise DistutilsSetupError(
("in 'libraries' option (library '%s'), " + "in 'libraries' option (library '%s'), "
"'sources' must be present and must be " + "'sources' must be present and must be "
"a list of source filenames") % lib_name "a list of source filenames" % lib_name)
sources = list(sources) sources = list(sources)
log.info("building '%s' library", lib_name) log.info("building '%s' library", lib_name)
...@@ -229,9 +204,3 @@ class build_clib (Command): ...@@ -229,9 +204,3 @@ class build_clib (Command):
self.compiler.create_static_lib(objects, lib_name, self.compiler.create_static_lib(objects, lib_name,
output_dir=self.build_clib, output_dir=self.build_clib,
debug=self.debug) debug=self.debug)
# for libraries
# build_libraries ()
# class build_lib
This diff is collapsed.
This diff is collapsed.
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
Implements the Distutils 'build_scripts' command.""" Implements the Distutils 'build_scripts' command."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os, re import sys, os, re
...@@ -17,7 +15,7 @@ from distutils import log ...@@ -17,7 +15,7 @@ from distutils import log
# check if Python is called on the first line with this expression # check if Python is called on the first line with this expression
first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$') first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
class build_scripts (Command): class build_scripts(Command):
description = "\"build\" scripts (copy and fixup #! line)" description = "\"build\" scripts (copy and fixup #! line)"
...@@ -30,14 +28,14 @@ class build_scripts (Command): ...@@ -30,14 +28,14 @@ class build_scripts (Command):
boolean_options = ['force'] boolean_options = ['force']
def initialize_options (self): def initialize_options(self):
self.build_dir = None self.build_dir = None
self.scripts = None self.scripts = None
self.force = None self.force = None
self.executable = None self.executable = None
self.outfiles = None self.outfiles = None
def finalize_options (self): def finalize_options(self):
self.set_undefined_options('build', self.set_undefined_options('build',
('build_scripts', 'build_dir'), ('build_scripts', 'build_dir'),
('force', 'force'), ('force', 'force'),
...@@ -47,13 +45,13 @@ class build_scripts (Command): ...@@ -47,13 +45,13 @@ class build_scripts (Command):
def get_source_files(self): def get_source_files(self):
return self.scripts return self.scripts
def run (self): def run(self):
if not self.scripts: if not self.scripts:
return return
self.copy_scripts() self.copy_scripts()
def copy_scripts (self): def copy_scripts(self):
"""Copy each script listed in 'self.scripts'; if it's marked as a """Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re', Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first ie. starts with "\#!" and contains "python"), then adjust the first
...@@ -62,7 +60,7 @@ class build_scripts (Command): ...@@ -62,7 +60,7 @@ class build_scripts (Command):
self.mkpath(self.build_dir) self.mkpath(self.build_dir)
outfiles = [] outfiles = []
for script in self.scripts: for script in self.scripts:
adjust = 0 adjust = False
script = convert_path(script) script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.basename(script)) outfile = os.path.join(self.build_dir, os.path.basename(script))
outfiles.append(outfile) outfiles.append(outfile)
...@@ -88,7 +86,7 @@ class build_scripts (Command): ...@@ -88,7 +86,7 @@ class build_scripts (Command):
match = first_line_re.match(first_line) match = first_line_re.match(first_line)
if match: if match:
adjust = 1 adjust = True
post_interp = match.group(1) or '' post_interp = match.group(1) or ''
if adjust: if adjust:
...@@ -125,7 +123,3 @@ class build_scripts (Command): ...@@ -125,7 +123,3 @@ class build_scripts (Command):
log.info("changing mode of %s from %o to %o", log.info("changing mode of %s from %o to %o",
file, oldmode, newmode) file, oldmode, newmode)
os.chmod(file, newmode) os.chmod(file, newmode)
# copy_scripts ()
# class build_scripts
...@@ -4,8 +4,6 @@ Implements the Distutils 'clean' command.""" ...@@ -4,8 +4,6 @@ Implements the Distutils 'clean' command."""
# contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -13,7 +11,7 @@ from distutils.core import Command ...@@ -13,7 +11,7 @@ from distutils.core import Command
from distutils.dir_util import remove_tree from distutils.dir_util import remove_tree
from distutils import log from distutils import log
class clean (Command): class clean(Command):
description = "clean up temporary files from 'build' command" description = "clean up temporary files from 'build' command"
user_options = [ user_options = [
...@@ -78,5 +76,3 @@ class clean (Command): ...@@ -78,5 +76,3 @@ class clean (Command):
log.info("removing '%s'", self.build_base) log.info("removing '%s'", self.build_base)
except OSError: except OSError:
pass pass
# class clean
...@@ -10,7 +10,7 @@ __revision__ = "$Id$" ...@@ -10,7 +10,7 @@ __revision__ = "$Id$"
from distutils.core import Command from distutils.core import Command
class x (Command): class x(Command):
# Brief (40-50 characters) description of the command # Brief (40-50 characters) description of the command
description = "" description = ""
...@@ -21,25 +21,13 @@ class x (Command): ...@@ -21,25 +21,13 @@ class x (Command):
""), ""),
] ]
def initialize_options(self):
def initialize_options (self):
self. = None self. = None
self. = None self. = None
self. = None self. = None
# initialize_options() def finalize_options(self):
def finalize_options (self):
if self.x is None: if self.x is None:
self.x = self.x =
# finalize_options() def run(self):
def run (self):
# run()
# class x
This diff is collapsed.
...@@ -4,12 +4,9 @@ Implements the Distutils 'install' command.""" ...@@ -4,12 +4,9 @@ Implements the Distutils 'install' command."""
from distutils import log from distutils import log
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from types import *
from distutils.core import Command from distutils.core import Command
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.sysconfig import get_config_vars from distutils.sysconfig import get_config_vars
...@@ -141,7 +138,7 @@ class install (Command): ...@@ -141,7 +138,7 @@ class install (Command):
negative_opt = {'no-compile' : 'compile'} negative_opt = {'no-compile' : 'compile'}
def initialize_options (self): def initialize_options(self):
# High-level options: these select both an installation base # High-level options: these select both an installation base
# and scheme. # and scheme.
...@@ -215,7 +212,7 @@ class install (Command): ...@@ -215,7 +212,7 @@ class install (Command):
# party Python modules on various platforms given a wide # party Python modules on various platforms given a wide
# array of user input is decided. Yes, it's quite complex!) # array of user input is decided. Yes, it's quite complex!)
def finalize_options (self): def finalize_options(self):
# This method (and its pliant slaves, like 'finalize_unix()', # This method (and its pliant slaves, like 'finalize_unix()',
# 'finalize_other()', and 'select_scheme()') is where the default # 'finalize_other()', and 'select_scheme()') is where the default
...@@ -233,13 +230,13 @@ class install (Command): ...@@ -233,13 +230,13 @@ class install (Command):
if ((self.prefix or self.exec_prefix or self.home) and if ((self.prefix or self.exec_prefix or self.home) and
(self.install_base or self.install_platbase)): (self.install_base or self.install_platbase)):
raise DistutilsOptionError, \ raise DistutilsOptionError(
("must supply either prefix/exec-prefix/home or " + "must supply either prefix/exec-prefix/home or " +
"install-base/install-platbase -- not both") "install-base/install-platbase -- not both")
if self.home and (self.prefix or self.exec_prefix): if self.home and (self.prefix or self.exec_prefix):
raise DistutilsOptionError, \ raise DistutilsOptionError(
"must supply either home or prefix/exec-prefix -- not both" "must supply either home or prefix/exec-prefix -- not both")
# Next, stuff that's wrong (or dubious) only on certain platforms. # Next, stuff that's wrong (or dubious) only on certain platforms.
if os.name != "posix": if os.name != "posix":
...@@ -341,10 +338,8 @@ class install (Command): ...@@ -341,10 +338,8 @@ class install (Command):
# Punt on doc directories for now -- after all, we're punting on # Punt on doc directories for now -- after all, we're punting on
# documentation completely! # documentation completely!
# finalize_options ()
def dump_dirs (self, msg): def dump_dirs(self, msg):
if DEBUG: if DEBUG:
from distutils.fancy_getopt import longopt_xlate from distutils.fancy_getopt import longopt_xlate
print(msg + ":") print(msg + ":")
...@@ -362,8 +357,7 @@ class install (Command): ...@@ -362,8 +357,7 @@ class install (Command):
print(" %s: %s" % (opt_name, val)) print(" %s: %s" % (opt_name, val))
def finalize_unix (self): def finalize_unix(self):
if self.install_base is not None or self.install_platbase is not None: if self.install_base is not None or self.install_platbase is not None:
if ((self.install_lib is None and if ((self.install_lib is None and
self.install_purelib is None and self.install_purelib is None and
...@@ -371,8 +365,8 @@ class install (Command): ...@@ -371,8 +365,8 @@ class install (Command):
self.install_headers is None or self.install_headers is None or
self.install_scripts is None or self.install_scripts is None or
self.install_data is None): self.install_data is None):
raise DistutilsOptionError, \ raise DistutilsOptionError(
("install-base or install-platbase supplied, but " "install-base or install-platbase supplied, but "
"installation scheme is incomplete") "installation scheme is incomplete")
return return
...@@ -382,8 +376,8 @@ class install (Command): ...@@ -382,8 +376,8 @@ class install (Command):
else: else:
if self.prefix is None: if self.prefix is None:
if self.exec_prefix is not None: if self.exec_prefix is not None:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"must not supply exec-prefix without prefix" "must not supply exec-prefix without prefix")
self.prefix = os.path.normpath(sys.prefix) self.prefix = os.path.normpath(sys.prefix)
self.exec_prefix = os.path.normpath(sys.exec_prefix) self.exec_prefix = os.path.normpath(sys.exec_prefix)
...@@ -396,11 +390,8 @@ class install (Command): ...@@ -396,11 +390,8 @@ class install (Command):
self.install_platbase = self.exec_prefix self.install_platbase = self.exec_prefix
self.select_scheme("unix_prefix") self.select_scheme("unix_prefix")
# finalize_unix ()
def finalize_other (self): # Windows and Mac OS for now
def finalize_other(self): # Windows and Mac OS for now
if self.home is not None: if self.home is not None:
self.install_base = self.install_platbase = self.home self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home") self.select_scheme("unix_home")
...@@ -412,13 +403,11 @@ class install (Command): ...@@ -412,13 +403,11 @@ class install (Command):
try: try:
self.select_scheme(os.name) self.select_scheme(os.name)
except KeyError: except KeyError:
raise DistutilsPlatformError, \ raise DistutilsPlatformError(
"I don't know how to install stuff on '%s'" % os.name "I don't know how to install stuff on '%s'" % os.name)
# finalize_other ()
def select_scheme (self, name): def select_scheme(self, name):
# it's the caller's problem if they supply a bad name! # it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name] scheme = INSTALL_SCHEMES[name]
for key in SCHEME_KEYS: for key in SCHEME_KEYS:
...@@ -427,7 +416,7 @@ class install (Command): ...@@ -427,7 +416,7 @@ class install (Command):
setattr(self, attrname, scheme[key]) setattr(self, attrname, scheme[key])
def _expand_attrs (self, attrs): def _expand_attrs(self, attrs):
for attr in attrs: for attr in attrs:
val = getattr(self, attr) val = getattr(self, attr)
if val is not None: if val is not None:
...@@ -437,12 +426,12 @@ class install (Command): ...@@ -437,12 +426,12 @@ class install (Command):
setattr(self, attr, val) setattr(self, attr, val)
def expand_basedirs (self): def expand_basedirs(self):
self._expand_attrs(['install_base', self._expand_attrs(['install_base',
'install_platbase', 'install_platbase',
'root']) 'root'])
def expand_dirs (self): def expand_dirs(self):
self._expand_attrs(['install_purelib', self._expand_attrs(['install_purelib',
'install_platlib', 'install_platlib',
'install_lib', 'install_lib',
...@@ -451,14 +440,12 @@ class install (Command): ...@@ -451,14 +440,12 @@ class install (Command):
'install_data',]) 'install_data',])
def convert_paths (self, *names): def convert_paths(self, *names):
for name in names: for name in names:
attr = "install_" + name attr = "install_" + name
setattr(self, attr, convert_path(getattr(self, attr))) setattr(self, attr, convert_path(getattr(self, attr)))
def handle_extra_path(self):
def handle_extra_path (self):
if self.extra_path is None: if self.extra_path is None:
self.extra_path = self.distribution.extra_path self.extra_path = self.distribution.extra_path
...@@ -471,8 +458,8 @@ class install (Command): ...@@ -471,8 +458,8 @@ class install (Command):
elif len(self.extra_path) == 2: elif len(self.extra_path) == 2:
(path_file, extra_dirs) = self.extra_path (path_file, extra_dirs) = self.extra_path
else: else:
raise DistutilsOptionError, \ raise DistutilsOptionError(
("'extra_path' option must be a list, tuple, or " "'extra_path' option must be a list, tuple, or "
"comma-separated string with 1 or 2 elements") "comma-separated string with 1 or 2 elements")
# convert to local form in case Unix notation used (as it # convert to local form in case Unix notation used (as it
...@@ -488,10 +475,7 @@ class install (Command): ...@@ -488,10 +475,7 @@ class install (Command):
self.path_file = path_file self.path_file = path_file
self.extra_dirs = extra_dirs self.extra_dirs = extra_dirs
# handle_extra_path () def change_roots(self, *names):
def change_roots (self, *names):
for name in names: for name in names:
attr = "install_" + name attr = "install_" + name
setattr(self, attr, change_root(self.root, getattr(self, attr))) setattr(self, attr, change_root(self.root, getattr(self, attr)))
...@@ -499,8 +483,7 @@ class install (Command): ...@@ -499,8 +483,7 @@ class install (Command):
# -- Command execution methods ------------------------------------- # -- Command execution methods -------------------------------------
def run (self): def run(self):
# Obviously have to build before we can install # Obviously have to build before we can install
if not self.skip_build: if not self.skip_build:
self.run_command('build') self.run_command('build')
...@@ -535,9 +518,7 @@ class install (Command): ...@@ -535,9 +518,7 @@ class install (Command):
"you'll have to change the search path yourself"), "you'll have to change the search path yourself"),
self.install_lib) self.install_lib)
# run () def create_path_file(self):
def create_path_file (self):
filename = os.path.join(self.install_libbase, filename = os.path.join(self.install_libbase,
self.path_file + ".pth") self.path_file + ".pth")
if self.install_path_file: if self.install_path_file:
...@@ -550,7 +531,7 @@ class install (Command): ...@@ -550,7 +531,7 @@ class install (Command):
# -- Reporting methods --------------------------------------------- # -- Reporting methods ---------------------------------------------
def get_outputs (self): def get_outputs(self):
# Assemble the outputs of all the sub-commands. # Assemble the outputs of all the sub-commands.
outputs = [] outputs = []
for cmd_name in self.get_sub_commands(): for cmd_name in self.get_sub_commands():
...@@ -567,7 +548,7 @@ class install (Command): ...@@ -567,7 +548,7 @@ class install (Command):
return outputs return outputs
def get_inputs (self): def get_inputs(self):
# XXX gee, this looks familiar ;-( # XXX gee, this looks familiar ;-(
inputs = [] inputs = []
for cmd_name in self.get_sub_commands(): for cmd_name in self.get_sub_commands():
...@@ -579,19 +560,19 @@ class install (Command): ...@@ -579,19 +560,19 @@ class install (Command):
# -- Predicates for sub-command list ------------------------------- # -- Predicates for sub-command list -------------------------------
def has_lib (self): def has_lib(self):
"""Return true if the current distribution has any Python """Return true if the current distribution has any Python
modules to install.""" modules to install."""
return (self.distribution.has_pure_modules() or return (self.distribution.has_pure_modules() or
self.distribution.has_ext_modules()) self.distribution.has_ext_modules())
def has_headers (self): def has_headers(self):
return self.distribution.has_headers() return self.distribution.has_headers()
def has_scripts (self): def has_scripts(self):
return self.distribution.has_scripts() return self.distribution.has_scripts()
def has_data (self): def has_data(self):
return self.distribution.has_data_files() return self.distribution.has_data_files()
...@@ -603,5 +584,3 @@ class install (Command): ...@@ -603,5 +584,3 @@ class install (Command):
('install_data', has_data), ('install_data', has_data),
('install_egg_info', lambda self:True), ('install_egg_info', lambda self:True),
] ]
# class install
...@@ -5,15 +5,13 @@ platform-independent data files.""" ...@@ -5,15 +5,13 @@ platform-independent data files."""
# contributed by Bastian Kleineidam # contributed by Bastian Kleineidam
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from distutils.core import Command from distutils.core import Command
from distutils.util import change_root, convert_path from distutils.util import change_root, convert_path
class install_data (Command): class install_data(Command):
description = "install data files" description = "install data files"
...@@ -28,7 +26,7 @@ class install_data (Command): ...@@ -28,7 +26,7 @@ class install_data (Command):
boolean_options = ['force'] boolean_options = ['force']
def initialize_options (self): def initialize_options(self):
self.install_dir = None self.install_dir = None
self.outfiles = [] self.outfiles = []
self.root = None self.root = None
...@@ -37,14 +35,14 @@ class install_data (Command): ...@@ -37,14 +35,14 @@ class install_data (Command):
self.data_files = self.distribution.data_files self.data_files = self.distribution.data_files
self.warn_dir = 1 self.warn_dir = 1
def finalize_options (self): def finalize_options(self):
self.set_undefined_options('install', self.set_undefined_options('install',
('install_data', 'install_dir'), ('install_data', 'install_dir'),
('root', 'root'), ('root', 'root'),
('force', 'force'), ('force', 'force'),
) )
def run (self): def run(self):
self.mkpath(self.install_dir) self.mkpath(self.install_dir)
for f in self.data_files: for f in self.data_files:
if isinstance(f, basestring): if isinstance(f, basestring):
...@@ -77,8 +75,8 @@ class install_data (Command): ...@@ -77,8 +75,8 @@ class install_data (Command):
(out, _) = self.copy_file(data, dir) (out, _) = self.copy_file(data, dir)
self.outfiles.append(out) self.outfiles.append(out)
def get_inputs (self): def get_inputs(self):
return self.data_files or [] return self.data_files or []
def get_outputs (self): def get_outputs(self):
return self.outfiles return self.outfiles
...@@ -3,15 +3,13 @@ ...@@ -3,15 +3,13 @@
Implements the Distutils 'install_headers' command, to install C/C++ header Implements the Distutils 'install_headers' command, to install C/C++ header
files to the Python include directory.""" files to the Python include directory."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from distutils.core import Command from distutils.core import Command
class install_headers (Command): class install_headers(Command):
description = "install C/C++ header files" description = "install C/C++ header files"
...@@ -23,18 +21,18 @@ class install_headers (Command): ...@@ -23,18 +21,18 @@ class install_headers (Command):
boolean_options = ['force'] boolean_options = ['force']
def initialize_options (self): def initialize_options(self):
self.install_dir = None self.install_dir = None
self.force = 0 self.force = 0
self.outfiles = [] self.outfiles = []
def finalize_options (self): def finalize_options(self):
self.set_undefined_options('install', self.set_undefined_options('install',
('install_headers', 'install_dir'), ('install_headers', 'install_dir'),
('force', 'force')) ('force', 'force'))
def run (self): def run(self):
headers = self.distribution.headers headers = self.distribution.headers
if not headers: if not headers:
return return
...@@ -44,10 +42,8 @@ class install_headers (Command): ...@@ -44,10 +42,8 @@ class install_headers (Command):
(out, _) = self.copy_file(header, self.install_dir) (out, _) = self.copy_file(header, self.install_dir)
self.outfiles.append(out) self.outfiles.append(out)
def get_inputs (self): def get_inputs(self):
return self.distribution.headers or [] return self.distribution.headers or []
def get_outputs (self): def get_outputs(self):
return self.outfiles return self.outfiles
# class install_headers
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from types import IntType
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
...@@ -11,7 +8,7 @@ from distutils.errors import DistutilsOptionError ...@@ -11,7 +8,7 @@ from distutils.errors import DistutilsOptionError
# Extension for Python source files. # Extension for Python source files.
PYTHON_SOURCE_EXTENSION = ".py" PYTHON_SOURCE_EXTENSION = ".py"
class install_lib (Command): class install_lib(Command):
description = "install all Python modules (extensions and pure Python)" description = "install all Python modules (extensions and pure Python)"
...@@ -45,8 +42,7 @@ class install_lib (Command): ...@@ -45,8 +42,7 @@ class install_lib (Command):
boolean_options = ['force', 'compile', 'skip-build'] boolean_options = ['force', 'compile', 'skip-build']
negative_opt = {'no-compile' : 'compile'} negative_opt = {'no-compile' : 'compile'}
def initialize_options(self):
def initialize_options (self):
# let the 'install' command dictate our installation directory # let the 'install' command dictate our installation directory
self.install_dir = None self.install_dir = None
self.build_dir = None self.build_dir = None
...@@ -55,7 +51,7 @@ class install_lib (Command): ...@@ -55,7 +51,7 @@ class install_lib (Command):
self.optimize = None self.optimize = None
self.skip_build = None self.skip_build = None
def finalize_options (self): def finalize_options(self):
# Get all the information we need to install pure Python modules # Get all the information we need to install pure Python modules
# from the umbrella 'install' command -- build (source) directory, # from the umbrella 'install' command -- build (source) directory,
...@@ -70,19 +66,18 @@ class install_lib (Command): ...@@ -70,19 +66,18 @@ class install_lib (Command):
) )
if self.compile is None: if self.compile is None:
self.compile = 1 self.compile = True
if self.optimize is None: if self.optimize is None:
self.optimize = 0 self.optimize = False
if type(self.optimize) is not IntType: if not isinstance(self.optimize, int):
try: try:
self.optimize = int(self.optimize) self.optimize = int(self.optimize)
assert 0 <= self.optimize <= 2 assert 0 <= self.optimize <= 2
except (ValueError, AssertionError): except (ValueError, AssertionError):
raise DistutilsOptionError, "optimize must be 0, 1, or 2" raise DistutilsOptionError("optimize must be 0, 1, or 2")
def run (self):
def run(self):
# Make sure we have built everything we need first # Make sure we have built everything we need first
self.build() self.build()
...@@ -95,20 +90,18 @@ class install_lib (Command): ...@@ -95,20 +90,18 @@ class install_lib (Command):
if outfiles is not None and self.distribution.has_pure_modules(): if outfiles is not None and self.distribution.has_pure_modules():
self.byte_compile(outfiles) self.byte_compile(outfiles)
# run ()
# -- Top-level worker functions ------------------------------------ # -- Top-level worker functions ------------------------------------
# (called from 'run()') # (called from 'run()')
def build (self): def build(self):
if not self.skip_build: if not self.skip_build:
if self.distribution.has_pure_modules(): if self.distribution.has_pure_modules():
self.run_command('build_py') self.run_command('build_py')
if self.distribution.has_ext_modules(): if self.distribution.has_ext_modules():
self.run_command('build_ext') self.run_command('build_ext')
def install (self): def install(self):
if os.path.isdir(self.build_dir): if os.path.isdir(self.build_dir):
outfiles = self.copy_tree(self.build_dir, self.install_dir) outfiles = self.copy_tree(self.build_dir, self.install_dir)
else: else:
...@@ -117,7 +110,7 @@ class install_lib (Command): ...@@ -117,7 +110,7 @@ class install_lib (Command):
return return
return outfiles return outfiles
def byte_compile (self, files): def byte_compile(self, files):
from distutils.util import byte_compile from distutils.util import byte_compile
# Get the "--root" directory supplied to the "install" command, # Get the "--root" directory supplied to the "install" command,
...@@ -138,8 +131,7 @@ class install_lib (Command): ...@@ -138,8 +131,7 @@ class install_lib (Command):
# -- Utility methods ----------------------------------------------- # -- Utility methods -----------------------------------------------
def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir): def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
if not has_any: if not has_any:
return [] return []
...@@ -154,9 +146,7 @@ class install_lib (Command): ...@@ -154,9 +146,7 @@ class install_lib (Command):
return outputs return outputs
# _mutate_outputs () def _bytecode_filenames(self, py_filenames):
def _bytecode_filenames (self, py_filenames):
bytecode_files = [] bytecode_files = []
for py_file in py_filenames: for py_file in py_filenames:
# Since build_py handles package data installation, the # Since build_py handles package data installation, the
...@@ -176,7 +166,7 @@ class install_lib (Command): ...@@ -176,7 +166,7 @@ class install_lib (Command):
# -- External interface -------------------------------------------- # -- External interface --------------------------------------------
# (called by outsiders) # (called by outsiders)
def get_outputs (self): def get_outputs(self):
"""Return the list of files that would be installed if this command """Return the list of files that would be installed if this command
were actually run. Not affected by the "dry-run" flag or whether were actually run. Not affected by the "dry-run" flag or whether
modules have actually been built yet. modules have actually been built yet.
...@@ -197,9 +187,7 @@ class install_lib (Command): ...@@ -197,9 +187,7 @@ class install_lib (Command):
return pure_outputs + bytecode_outputs + ext_outputs return pure_outputs + bytecode_outputs + ext_outputs
# get_outputs () def get_inputs(self):
def get_inputs (self):
"""Get the list of files that are input to this command, ie. the """Get the list of files that are input to this command, ie. the
files that get installed as they are named in the build tree. files that get installed as they are named in the build tree.
The files in this list correspond one-to-one to the output The files in this list correspond one-to-one to the output
...@@ -216,5 +204,3 @@ class install_lib (Command): ...@@ -216,5 +204,3 @@ class install_lib (Command):
inputs.extend(build_ext.get_outputs()) inputs.extend(build_ext.get_outputs())
return inputs return inputs
# class install_lib
...@@ -5,8 +5,6 @@ Python scripts.""" ...@@ -5,8 +5,6 @@ Python scripts."""
# contributed by Bastian Kleineidam # contributed by Bastian Kleineidam
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -14,7 +12,8 @@ from distutils.core import Command ...@@ -14,7 +12,8 @@ from distutils.core import Command
from distutils import log from distutils import log
from stat import ST_MODE from stat import ST_MODE
class install_scripts (Command):
class install_scripts(Command):
description = "install scripts (Python or otherwise)" description = "install scripts (Python or otherwise)"
...@@ -27,14 +26,13 @@ class install_scripts (Command): ...@@ -27,14 +26,13 @@ class install_scripts (Command):
boolean_options = ['force', 'skip-build'] boolean_options = ['force', 'skip-build']
def initialize_options(self):
def initialize_options (self):
self.install_dir = None self.install_dir = None
self.force = 0 self.force = 0
self.build_dir = None self.build_dir = None
self.skip_build = None self.skip_build = None
def finalize_options (self): def finalize_options(self):
self.set_undefined_options('build', ('build_scripts', 'build_dir')) self.set_undefined_options('build', ('build_scripts', 'build_dir'))
self.set_undefined_options('install', self.set_undefined_options('install',
('install_scripts', 'install_dir'), ('install_scripts', 'install_dir'),
...@@ -42,7 +40,7 @@ class install_scripts (Command): ...@@ -42,7 +40,7 @@ class install_scripts (Command):
('skip_build', 'skip_build'), ('skip_build', 'skip_build'),
) )
def run (self): def run(self):
if not self.skip_build: if not self.skip_build:
self.run_command('build_scripts') self.run_command('build_scripts')
self.outfiles = self.copy_tree(self.build_dir, self.install_dir) self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
...@@ -57,10 +55,8 @@ class install_scripts (Command): ...@@ -57,10 +55,8 @@ class install_scripts (Command):
log.info("changing mode of %s to %o", file, mode) log.info("changing mode of %s to %o", file, mode)
os.chmod(file, mode) os.chmod(file, mode)
def get_inputs (self): def get_inputs(self):
return self.distribution.scripts or [] return self.distribution.scripts or []
def get_outputs(self): def get_outputs(self):
return self.outfiles or [] return self.outfiles or []
# class install_scripts
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
Implements the Distutils 'sdist' command (create a source distribution).""" Implements the Distutils 'sdist' command (create a source distribution)."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from types import *
from glob import glob from glob import glob
from distutils.core import Command from distutils.core import Command
from distutils import dir_util, dep_util, file_util, archive_util from distutils import dir_util, dep_util, file_util, archive_util
...@@ -82,7 +79,7 @@ class sdist (Command): ...@@ -82,7 +79,7 @@ class sdist (Command):
default_format = { 'posix': 'gztar', default_format = { 'posix': 'gztar',
'nt': 'zip' } 'nt': 'zip' }
def initialize_options (self): def initialize_options(self):
# 'template' and 'manifest' are, respectively, the names of # 'template' and 'manifest' are, respectively, the names of
# the manifest template and manifest file. # the manifest template and manifest file.
self.template = None self.template = None
...@@ -103,7 +100,7 @@ class sdist (Command): ...@@ -103,7 +100,7 @@ class sdist (Command):
self.archive_files = None self.archive_files = None
def finalize_options (self): def finalize_options(self):
if self.manifest is None: if self.manifest is None:
self.manifest = "MANIFEST" self.manifest = "MANIFEST"
if self.template is None: if self.template is None:
...@@ -114,21 +111,20 @@ class sdist (Command): ...@@ -114,21 +111,20 @@ class sdist (Command):
try: try:
self.formats = [self.default_format[os.name]] self.formats = [self.default_format[os.name]]
except KeyError: except KeyError:
raise DistutilsPlatformError, \ raise DistutilsPlatformError(
"don't know how to create source distributions " + \ "don't know how to create source distributions "
"on platform %s" % os.name "on platform %s" % os.name)
bad_format = archive_util.check_archive_formats(self.formats) bad_format = archive_util.check_archive_formats(self.formats)
if bad_format: if bad_format:
raise DistutilsOptionError, \ raise DistutilsOptionError(
"unknown archive format '%s'" % bad_format "unknown archive format '%s'" % bad_format)
if self.dist_dir is None: if self.dist_dir is None:
self.dist_dir = "dist" self.dist_dir = "dist"
def run (self): def run(self):
# 'filelist' contains the list of files that will make up the # 'filelist' contains the list of files that will make up the
# manifest # manifest
self.filelist = FileList() self.filelist = FileList()
...@@ -150,8 +146,7 @@ class sdist (Command): ...@@ -150,8 +146,7 @@ class sdist (Command):
# or zipfile, or whatever. # or zipfile, or whatever.
self.make_distribution() self.make_distribution()
def check_metadata(self):
def check_metadata (self):
"""Ensure that all required elements of meta-data (name, version, """Ensure that all required elements of meta-data (name, version,
URL, (author and author_email) or (maintainer and URL, (author and author_email) or (maintainer and
maintainer_email)) are supplied by the Distribution object; warn if maintainer_email)) are supplied by the Distribution object; warn if
...@@ -181,17 +176,13 @@ class sdist (Command): ...@@ -181,17 +176,13 @@ class sdist (Command):
"or (maintainer and maintainer_email) " + "or (maintainer and maintainer_email) " +
"must be supplied") "must be supplied")
# check_metadata () def get_file_list(self):
def get_file_list (self):
"""Figure out the list of files to include in the source """Figure out the list of files to include in the source
distribution, and put it in 'self.filelist'. This might involve distribution, and put it in 'self.filelist'. This might involve
reading the manifest template (and writing the manifest), or just reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all reading the manifest, or just using the default file set -- it all
depends on the user's options and the state of the filesystem. depends on the user's options and the state of the filesystem.
""" """
# If we have a manifest template, see if it's newer than the # If we have a manifest template, see if it's newer than the
# manifest; if so, we'll regenerate the manifest. # manifest; if so, we'll regenerate the manifest.
template_exists = os.path.isfile(self.template) template_exists = os.path.isfile(self.template)
...@@ -231,9 +222,9 @@ class sdist (Command): ...@@ -231,9 +222,9 @@ class sdist (Command):
# Regenerate the manifest if necessary (or if explicitly told to) # Regenerate the manifest if necessary (or if explicitly told to)
if manifest_outofdate or neither_exists or force_regen: if manifest_outofdate or neither_exists or force_regen:
if not template_exists: if not template_exists:
self.warn(("manifest template '%s' does not exist " + self.warn("manifest template '%s' does not exist "
"(using default file list)") % "(using default file list)"
self.template) % self.template)
self.filelist.findall() self.filelist.findall()
if self.use_defaults: if self.use_defaults:
...@@ -251,10 +242,8 @@ class sdist (Command): ...@@ -251,10 +242,8 @@ class sdist (Command):
else: else:
self.read_manifest() self.read_manifest()
# get_file_list ()
def add_defaults (self): def add_defaults(self):
"""Add all the default files to self.filelist: """Add all the default files to self.filelist:
- README or README.txt - README or README.txt
- setup.py - setup.py
...@@ -265,15 +254,14 @@ class sdist (Command): ...@@ -265,15 +254,14 @@ class sdist (Command):
Warns if (README or README.txt) or setup.py are missing; everything Warns if (README or README.txt) or setup.py are missing; everything
else is optional. else is optional.
""" """
standards = [('README', 'README.txt'), self.distribution.script_name] standards = [('README', 'README.txt'), self.distribution.script_name]
for fn in standards: for fn in standards:
if type(fn) is TupleType: if isinstance(fn, tuple):
alts = fn alts = fn
got_it = 0 got_it = False
for fn in alts: for fn in alts:
if os.path.exists(fn): if os.path.exists(fn):
got_it = 1 got_it = True
self.filelist.append(fn) self.filelist.append(fn)
break break
...@@ -308,25 +296,18 @@ class sdist (Command): ...@@ -308,25 +296,18 @@ class sdist (Command):
build_scripts = self.get_finalized_command('build_scripts') build_scripts = self.get_finalized_command('build_scripts')
self.filelist.extend(build_scripts.get_source_files()) self.filelist.extend(build_scripts.get_source_files())
# add_defaults () def read_template(self):
def read_template (self):
"""Read and parse manifest template file named by self.template. """Read and parse manifest template file named by self.template.
(usually "MANIFEST.in") The parsing and processing is done by (usually "MANIFEST.in") The parsing and processing is done by
'self.filelist', which updates itself accordingly. 'self.filelist', which updates itself accordingly.
""" """
log.info("reading manifest template '%s'", self.template) log.info("reading manifest template '%s'", self.template)
template = TextFile(self.template, template = TextFile(self.template, strip_comments=1, skip_blanks=1,
strip_comments=1, join_lines=1, lstrip_ws=1, rstrip_ws=1,
skip_blanks=1,
join_lines=1,
lstrip_ws=1,
rstrip_ws=1,
collapse_join=1) collapse_join=1)
while 1: while True:
line = template.readline() line = template.readline()
if line is None: # end of file if line is None: # end of file
break break
...@@ -338,10 +319,7 @@ class sdist (Command): ...@@ -338,10 +319,7 @@ class sdist (Command):
template.current_line, template.current_line,
msg)) msg))
# read_template () def prune_file_list(self):
def prune_file_list (self):
"""Prune off branches that might slip into the file list as created """Prune off branches that might slip into the file list as created
by 'read_template()', but really don't belong there: by 'read_template()', but really don't belong there:
* the build tree (typically "build") * the build tree (typically "build")
...@@ -356,8 +334,7 @@ class sdist (Command): ...@@ -356,8 +334,7 @@ class sdist (Command):
self.filelist.exclude_pattern(None, prefix=base_dir) 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)/.*', is_regex=1)
def write_manifest(self):
def write_manifest (self):
"""Write the file list in 'self.filelist' (presumably as filled in """Write the file list in 'self.filelist' (presumably as filled in
by 'add_defaults()' and 'read_template()') to the manifest file by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'. named by 'self.manifest'.
...@@ -366,17 +343,14 @@ class sdist (Command): ...@@ -366,17 +343,14 @@ class sdist (Command):
(self.manifest, self.filelist.files), (self.manifest, self.filelist.files),
"writing manifest file '%s'" % self.manifest) "writing manifest file '%s'" % self.manifest)
# write_manifest () def read_manifest(self):
def read_manifest (self):
"""Read the manifest file (named by 'self.manifest') and use it to """Read the manifest file (named by 'self.manifest') and use it to
fill in 'self.filelist', the list of files to include in the source fill in 'self.filelist', the list of files to include in the source
distribution. distribution.
""" """
log.info("reading manifest file '%s'", self.manifest) log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest) manifest = open(self.manifest)
while 1: while True:
line = manifest.readline() line = manifest.readline()
if line == '': # end of file if line == '': # end of file
break break
...@@ -384,10 +358,7 @@ class sdist (Command): ...@@ -384,10 +358,7 @@ class sdist (Command):
line = line[0:-1] line = line[0:-1]
self.filelist.append(line) self.filelist.append(line)
# read_manifest () def make_release_tree(self, base_dir, files):
def make_release_tree (self, base_dir, files):
"""Create the directory tree that will become the source """Create the directory tree that will become the source
distribution archive. All directories implied by the filenames in distribution archive. All directories implied by the filenames in
'files' are created under 'base_dir', and then we hard link or copy 'files' are created under 'base_dir', and then we hard link or copy
...@@ -429,9 +400,7 @@ class sdist (Command): ...@@ -429,9 +400,7 @@ class sdist (Command):
self.distribution.metadata.write_pkg_info(base_dir) self.distribution.metadata.write_pkg_info(base_dir)
# make_release_tree () def make_distribution(self):
def make_distribution (self):
"""Create the source distribution(s). First, we create the release """Create the source distribution(s). First, we create the release
tree with 'make_release_tree()'; then, we create all required tree with 'make_release_tree()'; then, we create all required
archive files (according to 'self.formats') from the release tree. archive files (according to 'self.formats') from the release tree.
...@@ -456,10 +425,8 @@ class sdist (Command): ...@@ -456,10 +425,8 @@ class sdist (Command):
if not self.keep_temp: if not self.keep_temp:
dir_util.remove_tree(base_dir, dry_run=self.dry_run) dir_util.remove_tree(base_dir, dry_run=self.dry_run)
def get_archive_files (self): def get_archive_files(self):
"""Return the list of archive files created when the command """Return the list of archive files created when the command
was run, or None if the command hasn't run yet. was run, or None if the command hasn't run yet.
""" """
return self.archive_files return self.archive_files
# class sdist
...@@ -170,7 +170,7 @@ class upload(Command): ...@@ -170,7 +170,7 @@ class upload(Command):
elif schema == 'https': elif schema == 'https':
http = httplib.HTTPSConnection(netloc) http = httplib.HTTPSConnection(netloc)
else: else:
raise AssertionError, "unsupported schema "+schema raise AssertionError("unsupported schema "+schema)
data = '' data = ''
loglevel = log.INFO loglevel = log.INFO
......
...@@ -6,12 +6,9 @@ indirectly provides the Distribution and Command classes, although they are ...@@ -6,12 +6,9 @@ indirectly provides the Distribution and Command classes, although they are
really defined in distutils.dist and distutils.cmd. really defined in distutils.dist and distutils.cmd.
""" """
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from types import *
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.errors import * from distutils.errors import *
...@@ -112,10 +109,10 @@ def setup (**attrs): ...@@ -112,10 +109,10 @@ def setup (**attrs):
_setup_distribution = dist = klass(attrs) _setup_distribution = dist = klass(attrs)
except DistutilsSetupError as msg: except DistutilsSetupError as msg:
if 'name' not in attrs: if 'name' not in attrs:
raise SystemExit, "error in setup command: %s" % msg raise SystemExit("error in setup command: %s" % msg)
else: else:
raise SystemExit, "error in %s setup command: %s" % \ raise SystemExit("error in %s setup command: %s" % \
(attrs['name'], msg) (attrs['name'], msg))
if _setup_stop_after == "init": if _setup_stop_after == "init":
return dist return dist
...@@ -136,7 +133,7 @@ def setup (**attrs): ...@@ -136,7 +133,7 @@ def setup (**attrs):
try: try:
ok = dist.parse_command_line() ok = dist.parse_command_line()
except DistutilsArgError as msg: except DistutilsArgError as msg:
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
if DEBUG: if DEBUG:
print("options (after parsing command line):") print("options (after parsing command line):")
...@@ -150,7 +147,7 @@ def setup (**attrs): ...@@ -150,7 +147,7 @@ def setup (**attrs):
try: try:
dist.run_commands() dist.run_commands()
except KeyboardInterrupt: except KeyboardInterrupt:
raise SystemExit, "interrupted" raise SystemExit("interrupted")
except (IOError, os.error) as exc: except (IOError, os.error) as exc:
error = grok_environment_error(exc) error = grok_environment_error(exc)
...@@ -158,14 +155,14 @@ def setup (**attrs): ...@@ -158,14 +155,14 @@ def setup (**attrs):
sys.stderr.write(error + "\n") sys.stderr.write(error + "\n")
raise raise
else: else:
raise SystemExit, error raise SystemExit(error)
except (DistutilsError, except (DistutilsError,
CCompilerError) as msg: CCompilerError) as msg:
if DEBUG: if DEBUG:
raise raise
else: else:
raise SystemExit, "error: " + str(msg) raise SystemExit("error: " + str(msg))
return dist return dist
...@@ -204,7 +201,7 @@ def run_setup (script_name, script_args=None, stop_after="run"): ...@@ -204,7 +201,7 @@ def run_setup (script_name, script_args=None, stop_after="run"):
used to drive the Distutils. used to drive the Distutils.
""" """
if stop_after not in ('init', 'config', 'commandline', 'run'): if stop_after not in ('init', 'config', 'commandline', 'run'):
raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,) raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
global _setup_stop_after, _setup_distribution global _setup_stop_after, _setup_distribution
_setup_stop_after = stop_after _setup_stop_after = stop_after
...@@ -229,10 +226,9 @@ def run_setup (script_name, script_args=None, stop_after="run"): ...@@ -229,10 +226,9 @@ def run_setup (script_name, script_args=None, stop_after="run"):
raise raise
if _setup_distribution is None: if _setup_distribution is None:
raise RuntimeError, \ raise RuntimeError(("'distutils.core.setup()' was never called -- "
("'distutils.core.setup()' was never called -- "
"perhaps '%s' is not a Distutils setup script?") % \ "perhaps '%s' is not a Distutils setup script?") % \
script_name script_name)
# I wonder if the setup script's namespace -- g and l -- would be of # I wonder if the setup script's namespace -- g and l -- would be of
# any interest to callers? # any interest to callers?
......
...@@ -45,8 +45,6 @@ cygwin in no-cygwin mode). ...@@ -45,8 +45,6 @@ cygwin in no-cygwin mode).
# * mingw gcc 3.2/ld 2.13 works # * mingw gcc 3.2/ld 2.13 works
# (ld supports -shared) # (ld supports -shared)
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os,sys,copy import os,sys,copy
...@@ -143,13 +141,13 @@ class CygwinCCompiler (UnixCCompiler): ...@@ -143,13 +141,13 @@ class CygwinCCompiler (UnixCCompiler):
try: try:
self.spawn(["windres", "-i", src, "-o", obj]) self.spawn(["windres", "-i", src, "-o", obj])
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
else: # for other files use the C-compiler else: # for other files use the C-compiler
try: try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs) extra_postargs)
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
def link (self, def link (self,
target_desc, target_desc,
...@@ -260,9 +258,8 @@ class CygwinCCompiler (UnixCCompiler): ...@@ -260,9 +258,8 @@ class CygwinCCompiler (UnixCCompiler):
# use normcase to make sure '.rc' is really '.rc' and not '.RC' # use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name)) (base, ext) = os.path.splitext (os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc','.res']): if ext not in (self.src_extensions + ['.rc','.res']):
raise UnknownFileError, \ raise UnknownFileError("unknown file type '%s' (from '%s')" % \
"unknown file type '%s' (from '%s')" % \ (ext, src_name))
(ext, src_name)
if strip_dir: if strip_dir:
base = os.path.basename (base) base = os.path.basename (base)
if ext == '.res' or ext == '.rc': if ext == '.res' or ext == '.rc':
......
import os import os
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
# If DISTUTILS_DEBUG is anything other than the empty string, we run in # If DISTUTILS_DEBUG is anything other than the empty string, we run in
......
...@@ -4,8 +4,6 @@ Utility functions for simple, timestamp-based dependency of files ...@@ -4,8 +4,6 @@ Utility functions for simple, timestamp-based dependency of files
and groups of files; also, function based entirely on such and groups of files; also, function based entirely on such
timestamp dependency analysis.""" timestamp dependency analysis."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -19,7 +17,7 @@ def newer (source, target): ...@@ -19,7 +17,7 @@ def newer (source, target):
Raise DistutilsFileError if 'source' does not exist. Raise DistutilsFileError if 'source' does not exist.
""" """
if not os.path.exists(source): if not os.path.exists(source):
raise DistutilsFileError, "file '%s' does not exist" % source raise DistutilsFileError("file '%s' does not exist" % source)
if not os.path.exists(target): if not os.path.exists(target):
return 1 return 1
...@@ -39,7 +37,7 @@ def newer_pairwise (sources, targets): ...@@ -39,7 +37,7 @@ def newer_pairwise (sources, targets):
of 'newer()'. of 'newer()'.
""" """
if len(sources) != len(targets): if len(sources) != len(targets):
raise ValueError, "'sources' and 'targets' must be same length" raise ValueError("'sources' and 'targets' must be same length")
# build a pair of lists (sources, targets) where source is newer # build a pair of lists (sources, targets) where source is newer
n_sources = [] n_sources = []
......
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
Utility functions for manipulating directories and directory trees.""" Utility functions for manipulating directories and directory trees."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os, sys import os, sys
from types import *
from distutils.errors import DistutilsFileError, DistutilsInternalError from distutils.errors import DistutilsFileError, DistutilsInternalError
from distutils import log from distutils import log
...@@ -32,8 +29,8 @@ def mkpath (name, mode=0o777, verbose=0, dry_run=0): ...@@ -32,8 +29,8 @@ def mkpath (name, mode=0o777, verbose=0, dry_run=0):
# Detect a common bug -- name is None # Detect a common bug -- name is None
if not isinstance(name, basestring): if not isinstance(name, basestring):
raise DistutilsInternalError, \ raise DistutilsInternalError(
"mkpath: 'name' must be a string (got %r)" % (name,) "mkpath: 'name' must be a string (got %r)" % (name,))
# XXX what's the better way to handle verbosity? print as we create # XXX what's the better way to handle verbosity? print as we create
# each directory in the path (the current behaviour), or only announce # each directory in the path (the current behaviour), or only announce
...@@ -136,8 +133,8 @@ def copy_tree (src, dst, ...@@ -136,8 +133,8 @@ def copy_tree (src, dst,
from distutils.file_util import copy_file from distutils.file_util import copy_file
if not dry_run and not os.path.isdir(src): if not dry_run and not os.path.isdir(src):
raise DistutilsFileError, \ raise DistutilsFileError(
"cannot copy tree '%s': not a directory" % src "cannot copy tree '%s': not a directory" % src)
try: try:
names = os.listdir(src) names = os.listdir(src)
except os.error as e: except os.error as e:
...@@ -145,8 +142,8 @@ def copy_tree (src, dst, ...@@ -145,8 +142,8 @@ def copy_tree (src, dst,
if dry_run: if dry_run:
names = [] names = []
else: else:
raise DistutilsFileError, \ raise DistutilsFileError(
"error listing files in '%s': %s" % (src, errstr) "error listing files in '%s': %s" % (src, errstr))
if not dry_run: if not dry_run:
mkpath(dst) mkpath(dst)
...@@ -176,8 +173,6 @@ def copy_tree (src, dst, ...@@ -176,8 +173,6 @@ def copy_tree (src, dst,
return outputs return outputs
# copy_tree ()
# Helper for remove_tree() # Helper for remove_tree()
def _build_cmdtuple(path, cmdtuples): def _build_cmdtuple(path, cmdtuples):
for f in os.listdir(path): for f in os.listdir(path):
......
...@@ -4,8 +4,6 @@ Provides the Distribution class, which represents the module distribution ...@@ -4,8 +4,6 @@ Provides the Distribution class, which represents the module distribution
being built/installed/distributed. being built/installed/distributed.
""" """
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os, re import sys, os, re
...@@ -264,8 +262,6 @@ Common commands: (see '--help-commands' for more) ...@@ -264,8 +262,6 @@ Common commands: (see '--help-commands' for more)
self.finalize_options() self.finalize_options()
# __init__ ()
def get_option_dict (self, command): def get_option_dict (self, command):
"""Get the option dictionary for a given command. If that """Get the option dictionary for a given command. If that
...@@ -305,8 +301,6 @@ Common commands: (see '--help-commands' for more) ...@@ -305,8 +301,6 @@ Common commands: (see '--help-commands' for more)
for line in out.split("\n"): for line in out.split("\n"):
print(indent + " " + line) print(indent + " " + line)
# dump_option_dicts ()
# -- Config file finding/parsing methods --------------------------- # -- Config file finding/parsing methods ---------------------------
...@@ -353,8 +347,6 @@ Common commands: (see '--help-commands' for more) ...@@ -353,8 +347,6 @@ Common commands: (see '--help-commands' for more)
return files return files
# find_config_files ()
def parse_config_files (self, filenames=None): def parse_config_files (self, filenames=None):
...@@ -397,9 +389,7 @@ Common commands: (see '--help-commands' for more) ...@@ -397,9 +389,7 @@ Common commands: (see '--help-commands' for more)
else: else:
setattr(self, opt, val) setattr(self, opt, val)
except ValueError as msg: except ValueError as msg:
raise DistutilsOptionError, msg raise DistutilsOptionError(msg)
# parse_config_files ()
# -- Command-line parsing methods ---------------------------------- # -- Command-line parsing methods ----------------------------------
...@@ -472,12 +462,10 @@ Common commands: (see '--help-commands' for more) ...@@ -472,12 +462,10 @@ Common commands: (see '--help-commands' for more)
# Oops, no commands found -- an end-user error # Oops, no commands found -- an end-user error
if not self.commands: if not self.commands:
raise DistutilsArgError, "no commands supplied" raise DistutilsArgError("no commands supplied")
# All is well: return true # All is well: return true
return 1 return True
# parse_command_line()
def _get_toplevel_options (self): def _get_toplevel_options (self):
"""Return the non-display options recognized at the top level. """Return the non-display options recognized at the top level.
...@@ -505,7 +493,7 @@ Common commands: (see '--help-commands' for more) ...@@ -505,7 +493,7 @@ Common commands: (see '--help-commands' for more)
# Pull the current command from the head of the command line # Pull the current command from the head of the command line
command = args[0] command = args[0]
if not command_re.match(command): if not command_re.match(command):
raise SystemExit, "invalid command name '%s'" % command raise SystemExit("invalid command name '%s'" % command)
self.commands.append(command) self.commands.append(command)
# Dig up the command class that implements this command, so we # Dig up the command class that implements this command, so we
...@@ -514,22 +502,21 @@ Common commands: (see '--help-commands' for more) ...@@ -514,22 +502,21 @@ Common commands: (see '--help-commands' for more)
try: try:
cmd_class = self.get_command_class(command) cmd_class = self.get_command_class(command)
except DistutilsModuleError as msg: except DistutilsModuleError as msg:
raise DistutilsArgError, msg raise DistutilsArgError(msg)
# Require that the command class be derived from Command -- want # Require that the command class be derived from Command -- want
# to be sure that the basic "command" interface is implemented. # to be sure that the basic "command" interface is implemented.
if not issubclass(cmd_class, Command): if not issubclass(cmd_class, Command):
raise DistutilsClassError, \ raise DistutilsClassError(
"command class %s must subclass Command" % cmd_class "command class %s must subclass Command" % cmd_class)
# Also make sure that the command object provides a list of its # Also make sure that the command object provides a list of its
# known options. # known options.
if not (hasattr(cmd_class, 'user_options') and if not (hasattr(cmd_class, 'user_options') and
isinstance(cmd_class.user_options, list)): isinstance(cmd_class.user_options, list)):
raise DistutilsClassError, \ raise DistutilsClassError(("command class %s must provide " +
("command class %s must provide " +
"'user_options' attribute (a list of tuples)") % \ "'user_options' attribute (a list of tuples)") % \
cmd_class cmd_class)
# If the command class has a list of negative alias options, # If the command class has a list of negative alias options,
# merge it in with the global negative aliases. # merge it in with the global negative aliases.
...@@ -586,8 +573,6 @@ Common commands: (see '--help-commands' for more) ...@@ -586,8 +573,6 @@ Common commands: (see '--help-commands' for more)
return args return args
# _parse_command_opts ()
def finalize_options (self): def finalize_options (self):
"""Set final values for all the options on the Distribution """Set final values for all the options on the Distribution
instance, analogous to the .finalize_options() method of Command instance, analogous to the .finalize_options() method of Command
...@@ -660,8 +645,6 @@ Common commands: (see '--help-commands' for more) ...@@ -660,8 +645,6 @@ Common commands: (see '--help-commands' for more)
print(gen_usage(self.script_name)) print(gen_usage(self.script_name))
return return
# _show_help ()
def handle_display_options (self, option_order): def handle_display_options (self, option_order):
"""If there were any non-global "display-only" options """If there were any non-global "display-only" options
...@@ -703,13 +686,10 @@ Common commands: (see '--help-commands' for more) ...@@ -703,13 +686,10 @@ Common commands: (see '--help-commands' for more)
return any_display_options return any_display_options
# handle_display_options()
def print_command_list (self, commands, header, max_length): def print_command_list (self, commands, header, max_length):
"""Print a subset of the list of all commands -- used by """Print a subset of the list of all commands -- used by
'print_commands()'. 'print_commands()'.
""" """
print(header + ":") print(header + ":")
for cmd in commands: for cmd in commands:
...@@ -723,8 +703,6 @@ Common commands: (see '--help-commands' for more) ...@@ -723,8 +703,6 @@ Common commands: (see '--help-commands' for more)
print(" %-*s %s" % (max_length, cmd, description)) print(" %-*s %s" % (max_length, cmd, description))
# print_command_list ()
def print_commands (self): def print_commands (self):
"""Print out a help message listing all available commands with a """Print out a help message listing all available commands with a
...@@ -734,7 +712,6 @@ Common commands: (see '--help-commands' for more) ...@@ -734,7 +712,6 @@ Common commands: (see '--help-commands' for more)
descriptions come from the command class attribute descriptions come from the command class attribute
'description'. 'description'.
""" """
import distutils.command import distutils.command
std_commands = distutils.command.__all__ std_commands = distutils.command.__all__
is_std = {} is_std = {}
...@@ -760,8 +737,6 @@ Common commands: (see '--help-commands' for more) ...@@ -760,8 +737,6 @@ Common commands: (see '--help-commands' for more)
"Extra commands", "Extra commands",
max_length) max_length)
# print_commands ()
def get_command_list (self): def get_command_list (self):
"""Get a list of (command, description) tuples. """Get a list of (command, description) tuples.
The list is divided into "standard commands" (listed in The list is divided into "standard commands" (listed in
...@@ -771,7 +746,6 @@ Common commands: (see '--help-commands' for more) ...@@ -771,7 +746,6 @@ Common commands: (see '--help-commands' for more)
""" """
# Currently this is only used on Mac OS, for the Mac-only GUI # Currently this is only used on Mac OS, for the Mac-only GUI
# Distutils interface (by Jack Jansen) # Distutils interface (by Jack Jansen)
import distutils.command import distutils.command
std_commands = distutils.command.__all__ std_commands = distutils.command.__all__
is_std = {} is_std = {}
...@@ -839,18 +813,15 @@ Common commands: (see '--help-commands' for more) ...@@ -839,18 +813,15 @@ Common commands: (see '--help-commands' for more)
try: try:
klass = getattr(module, klass_name) klass = getattr(module, klass_name)
except AttributeError: except AttributeError:
raise DistutilsModuleError, \ raise DistutilsModuleError(
"invalid command '%s' (no class '%s' in module '%s')" \ "invalid command '%s' (no class '%s' in module '%s')"
% (command, klass_name, module_name) % (command, klass_name, module_name))
self.cmdclass[command] = klass self.cmdclass[command] = klass
return klass return klass
raise DistutilsModuleError("invalid command '%s'" % command) raise DistutilsModuleError("invalid command '%s'" % command)
# get_command_class ()
def get_command_obj (self, command, create=1): def get_command_obj (self, command, create=1):
"""Return the command object for 'command'. Normally this object """Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command is cached on a previous call to 'get_command_obj()'; if no command
...@@ -912,11 +883,11 @@ Common commands: (see '--help-commands' for more) ...@@ -912,11 +883,11 @@ Common commands: (see '--help-commands' for more)
elif hasattr(command_obj, option): elif hasattr(command_obj, option):
setattr(command_obj, option, value) setattr(command_obj, option, value)
else: else:
raise DistutilsOptionError, \ raise DistutilsOptionError(
("error in %s: command '%s' has no such option '%s'" "error in %s: command '%s' has no such option '%s'"
% (source, command_name, option)) % (source, command_name, option))
except ValueError as msg: except ValueError as msg:
raise DistutilsOptionError, msg raise DistutilsOptionError(msg)
def reinitialize_command (self, command, reinit_subcommands=0): def reinitialize_command (self, command, reinit_subcommands=0):
"""Reinitializes a command to the state it was in when first """Reinitializes a command to the state it was in when first
...@@ -1075,8 +1046,6 @@ class DistributionMetadata: ...@@ -1075,8 +1046,6 @@ class DistributionMetadata:
pkg_info.close() pkg_info.close()
# write_pkg_info ()
def write_pkg_file (self, file): def write_pkg_file (self, file):
"""Write the PKG-INFO format data to a file object. """Write the PKG-INFO format data to a file object.
""" """
...@@ -1202,8 +1171,6 @@ class DistributionMetadata: ...@@ -1202,8 +1171,6 @@ class DistributionMetadata:
distutils.versionpredicate.VersionPredicate(v) distutils.versionpredicate.VersionPredicate(v)
self.obsoletes = value self.obsoletes = value
# class DistributionMetadata
def fix_help_options (options): def fix_help_options (options):
"""Convert a 4-tuple 'help_options' list as found in various command """Convert a 4-tuple 'help_options' list as found in various command
......
...@@ -80,13 +80,13 @@ class EMXCCompiler (UnixCCompiler): ...@@ -80,13 +80,13 @@ class EMXCCompiler (UnixCCompiler):
try: try:
self.spawn(["rc", "-r", src]) self.spawn(["rc", "-r", src])
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
else: # for other files use the C-compiler else: # for other files use the C-compiler
try: try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs) extra_postargs)
except DistutilsExecError as msg: except DistutilsExecError as msg:
raise CompileError, msg raise CompileError(msg)
def link (self, def link (self,
target_desc, target_desc,
...@@ -189,9 +189,8 @@ class EMXCCompiler (UnixCCompiler): ...@@ -189,9 +189,8 @@ class EMXCCompiler (UnixCCompiler):
# use normcase to make sure '.rc' is really '.rc' and not '.RC' # use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name)) (base, ext) = os.path.splitext (os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc']): if ext not in (self.src_extensions + ['.rc']):
raise UnknownFileError, \ raise UnknownFileError("unknown file type '%s' (from '%s')" % \
"unknown file type '%s' (from '%s')" % \ (ext, src_name))
(ext, src_name)
if strip_dir: if strip_dir:
base = os.path.basename (base) base = os.path.basename (base)
if ext == '.rc': if ext == '.rc':
......
...@@ -8,8 +8,6 @@ usually raised for errors that are obviously the end-user's fault ...@@ -8,8 +8,6 @@ usually raised for errors that are obviously the end-user's fault
This module is safe to use in "from ... import *" mode; it only exports This module is safe to use in "from ... import *" mode; it only exports
symbols whose names start with "Distutils" and end with "Error".""" symbols whose names start with "Distutils" and end with "Error"."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
class DistutilsError (Exception): class DistutilsError (Exception):
......
...@@ -86,7 +86,7 @@ class Extension: ...@@ -86,7 +86,7 @@ class Extension:
# When adding arguments to this constructor, be sure to update # When adding arguments to this constructor, be sure to update
# setup_keywords in core.py. # setup_keywords in core.py.
def __init__ (self, name, sources, def __init__(self, name, sources,
include_dirs=None, include_dirs=None,
define_macros=None, define_macros=None,
undef_macros=None, undef_macros=None,
...@@ -125,17 +125,15 @@ class Extension: ...@@ -125,17 +125,15 @@ class Extension:
# If there are unknown keyword options, warn about them # If there are unknown keyword options, warn about them
if len(kw): if len(kw):
L = kw.keys() ; L.sort() L = map(repr, sorted(kw))
L = map(repr, L)
msg = "Unknown Extension options: " + ', '.join(L) msg = "Unknown Extension options: " + ', '.join(L)
if warnings is not None: if warnings is not None:
warnings.warn(msg) warnings.warn(msg)
else: else:
sys.stderr.write(msg + '\n') sys.stderr.write(msg + '\n')
# class Extension
def read_setup_file (filename): def read_setup_file(filename):
from distutils.sysconfig import \ from distutils.sysconfig import \
parse_makefile, expand_makefile_vars, _variable_rx parse_makefile, expand_makefile_vars, _variable_rx
from distutils.text_file import TextFile from distutils.text_file import TextFile
...@@ -151,7 +149,7 @@ def read_setup_file (filename): ...@@ -151,7 +149,7 @@ def read_setup_file (filename):
lstrip_ws=1, rstrip_ws=1) lstrip_ws=1, rstrip_ws=1)
extensions = [] extensions = []
while 1: while True:
line = file.readline() line = file.readline()
if line is None: # eof if line is None: # eof
break break
...@@ -241,5 +239,3 @@ def read_setup_file (filename): ...@@ -241,5 +239,3 @@ def read_setup_file (filename):
# 'lib_args': library_args } # 'lib_args': library_args }
return extensions return extensions
# read_setup_file ()
This diff is collapsed.
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
Utility functions for operating on single files. Utility functions for operating on single files.
""" """
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
...@@ -17,7 +15,7 @@ _copy_action = { None: 'copying', ...@@ -17,7 +15,7 @@ _copy_action = { None: 'copying',
'sym': 'symbolically linking' } 'sym': 'symbolically linking' }
def _copy_file_contents (src, dst, buffer_size=16*1024): def _copy_file_contents(src, dst, buffer_size=16*1024):
"""Copy the file 'src' to 'dst'; both must be filenames. Any error """Copy the file 'src' to 'dst'; both must be filenames. Any error
opening either file, reading from 'src', or writing to 'dst', raises opening either file, reading from 'src', or writing to 'dst', raises
DistutilsFileError. Data is read/written in chunks of 'buffer_size' DistutilsFileError. Data is read/written in chunks of 'buffer_size'
...@@ -26,7 +24,6 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -26,7 +24,6 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
""" """
# Stolen from shutil module in the standard library, but with # Stolen from shutil module in the standard library, but with
# custom error-handling added. # custom error-handling added.
fsrc = None fsrc = None
fdst = None fdst = None
try: try:
...@@ -34,31 +31,30 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -34,31 +31,30 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
fsrc = open(src, 'rb') fsrc = open(src, 'rb')
except os.error as e: except os.error as e:
(errno, errstr) = e (errno, errstr) = e
raise DistutilsFileError, \ raise DistutilsFileError("could not open '%s': %s" % (src, errstr))
"could not open '%s': %s" % (src, errstr)
if os.path.exists(dst): if os.path.exists(dst):
try: try:
os.unlink(dst) os.unlink(dst)
except os.error as e: except os.error as e:
(errno, errstr) = e (errno, errstr) = e
raise DistutilsFileError, \ raise DistutilsFileError(
"could not delete '%s': %s" % (dst, errstr) "could not delete '%s': %s" % (dst, errstr))
try: try:
fdst = open(dst, 'wb') fdst = open(dst, 'wb')
except os.error as e: except os.error as e:
(errno, errstr) = e (errno, errstr) = e
raise DistutilsFileError, \ raise DistutilsFileError(
"could not create '%s': %s" % (dst, errstr) "could not create '%s': %s" % (dst, errstr))
while 1: while True:
try: try:
buf = fsrc.read(buffer_size) buf = fsrc.read(buffer_size)
except os.error as e: except os.error as e:
(errno, errstr) = e (errno, errstr) = e
raise DistutilsFileError, \ raise DistutilsFileError(
"could not read from '%s': %s" % (src, errstr) "could not read from '%s': %s" % (src, errstr))
if not buf: if not buf:
break break
...@@ -67,25 +63,16 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -67,25 +63,16 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
fdst.write(buf) fdst.write(buf)
except os.error as e: except os.error as e:
(errno, errstr) = e (errno, errstr) = e
raise DistutilsFileError, \ raise DistutilsFileError(
"could not write to '%s': %s" % (dst, errstr) "could not write to '%s': %s" % (dst, errstr))
finally: finally:
if fdst: if fdst:
fdst.close() fdst.close()
if fsrc: if fsrc:
fsrc.close() fsrc.close()
# _copy_file_contents() def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
link=None, verbose=0, dry_run=0):
def copy_file (src, dst,
preserve_mode=1,
preserve_times=1,
update=0,
link=None,
verbose=0,
dry_run=0):
"""Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is """Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is
copied there with the same name; otherwise, it must be a filename. (If copied there with the same name; otherwise, it must be a filename. (If
the file exists, it will be ruthlessly clobbered.) If 'preserve_mode' the file exists, it will be ruthlessly clobbered.) If 'preserve_mode'
...@@ -120,8 +107,8 @@ def copy_file (src, dst, ...@@ -120,8 +107,8 @@ def copy_file (src, dst,
from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE
if not os.path.isfile(src): if not os.path.isfile(src):
raise DistutilsFileError, \ raise DistutilsFileError(
"can't copy '%s': doesn't exist or not a regular file" % src "can't copy '%s': doesn't exist or not a regular file" % src)
if os.path.isdir(dst): if os.path.isdir(dst):
dir = dst dir = dst
...@@ -131,13 +118,12 @@ def copy_file (src, dst, ...@@ -131,13 +118,12 @@ def copy_file (src, dst,
if update and not newer(src, dst): if update and not newer(src, dst):
log.debug("not copying %s (output up-to-date)", src) log.debug("not copying %s (output up-to-date)", src)
return dst, 0 return (dst, 0)
try: try:
action = _copy_action[link] action = _copy_action[link]
except KeyError: except KeyError:
raise ValueError, \ raise ValueError("invalid value '%s' for 'link' argument" % link)
"invalid value '%s' for 'link' argument" % link
if os.path.basename(dst) == os.path.basename(src): if os.path.basename(dst) == os.path.basename(src):
log.info("%s %s -> %s", action, src, dir) log.info("%s %s -> %s", action, src, dir)
else: else:
...@@ -152,8 +138,8 @@ def copy_file (src, dst, ...@@ -152,8 +138,8 @@ def copy_file (src, dst,
try: try:
macostools.copy(src, dst, 0, preserve_times) macostools.copy(src, dst, 0, preserve_times)
except os.error as exc: except os.error as exc:
raise DistutilsFileError, \ raise DistutilsFileError(
"could not copy '%s' to '%s': %s" % (src, dst, exc[-1]) "could not copy '%s' to '%s': %s" % (src, dst, exc[-1]))
# If linking (hard or symbolic), use the appropriate system call # If linking (hard or symbolic), use the appropriate system call
# (Unix only, of course, but that's the caller's responsibility) # (Unix only, of course, but that's the caller's responsibility)
...@@ -180,8 +166,6 @@ def copy_file (src, dst, ...@@ -180,8 +166,6 @@ def copy_file (src, dst,
return (dst, 1) return (dst, 1)
# copy_file ()
# XXX I suspect this is Unix-specific -- need porting help! # XXX I suspect this is Unix-specific -- need porting help!
def move_file (src, dst, def move_file (src, dst,
...@@ -204,31 +188,30 @@ def move_file (src, dst, ...@@ -204,31 +188,30 @@ def move_file (src, dst,
return dst return dst
if not isfile(src): if not isfile(src):
raise DistutilsFileError, \ raise DistutilsFileError("can't move '%s': not a regular file" % src)
"can't move '%s': not a regular file" % src
if isdir(dst): if isdir(dst):
dst = os.path.join(dst, basename(src)) dst = os.path.join(dst, basename(src))
elif exists(dst): elif exists(dst):
raise DistutilsFileError, \ raise DistutilsFileError(
"can't move '%s': destination '%s' already exists" % \ "can't move '%s': destination '%s' already exists" %
(src, dst) (src, dst))
if not isdir(dirname(dst)): if not isdir(dirname(dst)):
raise DistutilsFileError, \ raise DistutilsFileError(
"can't move '%s': destination '%s' not a valid path" % \ "can't move '%s': destination '%s' not a valid path" %
(src, dst) (src, dst))
copy_it = 0 copy_it = False
try: try:
os.rename(src, dst) os.rename(src, dst)
except os.error as e: except os.error as e:
(num, msg) = e (num, msg) = e
if num == errno.EXDEV: if num == errno.EXDEV:
copy_it = 1 copy_it = True
else: else:
raise DistutilsFileError, \ raise DistutilsFileError(
"couldn't move '%s' to '%s': %s" % (src, dst, msg) "couldn't move '%s' to '%s': %s" % (src, dst, msg))
if copy_it: if copy_it:
copy_file(src, dst) copy_file(src, dst)
...@@ -240,15 +223,12 @@ def move_file (src, dst, ...@@ -240,15 +223,12 @@ def move_file (src, dst,
os.unlink(dst) os.unlink(dst)
except os.error: except os.error:
pass pass
raise DistutilsFileError, \ raise DistutilsFileError(
("couldn't move '%s' to '%s' by copy/delete: " + "couldn't move '%s' to '%s' by copy/delete: "
"delete '%s' failed: %s") % \ "delete '%s' failed: %s"
(src, dst, src, msg) % (src, dst, src, msg))
return dst return dst
# move_file ()
def write_file (filename, contents): def write_file (filename, contents):
"""Create a file with the specified name and write 'contents' (a """Create a file with the specified name and write 'contents' (a
......
...@@ -4,20 +4,16 @@ Provides the FileList class, used for poking about the filesystem ...@@ -4,20 +4,16 @@ Provides the FileList class, used for poking about the filesystem
and building lists of files. and building lists of files.
""" """
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import os, re import os, re
import fnmatch import fnmatch
from types import *
from glob import glob from glob import glob
from distutils.util import convert_path from distutils.util import convert_path
from distutils.errors import DistutilsTemplateError, DistutilsInternalError from distutils.errors import DistutilsTemplateError, DistutilsInternalError
from distutils import log from distutils import log
class FileList: class FileList:
"""A list of files built by on exploring the filesystem and filtered by """A list of files built by on exploring the filesystem and filtered by
applying various patterns to what we find there. applying various patterns to what we find there.
...@@ -32,22 +28,19 @@ class FileList: ...@@ -32,22 +28,19 @@ class FileList:
filtering applied) filtering applied)
""" """
def __init__(self, def __init__(self, warn=None, debug_print=None):
warn=None,
debug_print=None):
# ignore argument to FileList, but keep them for backwards # ignore argument to FileList, but keep them for backwards
# compatibility # compatibility
self.allfiles = None self.allfiles = None
self.files = [] self.files = []
def set_allfiles (self, allfiles): def set_allfiles(self, allfiles):
self.allfiles = allfiles self.allfiles = allfiles
def findall (self, dir=os.curdir): def findall(self, dir=os.curdir):
self.allfiles = findall(dir) self.allfiles = findall(dir)
def debug_print (self, msg): def debug_print(self, msg):
"""Print 'msg' to stdout if the global DEBUG (taken from the """Print 'msg' to stdout if the global DEBUG (taken from the
DISTUTILS_DEBUG environment variable) flag is true. DISTUTILS_DEBUG environment variable) flag is true.
""" """
...@@ -57,13 +50,13 @@ class FileList: ...@@ -57,13 +50,13 @@ class FileList:
# -- List-like methods --------------------------------------------- # -- List-like methods ---------------------------------------------
def append (self, item): def append(self, item):
self.files.append(item) self.files.append(item)
def extend (self, items): def extend(self, items):
self.files.extend(items) self.files.extend(items)
def sort (self): def sort(self):
# Not a strict lexical sort! # Not a strict lexical sort!
sortable_files = sorted(map(os.path.split, self.files)) sortable_files = sorted(map(os.path.split, self.files))
self.files = [] self.files = []
...@@ -73,7 +66,7 @@ class FileList: ...@@ -73,7 +66,7 @@ class FileList:
# -- Other miscellaneous utility methods --------------------------- # -- Other miscellaneous utility methods ---------------------------
def remove_duplicates (self): def remove_duplicates(self):
# Assumes list has been sorted! # Assumes list has been sorted!
for i in range(len(self.files) - 1, 0, -1): for i in range(len(self.files) - 1, 0, -1):
if self.files[i] == self.files[i - 1]: if self.files[i] == self.files[i - 1]:
...@@ -82,7 +75,7 @@ class FileList: ...@@ -82,7 +75,7 @@ class FileList:
# -- "File template" methods --------------------------------------- # -- "File template" methods ---------------------------------------
def _parse_template_line (self, line): def _parse_template_line(self, line):
words = line.split() words = line.split()
action = words[0] action = words[0]
...@@ -91,36 +84,26 @@ class FileList: ...@@ -91,36 +84,26 @@ class FileList:
if action in ('include', 'exclude', if action in ('include', 'exclude',
'global-include', 'global-exclude'): 'global-include', 'global-exclude'):
if len(words) < 2: if len(words) < 2:
raise DistutilsTemplateError, \ raise DistutilsTemplateError(
"'%s' expects <pattern1> <pattern2> ..." % action "'%s' expects <pattern1> <pattern2> ..." % action)
patterns = map(convert_path, words[1:]) patterns = map(convert_path, words[1:])
elif action in ('recursive-include', 'recursive-exclude'): elif action in ('recursive-include', 'recursive-exclude'):
if len(words) < 3: if len(words) < 3:
raise DistutilsTemplateError, \ raise DistutilsTemplateError(
"'%s' expects <dir> <pattern1> <pattern2> ..." % action "'%s' expects <dir> <pattern1> <pattern2> ..." % action)
dir = convert_path(words[1]) dir = convert_path(words[1])
patterns = map(convert_path, words[2:]) patterns = map(convert_path, words[2:])
elif action in ('graft', 'prune'): elif action in ('graft', 'prune'):
if len(words) != 2: if len(words) != 2:
raise DistutilsTemplateError, \ raise DistutilsTemplateError(
"'%s' expects a single <dir_pattern>" % action "'%s' expects a single <dir_pattern>" % action)
dir_pattern = convert_path(words[1]) dir_pattern = convert_path(words[1])
else: else:
raise DistutilsTemplateError, "unknown action '%s'" % action raise DistutilsTemplateError("unknown action '%s'" % action)
return (action, patterns, dir, dir_pattern) return (action, patterns, dir, dir_pattern)
# _parse_template_line () def process_template_line(self, line):
def process_template_line (self, line):
# Parse the line: split it up, make sure the right number of words # Parse the line: split it up, make sure the right number of words
# is there, and return the relevant words. 'action' is always # is there, and return the relevant words. 'action' is always
# defined: it's the first word of the line. Which of the other # defined: it's the first word of the line. Which of the other
...@@ -149,7 +132,7 @@ class FileList: ...@@ -149,7 +132,7 @@ class FileList:
self.debug_print("global-include " + ' '.join(patterns)) self.debug_print("global-include " + ' '.join(patterns))
for pattern in patterns: for pattern in patterns:
if not self.include_pattern(pattern, anchor=0): if not self.include_pattern(pattern, anchor=0):
log.warn(("warning: no files found matching '%s' " + log.warn(("warning: no files found matching '%s' "
"anywhere in distribution"), pattern) "anywhere in distribution"), pattern)
elif action == 'global-exclude': elif action == 'global-exclude':
...@@ -165,7 +148,7 @@ class FileList: ...@@ -165,7 +148,7 @@ class FileList:
(dir, ' '.join(patterns))) (dir, ' '.join(patterns)))
for pattern in patterns: for pattern in patterns:
if not self.include_pattern(pattern, prefix=dir): if not self.include_pattern(pattern, prefix=dir):
log.warn(("warning: no files found matching '%s' " + log.warn(("warning: no files found matching '%s' "
"under directory '%s'"), "under directory '%s'"),
pattern, dir) pattern, dir)
...@@ -187,19 +170,16 @@ class FileList: ...@@ -187,19 +170,16 @@ class FileList:
elif action == 'prune': elif action == 'prune':
self.debug_print("prune " + dir_pattern) self.debug_print("prune " + dir_pattern)
if not self.exclude_pattern(None, prefix=dir_pattern): if not self.exclude_pattern(None, prefix=dir_pattern):
log.warn(("no previously-included directories found " + log.warn(("no previously-included directories found "
"matching '%s'"), dir_pattern) "matching '%s'"), dir_pattern)
else: else:
raise DistutilsInternalError, \ raise DistutilsInternalError(
"this cannot happen: invalid action '%s'" % action "this cannot happen: invalid action '%s'" % action)
# process_template_line ()
# -- Filtering/selection methods ----------------------------------- # -- Filtering/selection methods -----------------------------------
def include_pattern (self, pattern, def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
anchor=1, prefix=None, is_regex=0):
"""Select strings (presumably filenames) from 'self.files' that """Select strings (presumably filenames) from 'self.files' that
match 'pattern', a Unix-style wildcard (glob) pattern. Patterns match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
are not quite the same as implemented by the 'fnmatch' module: '*' are not quite the same as implemented by the 'fnmatch' module: '*'
...@@ -222,9 +202,9 @@ class FileList: ...@@ -222,9 +202,9 @@ class FileList:
Selected strings will be added to self.files. Selected strings will be added to self.files.
Return 1 if files are found. Return True if files are found, False otherwise.
""" """
files_found = 0 files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("include_pattern: applying regex r'%s'" % self.debug_print("include_pattern: applying regex r'%s'" %
pattern_re.pattern) pattern_re.pattern)
...@@ -237,12 +217,9 @@ class FileList: ...@@ -237,12 +217,9 @@ class FileList:
if pattern_re.search(name): if pattern_re.search(name):
self.debug_print(" adding " + name) self.debug_print(" adding " + name)
self.files.append(name) self.files.append(name)
files_found = 1 files_found = True
return files_found return files_found
# include_pattern ()
def exclude_pattern (self, pattern, def exclude_pattern (self, pattern,
anchor=1, prefix=None, is_regex=0): anchor=1, prefix=None, is_regex=0):
...@@ -250,9 +227,9 @@ class FileList: ...@@ -250,9 +227,9 @@ class FileList:
'pattern'. Other parameters are the same as for 'pattern'. Other parameters are the same as for
'include_pattern()', above. 'include_pattern()', above.
The list 'self.files' is modified in place. The list 'self.files' is modified in place.
Return 1 if files are found. Return True if files are found, False otherwise.
""" """
files_found = 0 files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex) pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("exclude_pattern: applying regex r'%s'" % self.debug_print("exclude_pattern: applying regex r'%s'" %
pattern_re.pattern) pattern_re.pattern)
...@@ -260,19 +237,14 @@ class FileList: ...@@ -260,19 +237,14 @@ class FileList:
if pattern_re.search(self.files[i]): if pattern_re.search(self.files[i]):
self.debug_print(" removing " + self.files[i]) self.debug_print(" removing " + self.files[i])
del self.files[i] del self.files[i]
files_found = 1 files_found = True
return files_found return files_found
# exclude_pattern ()
# class FileList
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Utility functions # Utility functions
def findall (dir = os.curdir): def findall(dir=os.curdir):
"""Find all files under 'dir' and return the list of full filenames """Find all files under 'dir' and return the list of full filenames
(relative to 'dir'). (relative to 'dir').
""" """
...@@ -300,11 +272,10 @@ def findall (dir = os.curdir): ...@@ -300,11 +272,10 @@ def findall (dir = os.curdir):
list.append(fullname) list.append(fullname)
elif S_ISDIR(mode) and not S_ISLNK(mode): elif S_ISDIR(mode) and not S_ISLNK(mode):
push(fullname) push(fullname)
return list return list
def glob_to_re (pattern): def glob_to_re(pattern):
"""Translate a shell-like glob pattern to a regular expression; return """Translate a shell-like glob pattern to a regular expression; return
a string containing the regex. Differs from 'fnmatch.translate()' in a string containing the regex. Differs from 'fnmatch.translate()' in
that '*' does not match "special characters" (which are that '*' does not match "special characters" (which are
...@@ -322,10 +293,8 @@ def glob_to_re (pattern): ...@@ -322,10 +293,8 @@ def glob_to_re (pattern):
pattern_re = re.sub(r'(^|[^\\])\.', r'\1[^/]', pattern_re) pattern_re = re.sub(r'(^|[^\\])\.', r'\1[^/]', pattern_re)
return pattern_re return pattern_re
# glob_to_re ()
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
"""Translate a shell-like wildcard pattern to a compiled regular """Translate a shell-like wildcard pattern to a compiled regular
expression. Return the compiled regex. If 'is_regex' true, expression. Return the compiled regex. If 'is_regex' true,
then 'pattern' is directly compiled to a regex (if it's a string) then 'pattern' is directly compiled to a regex (if it's a string)
...@@ -350,5 +319,3 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0): ...@@ -350,5 +319,3 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
pattern_re = "^" + pattern_re pattern_re = "^" + pattern_re
return re.compile(pattern_re) return re.compile(pattern_re)
# translate_pattern ()
"""A simple log mechanism styled after PEP 282.""" """A simple log mechanism styled after PEP 282."""
# This module should be kept compatible with Python 2.1.
# The class here is styled after PEP 282 so that it could later be # The class here is styled after PEP 282 so that it could later be
# replaced with a standard Python logging implementation. # replaced with a standard Python logging implementation.
......
This diff is collapsed.
...@@ -4,12 +4,9 @@ Contains MWerksCompiler, an implementation of the abstract CCompiler class ...@@ -4,12 +4,9 @@ Contains MWerksCompiler, an implementation of the abstract CCompiler class
for MetroWerks CodeWarrior on the Macintosh. Needs work to support CW on for MetroWerks CodeWarrior on the Macintosh. Needs work to support CW on
Windows.""" Windows."""
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from types import *
from distutils.errors import \ from distutils.errors import \
DistutilsExecError, DistutilsPlatformError, \ DistutilsExecError, DistutilsPlatformError, \
CompileError, LibError, LinkError CompileError, LibError, LinkError
...@@ -96,13 +93,13 @@ class MWerksCompiler (CCompiler) : ...@@ -96,13 +93,13 @@ class MWerksCompiler (CCompiler) :
# First examine a couple of options for things that aren't implemented yet # First examine a couple of options for things that aren't implemented yet
if not target_desc in (self.SHARED_LIBRARY, self.SHARED_OBJECT): if not target_desc in (self.SHARED_LIBRARY, self.SHARED_OBJECT):
raise DistutilsPlatformError, 'Can only make SHARED_LIBRARY or SHARED_OBJECT targets on the Mac' raise DistutilsPlatformError('Can only make SHARED_LIBRARY or SHARED_OBJECT targets on the Mac')
if runtime_library_dirs: if runtime_library_dirs:
raise DistutilsPlatformError, 'Runtime library dirs not implemented yet' raise DistutilsPlatformError('Runtime library dirs not implemented yet')
if extra_preargs or extra_postargs: if extra_preargs or extra_postargs:
raise DistutilsPlatformError, 'Runtime library dirs not implemented yet' raise DistutilsPlatformError('Runtime library dirs not implemented yet')
if len(export_symbols) != 1: if len(export_symbols) != 1:
raise DistutilsPlatformError, 'Need exactly one export symbol' raise DistutilsPlatformError('Need exactly one export symbol')
# Next there are various things for which we need absolute pathnames. # Next there are various things for which we need absolute pathnames.
# This is because we (usually) create the project in a subdirectory of # This is because we (usually) create the project in a subdirectory of
# where we are now, and keeping the paths relative is too much work right # where we are now, and keeping the paths relative is too much work right
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -140,7 +140,7 @@ class StrictVersion (Version): ...@@ -140,7 +140,7 @@ class StrictVersion (Version):
def parse (self, vstring): def parse (self, vstring):
match = self.version_re.match(vstring) match = self.version_re.match(vstring)
if not match: if not match:
raise ValueError, "invalid version number '%s'" % vstring raise ValueError("invalid version number '%s'" % vstring)
(major, minor, patch, prerelease, prerelease_num) = \ (major, minor, patch, prerelease, prerelease_num) = \
match.group(1, 2, 4, 5, 6) match.group(1, 2, 4, 5, 6)
......
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