summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/command
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/command')
-rw-r--r--Lib/distutils/command/__init__.py2
-rw-r--r--Lib/distutils/command/bdist.py34
-rw-r--r--Lib/distutils/command/bdist_dumb.py33
-rw-r--r--Lib/distutils/command/bdist_msi.py28
-rw-r--r--Lib/distutils/command/bdist_rpm.py54
-rw-r--r--Lib/distutils/command/bdist_wininst.py39
-rw-r--r--Lib/distutils/command/build.py26
-rw-r--r--Lib/distutils/command/build_clib.py97
-rw-r--r--Lib/distutils/command/build_ext.py120
-rw-r--r--Lib/distutils/command/build_py.py116
-rw-r--r--Lib/distutils/command/build_scripts.py20
-rw-r--r--Lib/distutils/command/clean.py6
-rw-r--r--Lib/distutils/command/command_template20
-rw-r--r--Lib/distutils/command/config.py102
-rw-r--r--Lib/distutils/command/install.py85
-rw-r--r--Lib/distutils/command/install_data.py14
-rw-r--r--Lib/distutils/command/install_headers.py16
-rw-r--r--Lib/distutils/command/install_lib.py44
-rw-r--r--Lib/distutils/command/install_scripts.py16
-rw-r--r--Lib/distutils/command/sdist.py89
-rw-r--r--Lib/distutils/command/upload.py2
21 files changed, 322 insertions, 641 deletions
diff --git a/Lib/distutils/command/__init__.py b/Lib/distutils/command/__init__.py
index 0888c27..add83f8 100644
--- a/Lib/distutils/command/__init__.py
+++ b/Lib/distutils/command/__init__.py
@@ -3,8 +3,6 @@
Package containing implementation of all the standard Distutils
commands."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
__all__ = ['build',
diff --git a/Lib/distutils/command/bdist.py b/Lib/distutils/command/bdist.py
index d6897d2..69c1b28 100644
--- a/Lib/distutils/command/bdist.py
+++ b/Lib/distutils/command/bdist.py
@@ -3,22 +3,19 @@
Implements the Distutils 'bdist' command (create a built [binary]
distribution)."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import os
-from types import *
from distutils.core import Command
from distutils.errors import *
from distutils.util import get_platform
-def show_formats ():
+def show_formats():
"""Print list of available formats (arguments to "--format" option).
"""
from distutils.fancy_getopt import FancyGetopt
- formats=[]
+ formats = []
for format in bdist.format_commands:
formats.append(("formats=" + format, None,
bdist.format_command[format][1]))
@@ -26,7 +23,7 @@ def show_formats ():
pretty_printer.print_help("List of available distribution formats:")
-class bdist (Command):
+class bdist(Command):
description = "create a built (binary) distribution"
@@ -84,17 +81,14 @@ class bdist (Command):
}
- def initialize_options (self):
+ def initialize_options(self):
self.bdist_base = None
self.plat_name = None
self.formats = None
self.dist_dir = None
self.skip_build = 0
- # initialize_options()
-
-
- def finalize_options (self):
+ def finalize_options(self):
# have to finalize 'plat_name' before 'bdist_base'
if self.plat_name is None:
self.plat_name = get_platform()
@@ -112,25 +106,21 @@ class bdist (Command):
try:
self.formats = [self.default_format[os.name]]
except KeyError:
- raise DistutilsPlatformError, \
- "don't know how to create built distributions " + \
- "on platform %s" % os.name
+ raise DistutilsPlatformError(
+ "don't know how to create built distributions "
+ "on platform %s" % os.name)
if self.dist_dir is None:
self.dist_dir = "dist"
- # finalize_options()
-
-
- def run (self):
-
+ def run(self):
# Figure out which sub-commands we need to run.
commands = []
for format in self.formats:
try:
commands.append(self.format_command[format][0])
except KeyError:
- raise DistutilsOptionError, "invalid format '%s'" % format
+ raise DistutilsOptionError("invalid format '%s'" % format)
# Reinitialize and run each command.
for i in range(len(self.formats)):
@@ -144,7 +134,3 @@ class bdist (Command):
if cmd_name in commands[i+1:]:
sub_cmd.keep_temp = 1
self.run_command(cmd_name)
-
- # run()
-
-# class bdist
diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py
index ccba009..f899617 100644
--- a/Lib/distutils/command/bdist_dumb.py
+++ b/Lib/distutils/command/bdist_dumb.py
@@ -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
$exec_prefix)."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import os
@@ -16,7 +14,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version
from distutils import log
-class bdist_dumb (Command):
+class bdist_dumb(Command):
description = "create a \"dumb\" built distribution"
@@ -45,8 +43,7 @@ class bdist_dumb (Command):
'nt': 'zip',
'os2': 'zip' }
-
- def initialize_options (self):
+ def initialize_options(self):
self.bdist_dir = None
self.plat_name = None
self.format = None
@@ -55,11 +52,7 @@ class bdist_dumb (Command):
self.skip_build = 0
self.relative = 0
- # initialize_options()
-
-
- def finalize_options (self):
-
+ def finalize_options(self):
if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'dumb')
@@ -68,19 +61,15 @@ class bdist_dumb (Command):
try:
self.format = self.default_format[os.name]
except KeyError:
- raise DistutilsPlatformError, \
- ("don't know how to create dumb built distributions " +
- "on platform %s") % os.name
+ raise DistutilsPlatformError(
+ "don't know how to create dumb built distributions "
+ "on platform %s" % os.name)
self.set_undefined_options('bdist',
('dist_dir', 'dist_dir'),
('plat_name', 'plat_name'))
- # finalize_options()
-
-
- def run (self):
-
+ def run(self):
if not self.skip_build:
self.run_command('build')
@@ -108,8 +97,8 @@ class bdist_dumb (Command):
else:
if (self.distribution.has_ext_modules() and
(install.install_base != install.install_platbase)):
- raise DistutilsPlatformError, \
- ("can't make a dumb built distribution where "
+ raise DistutilsPlatformError(
+ "can't make a dumb built distribution where "
"base and platbase are different (%s, %s)"
% (repr(install.install_base),
repr(install.install_platbase)))
@@ -129,7 +118,3 @@ class bdist_dumb (Command):
if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run)
-
- # run()
-
-# class bdist_dumb
diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py
index 5225bed..d313a50 100644
--- a/Lib/distutils/command/bdist_msi.py
+++ b/Lib/distutils/command/bdist_msi.py
@@ -81,7 +81,7 @@ class PyDialog(Dialog):
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)
-class bdist_msi (Command):
+class bdist_msi(Command):
description = "create a Microsoft Installer (.msi) binary distribution"
@@ -114,7 +114,7 @@ class bdist_msi (Command):
boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
'skip-build']
- def initialize_options (self):
+ def initialize_options(self):
self.bdist_dir = None
self.keep_temp = 0
self.no_target_compile = 0
@@ -125,7 +125,7 @@ class bdist_msi (Command):
self.install_script = None
self.pre_install_script = None
- def finalize_options (self):
+ def finalize_options(self):
if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'msi')
@@ -133,30 +133,29 @@ class bdist_msi (Command):
if self.target_version:
if not self.skip_build and self.distribution.has_ext_modules()\
and self.target_version != short_version:
- raise DistutilsOptionError, \
- "target version can only be %s, or the '--skip_build'" \
- " option must be specified" % (short_version,)
+ raise DistutilsOptionError(
+ "target version can only be %s, or the '--skip_build'"
+ " option must be specified" % (short_version,))
else:
self.target_version = short_version
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
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:
for script in self.distribution.scripts:
if self.install_script == os.path.basename(script):
break
else:
- raise DistutilsOptionError, \
- "install_script '%s' not found in scripts" % \
- self.install_script
+ raise DistutilsOptionError(
+ "install_script '%s' not found in scripts"
+ % self.install_script)
self.install_script_key = None
- # finalize_options()
-
- def run (self):
+ def run(self):
if not self.skip_build:
self.run_command('build')
@@ -263,7 +262,8 @@ class bdist_msi (Command):
key = dir.add_file(file)
if file==self.install_script:
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
cab.commit(db)
diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py
index ef2bdfd..72f74f9 100644
--- a/Lib/distutils/command/bdist_rpm.py
+++ b/Lib/distutils/command/bdist_rpm.py
@@ -3,13 +3,10 @@
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions)."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
import glob
-from types import *
from distutils.core import Command
from distutils.debug import DEBUG
from distutils.util import get_platform
@@ -18,7 +15,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version
from distutils import log
-class bdist_rpm (Command):
+class bdist_rpm(Command):
description = "create an RPM distribution"
@@ -136,7 +133,7 @@ class bdist_rpm (Command):
'rpm2-mode': 'rpm3-mode'}
- def initialize_options (self):
+ def initialize_options(self):
self.bdist_base = None
self.rpm_base = None
self.dist_dir = None
@@ -180,15 +177,12 @@ class bdist_rpm (Command):
self.force_arch = None
- # initialize_options()
-
-
- def finalize_options (self):
+ def finalize_options(self):
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
if self.rpm_base is None:
if not self.rpm3_mode:
- raise DistutilsOptionError, \
- "you must specify --rpm-base in RPM 2 mode"
+ raise DistutilsOptionError(
+ "you must specify --rpm-base in RPM 2 mode")
self.rpm_base = os.path.join(self.bdist_base, "rpm")
if self.python is None:
@@ -197,16 +191,15 @@ class bdist_rpm (Command):
else:
self.python = "python"
elif self.fix_python:
- raise DistutilsOptionError, \
- "--python and --fix-python are mutually exclusive options"
+ raise DistutilsOptionError(
+ "--python and --fix-python are mutually exclusive options")
if os.name != 'posix':
- raise DistutilsPlatformError, \
- ("don't know how to create RPM "
+ raise DistutilsPlatformError("don't know how to create RPM "
"distributions on platform %s" % os.name)
if self.binary_only and self.source_only:
- raise DistutilsOptionError, \
- "cannot supply both '--source-only' and '--binary-only'"
+ raise DistutilsOptionError(
+ "cannot supply both '--source-only' and '--binary-only'")
# don't pass CFLAGS to pure python distributions
if not self.distribution.has_ext_modules():
@@ -215,16 +208,14 @@ class bdist_rpm (Command):
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
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('vendor',
"%s <%s>" % (self.distribution.get_contact(),
self.distribution.get_contact_email()))
self.ensure_string('packager')
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'):
if os.path.exists(readme) and readme not in self.doc_files:
self.doc_files.append(readme)
@@ -261,11 +252,8 @@ class bdist_rpm (Command):
self.ensure_string_list('obsoletes')
self.ensure_string('force_arch')
- # finalize_package_data ()
-
-
- def run (self):
+ def run(self):
if DEBUG:
print("before _get_package_data():")
print("vendor =", self.vendor)
@@ -315,9 +303,8 @@ class bdist_rpm (Command):
if os.path.exists(self.icon):
self.copy_file(self.icon, source_dir)
else:
- raise DistutilsFileError, \
- "icon file '%s' does not exist" % self.icon
-
+ raise DistutilsFileError(
+ "icon file '%s' does not exist" % self.icon)
# build package
log.info("building RPMs")
@@ -350,7 +337,7 @@ class bdist_rpm (Command):
out = os.popen(q_cmd)
binary_rpms = []
source_rpm = None
- while 1:
+ while True:
line = out.readline()
if not line:
break
@@ -378,7 +365,6 @@ class bdist_rpm (Command):
rpm = os.path.join(rpm_dir['RPMS'], rpm)
if os.path.exists(rpm):
self.move_file(rpm, self.dist_dir)
- # run()
def _dist_path(self, path):
return os.path.join(self.dist_dir, os.path.basename(path))
@@ -438,7 +424,7 @@ class bdist_rpm (Command):
'Obsoletes',
):
val = getattr(self, field.lower())
- if type(val) is ListType:
+ if isinstance(val, list):
spec_file.append('%s: %s' % (field, ' '.join(val)))
elif val is not None:
spec_file.append('%s: %s' % (field, val))
@@ -536,8 +522,6 @@ class bdist_rpm (Command):
return spec_file
- # _make_spec_file ()
-
def _format_changelog(self, changelog):
"""Format the changelog correctly and convert it to a list of strings
"""
@@ -558,7 +542,3 @@ class bdist_rpm (Command):
del new_changelog[0]
return new_changelog
-
- # _format_changelog()
-
-# class bdist_rpm
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 55d5d7e..249b74c 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -3,8 +3,6 @@
Implements the Distutils 'bdist_wininst' command: create a windows installer
exe-program."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
@@ -15,7 +13,7 @@ from distutils.errors import *
from distutils.sysconfig import get_python_version
from distutils import log
-class bdist_wininst (Command):
+class bdist_wininst(Command):
description = "create an executable installer for MS Windows"
@@ -52,7 +50,7 @@ class bdist_wininst (Command):
boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
'skip-build']
- def initialize_options (self):
+ def initialize_options(self):
self.bdist_dir = None
self.keep_temp = 0
self.no_target_compile = 0
@@ -65,10 +63,8 @@ class bdist_wininst (Command):
self.install_script = None
self.pre_install_script = None
- # initialize_options()
-
- def finalize_options (self):
+ def finalize_options(self):
if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'wininst')
@@ -77,9 +73,9 @@ class bdist_wininst (Command):
if not self.skip_build and self.distribution.has_ext_modules():
short_version = get_python_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'" \
- " option must be specified" % (short_version,)
+ " option must be specified" % (short_version,))
self.target_version = short_version
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
@@ -89,13 +85,11 @@ class bdist_wininst (Command):
if self.install_script == os.path.basename(script):
break
else:
- raise DistutilsOptionError, \
- "install_script '%s' not found in scripts" % \
- self.install_script
- # finalize_options()
+ raise DistutilsOptionError(
+ "install_script '%s' not found in scripts"
+ % self.install_script)
-
- def run (self):
+ def run(self):
if (sys.platform != "win32" and
(self.distribution.has_ext_modules() or
self.distribution.has_c_libraries())):
@@ -175,11 +169,8 @@ class bdist_wininst (Command):
if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run)
- # run()
-
- def get_inidata (self):
+ def get_inidata(self):
# Return data describing the installation.
-
lines = []
metadata = self.distribution.metadata
@@ -222,9 +213,7 @@ class bdist_wininst (Command):
lines.append("build_info=%s" % build_info)
return "\n".join(lines)
- # get_inidata()
-
- def create_exe (self, arcname, fullname, bitmap=None):
+ def create_exe(self, arcname, fullname, bitmap=None):
import struct
self.mkpath(self.dist_dir)
@@ -272,8 +261,6 @@ class bdist_wininst (Command):
file.write(header)
file.write(open(arcname, "rb").read())
- # create_exe()
-
def get_installer_filename(self, fullname):
# Factored out to allow overriding in subclasses
if self.target_version:
@@ -286,9 +273,8 @@ class bdist_wininst (Command):
installer_name = os.path.join(self.dist_dir,
"%s.win32.exe" % fullname)
return installer_name
- # get_installer_filename()
- def get_exe_bytes (self):
+ def get_exe_bytes(self):
from distutils.msvccompiler import get_build_version
# If a target-version other than the current version has been
# specified, then using the MSVC version from *this* build is no good.
@@ -320,4 +306,3 @@ class bdist_wininst (Command):
# used for python. XXX What about mingw, borland, and so on?
filename = os.path.join(directory, "wininst-%s.exe" % bv)
return open(filename, "rb").read()
-# class bdist_wininst
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 9ae0a29..1f2ce06 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -2,8 +2,6 @@
Implements the Distutils 'build' command."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
@@ -11,12 +9,12 @@ from distutils.core import Command
from distutils.util import get_platform
-def show_compilers ():
+def show_compilers():
from distutils.ccompiler import show_compilers
show_compilers()
-class build (Command):
+class build(Command):
description = "build everything needed to install"
@@ -51,7 +49,7 @@ class build (Command):
"list available compilers", show_compilers),
]
- def initialize_options (self):
+ def initialize_options(self):
self.build_base = 'build'
# these are decided only after 'build_base' has its final value
# (unless overridden by the user or client)
@@ -65,8 +63,7 @@ class build (Command):
self.force = 0
self.executable = None
- def finalize_options (self):
-
+ def finalize_options(self):
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
# 'build_purelib' and 'build_platlib' just default to 'lib' and
@@ -98,11 +95,8 @@ class build (Command):
if self.executable is None:
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:
# - build_py - pure Python modules
# - build_clib - standalone C libraries
@@ -114,16 +108,16 @@ class build (Command):
# -- Predicates for the sub-command list ---------------------------
- def has_pure_modules (self):
+ def has_pure_modules(self):
return self.distribution.has_pure_modules()
- def has_c_libraries (self):
+ def has_c_libraries(self):
return self.distribution.has_c_libraries()
- def has_ext_modules (self):
+ def has_ext_modules(self):
return self.distribution.has_ext_modules()
- def has_scripts (self):
+ def has_scripts(self):
return self.distribution.has_scripts()
@@ -132,5 +126,3 @@ class build (Command):
('build_ext', has_ext_modules),
('build_scripts', has_scripts),
]
-
-# class build
diff --git a/Lib/distutils/command/build_clib.py b/Lib/distutils/command/build_clib.py
index bdf98bf..5f95207 100644
--- a/Lib/distutils/command/build_clib.py
+++ b/Lib/distutils/command/build_clib.py
@@ -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
module."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
@@ -19,18 +17,17 @@ __revision__ = "$Id$"
# cut 'n paste. Sigh.
import os
-from types import *
from distutils.core import Command
from distutils.errors import *
from distutils.sysconfig import customize_compiler
from distutils import log
-def show_compilers ():
+def show_compilers():
from distutils.ccompiler import show_compilers
show_compilers()
-class build_clib (Command):
+class build_clib(Command):
description = "build C/C++ libraries used by Python extensions"
@@ -54,7 +51,7 @@ class build_clib (Command):
"list available compilers", show_compilers),
]
- def initialize_options (self):
+ def initialize_options(self):
self.build_clib = None
self.build_temp = None
@@ -69,11 +66,8 @@ class build_clib (Command):
self.force = 0
self.compiler = None
- # initialize_options()
-
-
- def finalize_options (self):
+ def finalize_options(self):
# This might be confusing: both build-clib and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
@@ -98,11 +92,8 @@ class build_clib (Command):
# XXX same as for build_ext -- what about 'self.define' and
# 'self.undef' ?
- # finalize_options()
-
-
- def run (self):
+ def run(self):
if not self.libraries:
return
@@ -125,51 +116,41 @@ class build_clib (Command):
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
command option 'libraries') is valid, i.e. it is a list of
2-tuples, where the tuples are (library_name, build_info_dict).
Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise."""
-
# Yechh, blecch, ackk: this is ripped straight out of build_ext.py,
# with only names changed to protect the innocent!
-
- if type(libraries) is not ListType:
- raise DistutilsSetupError, \
- "'libraries' option must be a list of tuples"
+ if not isinstance(libraries, list):
+ raise DistutilsSetupError(
+ "'libraries' option must be a list of tuples")
for lib in libraries:
- if type(lib) is not TupleType and len(lib) != 2:
- raise DistutilsSetupError, \
- "each element of 'libraries' must a 2-tuple"
+ if not isinstance(lib, tuple) and len(lib) != 2:
+ raise DistutilsSetupError(
+ "each element of 'libraries' must a 2-tuple")
if isinstance(lib[0], basestring):
- raise DistutilsSetupError, \
- "first element of each tuple in 'libraries' " + \
- "must be a string (the library name)"
+ raise DistutilsSetupError(
+ "first element of each tuple in 'libraries' "
+ "must be a string (the library name)")
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
- raise DistutilsSetupError, \
- ("bad library name '%s': " +
- "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
+ raise DistutilsSetupError("bad library name '%s': "
+ "may not contain directory separators" % lib[0])
- # 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
# called from 'finalize_options()', so it should be!
-
if not self.libraries:
return None
@@ -178,36 +159,30 @@ class build_clib (Command):
lib_names.append(lib_name)
return lib_names
- # get_library_names ()
-
- def get_source_files (self):
+ def get_source_files(self):
self.check_library_list(self.libraries)
filenames = []
for (lib_name, build_info) in self.libraries:
sources = build_info.get('sources')
- if (sources is None or
- type(sources) not in (ListType, TupleType) ):
- raise DistutilsSetupError, \
- ("in 'libraries' option (library '%s'), "
+ if sources is None or not isinstance(sources, (list, tuple)):
+ raise DistutilsSetupError(
+ "in 'libraries' option (library '%s'), "
"'sources' must be present and must be "
- "a list of source filenames") % lib_name
+ "a list of source filenames" % lib_name)
filenames.extend(sources)
-
return filenames
- # get_source_files ()
-
- def build_libraries (self, libraries):
+ def build_libraries(self, libraries):
for (lib_name, build_info) in libraries:
sources = build_info.get('sources')
- if sources is None or type(sources) not in (ListType, TupleType):
- raise DistutilsSetupError, \
- ("in 'libraries' option (library '%s'), " +
- "'sources' must be present and must be " +
- "a list of source filenames") % lib_name
+ if sources is None or not isinstance(sources, (list, tuple)):
+ raise DistutilsSetupError(
+ "in 'libraries' option (library '%s'), "
+ "'sources' must be present and must be "
+ "a list of source filenames" % lib_name)
sources = list(sources)
log.info("building '%s' library", lib_name)
@@ -229,9 +204,3 @@ class build_clib (Command):
self.compiler.create_static_lib(objects, lib_name,
output_dir=self.build_clib,
debug=self.debug)
-
- # for libraries
-
- # build_libraries ()
-
-# class build_lib
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 0236a26..a439c49 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -4,12 +4,9 @@ Implements the Distutils 'build_ext' command, for building extension
modules (currently limited to C extensions, should accommodate C++
extensions ASAP)."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os, re
-from types import *
from distutils.core import Command
from distutils.errors import *
from distutils.sysconfig import customize_compiler, get_python_version
@@ -28,7 +25,7 @@ def show_compilers ():
show_compilers()
-class build_ext (Command):
+class build_ext(Command):
description = "build C/C++ extensions (compile/link to build directory)"
@@ -94,7 +91,7 @@ class build_ext (Command):
"list available compilers", show_compilers),
]
- def initialize_options (self):
+ def initialize_options(self):
self.extensions = None
self.build_lib = None
self.build_temp = None
@@ -115,7 +112,7 @@ class build_ext (Command):
self.swig_cpp = None
self.swig_opts = None
- def finalize_options (self):
+ def finalize_options(self):
from distutils import sysconfig
self.set_undefined_options('build',
@@ -130,7 +127,6 @@ class build_ext (Command):
self.extensions = self.distribution.ext_modules
-
# Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path.
py_include = sysconfig.get_python_inc()
@@ -226,11 +222,7 @@ class build_ext (Command):
else:
self.swig_opts = self.swig_opts.split(' ')
- # finalize_options ()
-
-
- def run (self):
-
+ def run(self):
from distutils.ccompiler import new_compiler
# 'self.extensions', as supplied by setup.py, is a list of
@@ -289,10 +281,7 @@ class build_ext (Command):
# Now actually compile and link everything.
self.build_extensions()
- # run ()
-
-
- def check_extensions_list (self, extensions):
+ def check_extensions_list(self, extensions):
"""Ensure that the list of extensions (presumably provided as a
command option 'extensions') is valid, i.e. it is a list of
Extension objects. We also support the old-style list of 2-tuples,
@@ -302,34 +291,33 @@ class build_ext (Command):
Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise.
"""
- if type(extensions) is not ListType:
- raise DistutilsSetupError, \
- "'ext_modules' option must be a list of Extension instances"
+ if not isinstance(extensions, list):
+ raise DistutilsSetupError(
+ "'ext_modules' option must be a list of Extension instances")
- for i in range(len(extensions)):
- ext = extensions[i]
+ for i, ext in enumerate(extensions):
if isinstance(ext, Extension):
continue # OK! (assume type-checking done
# by Extension constructor)
(ext_name, build_info) = ext
- log.warn(("old-style (ext_name, build_info) tuple found in "
- "ext_modules for extension '%s'"
- "-- please convert to Extension instance" % ext_name))
- if type(ext) is not TupleType and len(ext) != 2:
- raise DistutilsSetupError, \
- ("each element of 'ext_modules' option must be an "
+ log.warn("old-style (ext_name, build_info) tuple found in "
+ "ext_modules for extension '%s'"
+ "-- please convert to Extension instance" % ext_name)
+ if not isinstance(ext, tuple) and len(ext) != 2:
+ raise DistutilsSetupError(
+ "each element of 'ext_modules' option must be an "
"Extension instance or 2-tuple")
if not (isinstance(ext_name, basestring) and
extension_name_re.match(ext_name)):
- raise DistutilsSetupError, \
- ("first element of each tuple in 'ext_modules' "
+ raise DistutilsSetupError(
+ "first element of each tuple in 'ext_modules' "
"must be the extension name (a string)")
- if type(build_info) is not DictionaryType:
- raise DistutilsSetupError, \
- ("second element of each tuple in 'ext_modules' "
+ if not instance(build_info, DictionaryType):
+ raise DistutilsSetupError(
+ "second element of each tuple in 'ext_modules' "
"must be a dictionary (build info)")
# OK, the (ext_name, build_info) dict is type-safe: convert it
@@ -361,11 +349,10 @@ class build_ext (Command):
ext.define_macros = []
ext.undef_macros = []
for macro in macros:
- if not (type(macro) is TupleType and
- 1 <= len(macro) <= 2):
- raise DistutilsSetupError, \
- ("'macros' element of build info dict "
- "must be 1- or 2-tuple")
+ if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
+ raise DistutilsSetupError(
+ "'macros' element of build info dict "
+ "must be 1- or 2-tuple")
if len(macro) == 1:
ext.undef_macros.append(macro[0])
elif len(macro) == 2:
@@ -373,24 +360,16 @@ class build_ext (Command):
extensions[i] = ext
- # for extensions
-
- # check_extensions_list ()
-
-
- def get_source_files (self):
+ def get_source_files(self):
self.check_extensions_list(self.extensions)
filenames = []
# Wouldn't it be neat if we knew the names of header files too...
for ext in self.extensions:
filenames.extend(ext.sources)
-
return filenames
-
- def get_outputs (self):
-
+ def get_outputs(self):
# Sanity check the 'extensions' list -- can't assume this is being
# done in the same run as a 'build_extensions()' call (in fact, we
# can probably assume that it *isn't*!).
@@ -406,8 +385,6 @@ class build_ext (Command):
self.get_ext_filename(fullname)))
return outputs
- # get_outputs ()
-
def build_extensions(self):
# First, sanity-check the 'extensions' list
self.check_extensions_list(self.extensions)
@@ -417,11 +394,11 @@ class build_ext (Command):
def build_extension(self, ext):
sources = ext.sources
- if sources is None or type(sources) not in (ListType, TupleType):
- raise DistutilsSetupError, \
- ("in 'ext_modules' option (extension '%s'), " +
- "'sources' must be present and must be " +
- "a list of source filenames") % ext.name
+ if sources is None or not isinstance(sources, (list, tuple)):
+ raise DistutilsSetupError(
+ "in 'ext_modules' option (extension '%s'), "
+ "'sources' must be present and must be "
+ "a list of source filenames" % ext.name)
sources = list(sources)
fullname = self.get_ext_fullname(ext.name)
@@ -512,15 +489,12 @@ class build_ext (Command):
build_temp=self.build_temp,
target_lang=language)
-
- def swig_sources (self, sources, extension):
-
+ def swig_sources(self, sources, extension):
"""Walk the list of source files in 'sources', looking for SWIG
interface (.i) files. Run SWIG on all that are found, and
return a modified 'sources' list with SWIG source files replaced
by the generated C (or C++) files.
"""
-
new_sources = []
swig_sources = []
swig_targets = {}
@@ -569,18 +543,14 @@ class build_ext (Command):
return new_sources
- # swig_sources ()
-
- def find_swig (self):
+ def find_swig(self):
"""Return the name of the SWIG executable. On Unix, this is
just "swig" -- it should be in the PATH. Tries a bit harder on
Windows.
"""
-
if os.name == "posix":
return "swig"
elif os.name == "nt":
-
# Look for SWIG in its standard installation directory on
# Windows (or so I presume!). If we find it there, great;
# if not, act like Unix and assume it's in the PATH.
@@ -590,33 +560,28 @@ class build_ext (Command):
return fn
else:
return "swig.exe"
-
elif os.name == "os2":
# assume swig available in the PATH.
return "swig.exe"
-
else:
- raise DistutilsPlatformError, \
- ("I don't know how to find (much less run) SWIG "
- "on platform '%s'") % os.name
-
- # find_swig ()
+ raise DistutilsPlatformError(
+ "I don't know how to find (much less run) SWIG "
+ "on platform '%s'" % os.name)
# -- Name generators -----------------------------------------------
# (extension names, filenames, whatever)
- def get_ext_fullname (self, ext_name):
+ def get_ext_fullname(self, ext_name):
if self.package is None:
return ext_name
else:
return self.package + '.' + ext_name
- def get_ext_filename (self, ext_name):
+ def get_ext_filename(self, ext_name):
r"""Convert the name of an extension (eg. "foo.bar") into the name
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
-
from distutils.sysconfig import get_config_var
ext_path = ext_name.split('.')
# OS/2 has an 8 character module (extension) limit :-(
@@ -628,19 +593,18 @@ class build_ext (Command):
return os.path.join(*ext_path) + '_d' + so_ext
return os.path.join(*ext_path) + so_ext
- def get_export_symbols (self, ext):
+ def get_export_symbols(self, ext):
"""Return the list of symbols that a shared extension has to
export. This either uses 'ext.export_symbols' or, if it's not
provided, "init" + module_name. Only relevant on Windows, where
the .pyd file (DLL) must export the module "init" function.
"""
-
initfunc_name = "init" + ext.name.split('.')[-1]
if initfunc_name not in ext.export_symbols:
ext.export_symbols.append(initfunc_name)
return ext.export_symbols
- def get_libraries (self, ext):
+ def get_libraries(self, ext):
"""Return the list of libraries to link against when building a
shared extension. On most platforms, this is just 'ext.libraries';
on Windows and OS/2, we add the Python library (eg. python20.dll).
@@ -699,11 +663,9 @@ class build_ext (Command):
# don't extend ext.libraries, it may be shared with other
# extensions, it is a reference to the original list
return ext.libraries + [pythonlib, "m"] + extra
-
elif sys.platform == 'darwin':
# Don't use the default code below
return ext.libraries
-
else:
from distutils import sysconfig
if sysconfig.get_config_var('Py_ENABLE_SHARED'):
@@ -713,5 +675,3 @@ class build_ext (Command):
return ext.libraries + [pythonlib]
else:
return ext.libraries
-
-# class build_ext
diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py
index 8f56090..454424f 100644
--- a/Lib/distutils/command/build_py.py
+++ b/Lib/distutils/command/build_py.py
@@ -2,12 +2,9 @@
Implements the Distutils 'build_py' command."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
-from types import *
from glob import glob
from distutils.core import Command
@@ -32,8 +29,7 @@ class build_py (Command):
boolean_options = ['compile', 'force']
negative_opt = {'no-compile' : 'compile'}
-
- def initialize_options (self):
+ def initialize_options(self):
self.build_lib = None
self.py_modules = None
self.package = None
@@ -43,7 +39,7 @@ class build_py (Command):
self.optimize = 0
self.force = None
- def finalize_options (self):
+ def finalize_options(self):
self.set_undefined_options('build',
('build_lib', 'build_lib'),
('force', 'force'))
@@ -61,15 +57,14 @@ class build_py (Command):
# Ick, copied straight from install_lib.py (fancy_getopt needs a
# type system! Hell, *everything* needs a type system!!!)
- if type(self.optimize) is not IntType:
+ if not isinstance(self.optimize, int):
try:
self.optimize = int(self.optimize)
assert 0 <= self.optimize <= 2
except (ValueError, AssertionError):
- raise DistutilsOptionError, "optimize must be 0, 1, or 2"
-
- def run (self):
+ raise DistutilsOptionError("optimize must be 0, 1, or 2")
+ def run(self):
# XXX copy_file by default preserves atime and mtime. IMHO this is
# the right thing to do, but perhaps it should be an option -- in
# particular, a site administrator might want installed files to
@@ -99,9 +94,7 @@ class build_py (Command):
self.byte_compile(self.get_outputs(include_bytecode=0))
- # run ()
-
- def get_data_files (self):
+ def get_data_files(self):
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
data = []
if not self.packages:
@@ -125,7 +118,7 @@ class build_py (Command):
data.append((package, src_dir, build_dir, filenames))
return data
- def find_data_files (self, package, src_dir):
+ def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'"""
globs = (self.package_data.get('', [])
+ self.package_data.get(package, []))
@@ -137,7 +130,7 @@ class build_py (Command):
files.extend([fn for fn in filelist if fn not in files])
return files
- def build_package_data (self):
+ def build_package_data(self):
"""Copy data files into build directory"""
lastdir = None
for package, src_dir, build_dir, filenames in self.data_files:
@@ -147,11 +140,10 @@ class build_py (Command):
self.copy_file(os.path.join(src_dir, filename), target,
preserve_mode=False)
- def get_package_dir (self, package):
+ def get_package_dir(self, package):
"""Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any)."""
-
path = package.split('.')
if not self.package_dir:
@@ -187,23 +179,19 @@ class build_py (Command):
else:
return ''
- # get_package_dir ()
-
-
- def check_package (self, package, package_dir):
-
+ def check_package(self, package, package_dir):
# Empty dir name means current directory, which we can probably
# assume exists. Also, os.path.exists and isdir don't know about
# my "empty string means current dir" convention, so we have to
# circumvent them.
if package_dir != "":
if not os.path.exists(package_dir):
- raise DistutilsFileError, \
- "package directory '%s' does not exist" % package_dir
+ raise DistutilsFileError(
+ "package directory '%s' does not exist" % package_dir)
if not os.path.isdir(package_dir):
- raise DistutilsFileError, \
- ("supposed package directory '%s' exists, " +
- "but is not a directory") % package_dir
+ raise DistutilsFileError(
+ "supposed package directory '%s' exists, "
+ "but is not a directory" % package_dir)
# Require __init__.py for all but the "root package"
if package:
@@ -218,20 +206,14 @@ class build_py (Command):
# __init__.py doesn't exist -- so don't return the filename.
return None
- # check_package ()
-
-
- def check_module (self, module, module_file):
+ def check_module(self, module, module_file):
if not os.path.isfile(module_file):
log.warn("file %s (for module %s) not found", module_file, module)
- return 0
+ return False
else:
- return 1
+ return True
- # check_module ()
-
-
- def find_package_modules (self, package, package_dir):
+ def find_package_modules(self, package, package_dir):
self.check_package(package, package_dir)
module_files = glob(os.path.join(package_dir, "*.py"))
modules = []
@@ -246,8 +228,7 @@ class build_py (Command):
self.debug_print("excluding %s" % setup_script)
return modules
-
- def find_modules (self):
+ def find_modules(self):
"""Finds individually-specified Python modules, ie. those listed by
module name in 'self.py_modules'. Returns a list of tuples (package,
module_base, filename): 'package' is a tuple of the path through
@@ -256,7 +237,6 @@ class build_py (Command):
".py" file (relative to the distribution root) that implements the
module.
"""
-
# Map package names to tuples of useful info about the package:
# (package_dir, checked)
# package_dir - the directory where we'll find source files for
@@ -272,7 +252,6 @@ class build_py (Command):
# just the "package" for a toplevel is empty (either an empty
# string or empty list, depending on context). Differences:
# - don't check for __init__.py in directory for empty package
-
for module in self.py_modules:
path = module.split('.')
package = '.'.join(path[0:-1])
@@ -301,16 +280,12 @@ class build_py (Command):
return modules
- # find_modules ()
-
-
- def find_all_modules (self):
+ def find_all_modules(self):
"""Compute the list of all modules that will be built, whether
they are specified one-module-at-a-time ('self.py_modules') or
by whole packages ('self.packages'). Return a list of tuples
(package, module, module_file), just like 'find_modules()' and
'find_package_modules()' do."""
-
modules = []
if self.py_modules:
modules.extend(self.find_modules())
@@ -319,28 +294,16 @@ class build_py (Command):
package_dir = self.get_package_dir(package)
m = self.find_package_modules(package, package_dir)
modules.extend(m)
-
return modules
- # find_all_modules ()
+ def get_source_files(self):
+ return [module[-1] for module in self.find_all_modules()]
-
- def get_source_files (self):
-
- modules = self.find_all_modules()
- filenames = []
- for module in modules:
- filenames.append(module[-1])
-
- return filenames
-
-
- def get_module_outfile (self, build_dir, package, module):
+ def get_module_outfile(self, build_dir, package, module):
outfile_path = [build_dir] + list(package) + [module + ".py"]
return os.path.join(*outfile_path)
-
- def get_outputs (self, include_bytecode=1):
+ def get_outputs(self, include_bytecode=1):
modules = self.find_all_modules()
outputs = []
for (package, module, module_file) in modules:
@@ -361,13 +324,12 @@ class build_py (Command):
return outputs
-
- def build_module (self, module, module_file, package):
+ def build_module(self, module, module_file, package):
if isinstance(package, basestring):
package = package.split('.')
- elif type(package) not in (ListType, TupleType):
- raise TypeError, \
- "'package' must be a string (dot-separated), list, or tuple"
+ elif not isinstance(package, (list, tuple)):
+ raise TypeError(
+ "'package' must be a string (dot-separated), list, or tuple")
# Now put the module source file into the "build" area -- this is
# easy, we just copy it somewhere under self.build_lib (the build
@@ -377,25 +339,17 @@ class build_py (Command):
self.mkpath(dir)
return self.copy_file(module_file, outfile, preserve_mode=0)
-
- def build_modules (self):
-
+ def build_modules(self):
modules = self.find_modules()
for (package, module, module_file) in modules:
-
# Now "build" the module -- ie. copy the source file to
# self.build_lib (the build directory for Python source).
# (Actually, it gets copied to the directory for this package
# under self.build_lib.)
self.build_module(module, module_file, package)
- # build_modules ()
-
-
- def build_packages (self):
-
+ def build_packages(self):
for package in self.packages:
-
# Get list of (package, module, module_file) tuples based on
# scanning the package directory. 'package' is only included
# in the tuple so that 'find_modules()' and
@@ -414,10 +368,7 @@ class build_py (Command):
assert package == package_
self.build_module(module, module_file, package)
- # build_packages ()
-
-
- def byte_compile (self, files):
+ def byte_compile(self, files):
from distutils.util import byte_compile
prefix = self.build_lib
if prefix[-1] != os.sep:
@@ -426,12 +377,9 @@ class build_py (Command):
# XXX this code is essentially the same as the 'byte_compile()
# method of the "install_lib" command, except for the determination
# of the 'prefix' string. Hmmm.
-
if self.compile:
byte_compile(files, optimize=0,
force=self.force, prefix=prefix, dry_run=self.dry_run)
if self.optimize > 0:
byte_compile(files, optimize=self.optimize,
force=self.force, prefix=prefix, dry_run=self.dry_run)
-
-# class build_py
diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py
index 511b82f..176e6e1 100644
--- a/Lib/distutils/command/build_scripts.py
+++ b/Lib/distutils/command/build_scripts.py
@@ -2,8 +2,6 @@
Implements the Distutils 'build_scripts' command."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os, re
@@ -17,7 +15,7 @@ from distutils import log
# check if Python is called on the first line with this expression
first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
-class build_scripts (Command):
+class build_scripts(Command):
description = "\"build\" scripts (copy and fixup #! line)"
@@ -30,14 +28,14 @@ class build_scripts (Command):
boolean_options = ['force']
- def initialize_options (self):
+ def initialize_options(self):
self.build_dir = None
self.scripts = None
self.force = None
self.executable = None
self.outfiles = None
- def finalize_options (self):
+ def finalize_options(self):
self.set_undefined_options('build',
('build_scripts', 'build_dir'),
('force', 'force'),
@@ -47,13 +45,13 @@ class build_scripts (Command):
def get_source_files(self):
return self.scripts
- def run (self):
+ def run(self):
if not self.scripts:
return
self.copy_scripts()
- def copy_scripts (self):
+ def copy_scripts(self):
"""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',
ie. starts with "\#!" and contains "python"), then adjust the first
@@ -62,7 +60,7 @@ class build_scripts (Command):
self.mkpath(self.build_dir)
outfiles = []
for script in self.scripts:
- adjust = 0
+ adjust = False
script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.basename(script))
outfiles.append(outfile)
@@ -88,7 +86,7 @@ class build_scripts (Command):
match = first_line_re.match(first_line)
if match:
- adjust = 1
+ adjust = True
post_interp = match.group(1) or ''
if adjust:
@@ -125,7 +123,3 @@ class build_scripts (Command):
log.info("changing mode of %s from %o to %o",
file, oldmode, newmode)
os.chmod(file, newmode)
-
- # copy_scripts ()
-
-# class build_scripts
diff --git a/Lib/distutils/command/clean.py b/Lib/distutils/command/clean.py
index 02189c5..ae1d22c 100644
--- a/Lib/distutils/command/clean.py
+++ b/Lib/distutils/command/clean.py
@@ -4,8 +4,6 @@ Implements the Distutils 'clean' command."""
# 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$"
import os
@@ -13,7 +11,7 @@ from distutils.core import Command
from distutils.dir_util import remove_tree
from distutils import log
-class clean (Command):
+class clean(Command):
description = "clean up temporary files from 'build' command"
user_options = [
@@ -78,5 +76,3 @@ class clean (Command):
log.info("removing '%s'", self.build_base)
except OSError:
pass
-
-# class clean
diff --git a/Lib/distutils/command/command_template b/Lib/distutils/command/command_template
index 50bbab7..6106819 100644
--- a/Lib/distutils/command/command_template
+++ b/Lib/distutils/command/command_template
@@ -10,7 +10,7 @@ __revision__ = "$Id$"
from distutils.core import Command
-class x (Command):
+class x(Command):
# Brief (40-50 characters) description of the command
description = ""
@@ -21,25 +21,13 @@ class x (Command):
""),
]
-
- def initialize_options (self):
+ def initialize_options(self):
self. = None
self. = None
self. = None
- # initialize_options()
-
-
- def finalize_options (self):
+ def finalize_options(self):
if self.x is None:
self.x =
- # finalize_options()
-
-
- def run (self):
-
-
- # run()
-
-# class x
+ def run(self):
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 04cfcde..a601234 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -9,21 +9,17 @@ configure-like tasks: "try to compile this C code", or "figure out where
this header file lives".
"""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os, re
-from types import *
from distutils.core import Command
from distutils.errors import DistutilsExecError
from distutils.sysconfig import customize_compiler
from distutils import log
-LANG_EXT = {'c': '.c',
- 'c++': '.cxx'}
+LANG_EXT = {"c": ".c", "c++": ".cxx"}
-class config (Command):
+class config(Command):
description = "prepare to build"
@@ -53,7 +49,7 @@ class config (Command):
# The three standard command methods: since the "config" command
# does nothing by default, these are empty.
- def initialize_options (self):
+ def initialize_options(self):
self.compiler = None
self.cc = None
self.include_dirs = None
@@ -70,7 +66,7 @@ class config (Command):
# to clean at some point
self.temp_files = []
- def finalize_options (self):
+ def finalize_options(self):
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
elif isinstance(self.include_dirs, basestring):
@@ -86,16 +82,14 @@ class config (Command):
elif isinstance(self.library_dirs, basestring):
self.library_dirs = self.library_dirs.split(os.pathsep)
-
- def run (self):
+ def run(self):
pass
-
# Utility methods for actual "config" commands. The interfaces are
# loosely based on Autoconf macros of similar names. Sub-classes
# may use these freely.
- def _check_compiler (self):
+ def _check_compiler(self):
"""Check that 'self.compiler' really is a CCompiler object;
if not, make it one.
"""
@@ -113,8 +107,7 @@ class config (Command):
if self.library_dirs:
self.compiler.set_library_dirs(self.library_dirs)
-
- def _gen_temp_sourcefile (self, body, headers, lang):
+ def _gen_temp_sourcefile(self, body, headers, lang):
filename = "_configtest" + LANG_EXT[lang]
file = open(filename, "w")
if headers:
@@ -127,14 +120,14 @@ class config (Command):
file.close()
return filename
- def _preprocess (self, body, headers, include_dirs, lang):
+ def _preprocess(self, body, headers, include_dirs, lang):
src = self._gen_temp_sourcefile(body, headers, lang)
out = "_configtest.i"
self.temp_files.extend([src, out])
self.compiler.preprocess(src, out, include_dirs=include_dirs)
return (src, out)
- def _compile (self, body, headers, include_dirs, lang):
+ def _compile(self, body, headers, include_dirs, lang):
src = self._gen_temp_sourcefile(body, headers, lang)
if self.dump_source:
dump_file(src, "compiling '%s':" % src)
@@ -143,9 +136,8 @@ class config (Command):
self.compiler.compile([src], include_dirs=include_dirs)
return (src, obj)
- def _link (self, body,
- headers, include_dirs,
- libraries, library_dirs, lang):
+ def _link(self, body, headers, include_dirs, libraries,
+ library_dirs, lang):
(src, obj) = self._compile(body, headers, include_dirs, lang)
prog = os.path.splitext(os.path.basename(src))[0]
self.compiler.link_executable([obj], prog,
@@ -159,7 +151,7 @@ class config (Command):
return (src, obj, prog)
- def _clean (self, *filenames):
+ def _clean(self, *filenames):
if not filenames:
filenames = self.temp_files
self.temp_files = []
@@ -181,7 +173,7 @@ class config (Command):
# XXX need access to the header search path and maybe default macros.
- def try_cpp (self, body=None, headers=None, include_dirs=None, lang="c"):
+ def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
"""Construct a source file from 'body' (a string containing lines
of C/C++ code) and 'headers' (a list of header files to include)
and run it through the preprocessor. Return true if the
@@ -190,17 +182,17 @@ class config (Command):
"""
from distutils.ccompiler import CompileError
self._check_compiler()
- ok = 1
+ ok = True
try:
self._preprocess(body, headers, include_dirs, lang)
except CompileError:
- ok = 0
+ ok = False
self._clean()
return ok
- def search_cpp (self, pattern, body=None,
- headers=None, include_dirs=None, lang="c"):
+ def search_cpp(self, pattern, body=None, headers=None,
+ include_dirs=None, lang="c"):
"""Construct a source file (just like 'try_cpp()'), run it through
the preprocessor, and return true if any line of the output matches
'pattern'. 'pattern' should either be a compiled regex object or a
@@ -216,20 +208,20 @@ class config (Command):
pattern = re.compile(pattern)
file = open(out)
- match = 0
- while 1:
+ match = False
+ while True:
line = file.readline()
if line == '':
break
if pattern.search(line):
- match = 1
+ match = True
break
file.close()
self._clean()
return match
- def try_compile (self, body, headers=None, include_dirs=None, lang="c"):
+ def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
"""Try to compile a source file built from 'body' and 'headers'.
Return true on success, false otherwise.
"""
@@ -237,18 +229,16 @@ class config (Command):
self._check_compiler()
try:
self._compile(body, headers, include_dirs, lang)
- ok = 1
+ ok = True
except CompileError:
- ok = 0
+ ok = False
log.info(ok and "success!" or "failure.")
self._clean()
return ok
- def try_link (self, body,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- lang="c"):
+ def try_link(self, body, headers=None, include_dirs=None,
+ libraries=None, library_dirs=None, lang="c"):
"""Try to compile and link a source file, built from 'body' and
'headers', to executable form. Return true on success, false
otherwise.
@@ -258,18 +248,16 @@ class config (Command):
try:
self._link(body, headers, include_dirs,
libraries, library_dirs, lang)
- ok = 1
+ ok = True
except (CompileError, LinkError):
- ok = 0
+ ok = False
log.info(ok and "success!" or "failure.")
self._clean()
return ok
- def try_run (self, body,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- lang="c"):
+ def try_run(self, body, headers=None, include_dirs=None,
+ libraries=None, library_dirs=None, lang="c"):
"""Try to compile, link to an executable, and run a program
built from 'body' and 'headers'. Return true on success, false
otherwise.
@@ -280,9 +268,9 @@ class config (Command):
src, obj, exe = self._link(body, headers, include_dirs,
libraries, library_dirs, lang)
self.spawn([exe])
- ok = 1
+ ok = True
except (CompileError, LinkError, DistutilsExecError):
- ok = 0
+ ok = False
log.info(ok and "success!" or "failure.")
self._clean()
@@ -293,11 +281,8 @@ class config (Command):
# (these are the ones that are actually likely to be useful
# when implementing a real-world config command!)
- def check_func (self, func,
- headers=None, include_dirs=None,
- libraries=None, library_dirs=None,
- decl=0, call=0):
-
+ def check_func(self, func, headers=None, include_dirs=None,
+ libraries=None, library_dirs=None, decl=0, call=0):
"""Determine if function 'func' is available by constructing a
source file that refers to 'func', and compiles and links it.
If everything succeeds, returns true; otherwise returns false.
@@ -311,7 +296,6 @@ class config (Command):
calls it. 'libraries' and 'library_dirs' are used when
linking.
"""
-
self._check_compiler()
body = []
if decl:
@@ -327,10 +311,8 @@ class config (Command):
return self.try_link(body, headers, include_dirs,
libraries, library_dirs)
- # check_func ()
-
- def check_lib (self, library, library_dirs=None,
- headers=None, include_dirs=None, other_libraries=[]):
+ def check_lib(self, library, library_dirs=None, headers=None,
+ include_dirs=None, other_libraries=[]):
"""Determine if 'library' is available to be linked against,
without actually checking that any particular symbols are provided
by it. 'headers' will be used in constructing the source file to
@@ -340,12 +322,11 @@ class config (Command):
has symbols that depend on other libraries.
"""
self._check_compiler()
- return self.try_link("int main (void) { }",
- headers, include_dirs,
- [library]+other_libraries, library_dirs)
+ return self.try_link("int main (void) { }", headers, include_dirs,
+ [library] + other_libraries, library_dirs)
- def check_header (self, header, include_dirs=None,
- library_dirs=None, lang="c"):
+ def check_header(self, header, include_dirs=None, library_dirs=None,
+ lang="c"):
"""Determine if the system header file named by 'header_file'
exists and can be found by the preprocessor; return true if so,
false otherwise.
@@ -354,10 +335,7 @@ class config (Command):
include_dirs=include_dirs)
-# class config
-
-
-def dump_file (filename, head=None):
+def dump_file(filename, head=None):
if head is None:
print(filename + ":")
else:
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index a6543ba..29cda1e 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -4,12 +4,9 @@ Implements the Distutils 'install' command."""
from distutils import log
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
-from types import *
from distutils.core import Command
from distutils.debug import DEBUG
from distutils.sysconfig import get_config_vars
@@ -141,7 +138,7 @@ class install (Command):
negative_opt = {'no-compile' : 'compile'}
- def initialize_options (self):
+ def initialize_options(self):
# High-level options: these select both an installation base
# and scheme.
@@ -215,7 +212,7 @@ class install (Command):
# party Python modules on various platforms given a wide
# 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()',
# 'finalize_other()', and 'select_scheme()') is where the default
@@ -233,13 +230,13 @@ class install (Command):
if ((self.prefix or self.exec_prefix or self.home) and
(self.install_base or self.install_platbase)):
- raise DistutilsOptionError, \
- ("must supply either prefix/exec-prefix/home or " +
+ raise DistutilsOptionError(
+ "must supply either prefix/exec-prefix/home or " +
"install-base/install-platbase -- not both")
if self.home and (self.prefix or self.exec_prefix):
- raise DistutilsOptionError, \
- "must supply either home or prefix/exec-prefix -- not both"
+ raise DistutilsOptionError(
+ "must supply either home or prefix/exec-prefix -- not both")
# Next, stuff that's wrong (or dubious) only on certain platforms.
if os.name != "posix":
@@ -341,10 +338,8 @@ class install (Command):
# Punt on doc directories for now -- after all, we're punting on
# documentation completely!
- # finalize_options ()
-
- def dump_dirs (self, msg):
+ def dump_dirs(self, msg):
if DEBUG:
from distutils.fancy_getopt import longopt_xlate
print(msg + ":")
@@ -362,8 +357,7 @@ class install (Command):
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_lib is None and
self.install_purelib is None and
@@ -371,8 +365,8 @@ class install (Command):
self.install_headers is None or
self.install_scripts is None or
self.install_data is None):
- raise DistutilsOptionError, \
- ("install-base or install-platbase supplied, but "
+ raise DistutilsOptionError(
+ "install-base or install-platbase supplied, but "
"installation scheme is incomplete")
return
@@ -382,8 +376,8 @@ class install (Command):
else:
if self.prefix is None:
if self.exec_prefix is not None:
- raise DistutilsOptionError, \
- "must not supply exec-prefix without prefix"
+ raise DistutilsOptionError(
+ "must not supply exec-prefix without prefix")
self.prefix = os.path.normpath(sys.prefix)
self.exec_prefix = os.path.normpath(sys.exec_prefix)
@@ -396,11 +390,8 @@ class install (Command):
self.install_platbase = self.exec_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:
self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home")
@@ -412,13 +403,11 @@ class install (Command):
try:
self.select_scheme(os.name)
except KeyError:
- raise DistutilsPlatformError, \
- "I don't know how to install stuff on '%s'" % os.name
-
- # finalize_other ()
+ raise DistutilsPlatformError(
+ "I don't know how to install stuff on '%s'" % os.name)
- def select_scheme (self, name):
+ def select_scheme(self, name):
# it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name]
for key in SCHEME_KEYS:
@@ -427,7 +416,7 @@ class install (Command):
setattr(self, attrname, scheme[key])
- def _expand_attrs (self, attrs):
+ def _expand_attrs(self, attrs):
for attr in attrs:
val = getattr(self, attr)
if val is not None:
@@ -437,12 +426,12 @@ class install (Command):
setattr(self, attr, val)
- def expand_basedirs (self):
+ def expand_basedirs(self):
self._expand_attrs(['install_base',
'install_platbase',
'root'])
- def expand_dirs (self):
+ def expand_dirs(self):
self._expand_attrs(['install_purelib',
'install_platlib',
'install_lib',
@@ -451,14 +440,12 @@ class install (Command):
'install_data',])
- def convert_paths (self, *names):
+ def convert_paths(self, *names):
for name in names:
attr = "install_" + name
setattr(self, attr, convert_path(getattr(self, attr)))
-
- def handle_extra_path (self):
-
+ def handle_extra_path(self):
if self.extra_path is None:
self.extra_path = self.distribution.extra_path
@@ -471,8 +458,8 @@ class install (Command):
elif len(self.extra_path) == 2:
(path_file, extra_dirs) = self.extra_path
else:
- raise DistutilsOptionError, \
- ("'extra_path' option must be a list, tuple, or "
+ raise DistutilsOptionError(
+ "'extra_path' option must be a list, tuple, or "
"comma-separated string with 1 or 2 elements")
# convert to local form in case Unix notation used (as it
@@ -488,10 +475,7 @@ class install (Command):
self.path_file = path_file
self.extra_dirs = extra_dirs
- # handle_extra_path ()
-
-
- def change_roots (self, *names):
+ def change_roots(self, *names):
for name in names:
attr = "install_" + name
setattr(self, attr, change_root(self.root, getattr(self, attr)))
@@ -499,8 +483,7 @@ class install (Command):
# -- Command execution methods -------------------------------------
- def run (self):
-
+ def run(self):
# Obviously have to build before we can install
if not self.skip_build:
self.run_command('build')
@@ -535,9 +518,7 @@ class install (Command):
"you'll have to change the search path yourself"),
self.install_lib)
- # run ()
-
- def create_path_file (self):
+ def create_path_file(self):
filename = os.path.join(self.install_libbase,
self.path_file + ".pth")
if self.install_path_file:
@@ -550,7 +531,7 @@ class install (Command):
# -- Reporting methods ---------------------------------------------
- def get_outputs (self):
+ def get_outputs(self):
# Assemble the outputs of all the sub-commands.
outputs = []
for cmd_name in self.get_sub_commands():
@@ -567,7 +548,7 @@ class install (Command):
return outputs
- def get_inputs (self):
+ def get_inputs(self):
# XXX gee, this looks familiar ;-(
inputs = []
for cmd_name in self.get_sub_commands():
@@ -579,19 +560,19 @@ class install (Command):
# -- Predicates for sub-command list -------------------------------
- def has_lib (self):
+ def has_lib(self):
"""Return true if the current distribution has any Python
modules to install."""
return (self.distribution.has_pure_modules() or
self.distribution.has_ext_modules())
- def has_headers (self):
+ def has_headers(self):
return self.distribution.has_headers()
- def has_scripts (self):
+ def has_scripts(self):
return self.distribution.has_scripts()
- def has_data (self):
+ def has_data(self):
return self.distribution.has_data_files()
@@ -603,5 +584,3 @@ class install (Command):
('install_data', has_data),
('install_egg_info', lambda self:True),
]
-
-# class install
diff --git a/Lib/distutils/command/install_data.py b/Lib/distutils/command/install_data.py
index a951944..2fbac63 100644
--- a/Lib/distutils/command/install_data.py
+++ b/Lib/distutils/command/install_data.py
@@ -5,15 +5,13 @@ platform-independent data files."""
# contributed by Bastian Kleineidam
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import os
from distutils.core import Command
from distutils.util import change_root, convert_path
-class install_data (Command):
+class install_data(Command):
description = "install data files"
@@ -28,7 +26,7 @@ class install_data (Command):
boolean_options = ['force']
- def initialize_options (self):
+ def initialize_options(self):
self.install_dir = None
self.outfiles = []
self.root = None
@@ -37,14 +35,14 @@ class install_data (Command):
self.data_files = self.distribution.data_files
self.warn_dir = 1
- def finalize_options (self):
+ def finalize_options(self):
self.set_undefined_options('install',
('install_data', 'install_dir'),
('root', 'root'),
('force', 'force'),
)
- def run (self):
+ def run(self):
self.mkpath(self.install_dir)
for f in self.data_files:
if isinstance(f, basestring):
@@ -77,8 +75,8 @@ class install_data (Command):
(out, _) = self.copy_file(data, dir)
self.outfiles.append(out)
- def get_inputs (self):
+ def get_inputs(self):
return self.data_files or []
- def get_outputs (self):
+ def get_outputs(self):
return self.outfiles
diff --git a/Lib/distutils/command/install_headers.py b/Lib/distutils/command/install_headers.py
index 2bd1b04..7114eaf 100644
--- a/Lib/distutils/command/install_headers.py
+++ b/Lib/distutils/command/install_headers.py
@@ -3,15 +3,13 @@
Implements the Distutils 'install_headers' command, to install C/C++ header
files to the Python include directory."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import os
from distutils.core import Command
-class install_headers (Command):
+class install_headers(Command):
description = "install C/C++ header files"
@@ -23,18 +21,18 @@ class install_headers (Command):
boolean_options = ['force']
- def initialize_options (self):
+ def initialize_options(self):
self.install_dir = None
self.force = 0
self.outfiles = []
- def finalize_options (self):
+ def finalize_options(self):
self.set_undefined_options('install',
('install_headers', 'install_dir'),
('force', 'force'))
- def run (self):
+ def run(self):
headers = self.distribution.headers
if not headers:
return
@@ -44,10 +42,8 @@ class install_headers (Command):
(out, _) = self.copy_file(header, self.install_dir)
self.outfiles.append(out)
- def get_inputs (self):
+ def get_inputs(self):
return self.distribution.headers or []
- def get_outputs (self):
+ def get_outputs(self):
return self.outfiles
-
-# class install_headers
diff --git a/Lib/distutils/command/install_lib.py b/Lib/distutils/command/install_lib.py
index 4efaf9c..ac620fc 100644
--- a/Lib/distutils/command/install_lib.py
+++ b/Lib/distutils/command/install_lib.py
@@ -1,9 +1,6 @@
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
-from types import IntType
from distutils.core import Command
from distutils.errors import DistutilsOptionError
@@ -11,7 +8,7 @@ from distutils.errors import DistutilsOptionError
# Extension for Python source files.
PYTHON_SOURCE_EXTENSION = ".py"
-class install_lib (Command):
+class install_lib(Command):
description = "install all Python modules (extensions and pure Python)"
@@ -45,8 +42,7 @@ class install_lib (Command):
boolean_options = ['force', 'compile', 'skip-build']
negative_opt = {'no-compile' : 'compile'}
-
- def initialize_options (self):
+ def initialize_options(self):
# let the 'install' command dictate our installation directory
self.install_dir = None
self.build_dir = None
@@ -55,7 +51,7 @@ class install_lib (Command):
self.optimize = None
self.skip_build = None
- def finalize_options (self):
+ def finalize_options(self):
# Get all the information we need to install pure Python modules
# from the umbrella 'install' command -- build (source) directory,
@@ -70,19 +66,18 @@ class install_lib (Command):
)
if self.compile is None:
- self.compile = 1
+ self.compile = True
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:
self.optimize = int(self.optimize)
assert 0 <= self.optimize <= 2
except (ValueError, AssertionError):
- raise DistutilsOptionError, "optimize must be 0, 1, or 2"
-
- def run (self):
+ raise DistutilsOptionError("optimize must be 0, 1, or 2")
+ def run(self):
# Make sure we have built everything we need first
self.build()
@@ -95,20 +90,18 @@ class install_lib (Command):
if outfiles is not None and self.distribution.has_pure_modules():
self.byte_compile(outfiles)
- # run ()
-
# -- Top-level worker functions ------------------------------------
# (called from 'run()')
- def build (self):
+ def build(self):
if not self.skip_build:
if self.distribution.has_pure_modules():
self.run_command('build_py')
if self.distribution.has_ext_modules():
self.run_command('build_ext')
- def install (self):
+ def install(self):
if os.path.isdir(self.build_dir):
outfiles = self.copy_tree(self.build_dir, self.install_dir)
else:
@@ -117,7 +110,7 @@ class install_lib (Command):
return
return outfiles
- def byte_compile (self, files):
+ def byte_compile(self, files):
from distutils.util import byte_compile
# Get the "--root" directory supplied to the "install" command,
@@ -138,8 +131,7 @@ class install_lib (Command):
# -- 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:
return []
@@ -154,9 +146,7 @@ class install_lib (Command):
return outputs
- # _mutate_outputs ()
-
- def _bytecode_filenames (self, py_filenames):
+ def _bytecode_filenames(self, py_filenames):
bytecode_files = []
for py_file in py_filenames:
# Since build_py handles package data installation, the
@@ -176,7 +166,7 @@ class install_lib (Command):
# -- External interface --------------------------------------------
# (called by outsiders)
- def get_outputs (self):
+ def get_outputs(self):
"""Return the list of files that would be installed if this command
were actually run. Not affected by the "dry-run" flag or whether
modules have actually been built yet.
@@ -197,9 +187,7 @@ class install_lib (Command):
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
files that get installed as they are named in the build tree.
The files in this list correspond one-to-one to the output
@@ -216,5 +204,3 @@ class install_lib (Command):
inputs.extend(build_ext.get_outputs())
return inputs
-
-# class install_lib
diff --git a/Lib/distutils/command/install_scripts.py b/Lib/distutils/command/install_scripts.py
index da2da35..ea8d5aa 100644
--- a/Lib/distutils/command/install_scripts.py
+++ b/Lib/distutils/command/install_scripts.py
@@ -5,8 +5,6 @@ Python scripts."""
# contributed by Bastian Kleineidam
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import os
@@ -14,7 +12,8 @@ from distutils.core import Command
from distutils import log
from stat import ST_MODE
-class install_scripts (Command):
+
+class install_scripts(Command):
description = "install scripts (Python or otherwise)"
@@ -27,14 +26,13 @@ class install_scripts (Command):
boolean_options = ['force', 'skip-build']
-
- def initialize_options (self):
+ def initialize_options(self):
self.install_dir = None
self.force = 0
self.build_dir = 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('install',
('install_scripts', 'install_dir'),
@@ -42,7 +40,7 @@ class install_scripts (Command):
('skip_build', 'skip_build'),
)
- def run (self):
+ def run(self):
if not self.skip_build:
self.run_command('build_scripts')
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
@@ -57,10 +55,8 @@ class install_scripts (Command):
log.info("changing mode of %s to %o", file, mode)
os.chmod(file, mode)
- def get_inputs (self):
+ def get_inputs(self):
return self.distribution.scripts or []
def get_outputs(self):
return self.outfiles or []
-
-# class install_scripts
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
index 8e1c066..b1c7648 100644
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -2,12 +2,9 @@
Implements the Distutils 'sdist' command (create a source distribution)."""
-# This module should be kept compatible with Python 2.1.
-
__revision__ = "$Id$"
import sys, os
-from types import *
from glob import glob
from distutils.core import Command
from distutils import dir_util, dep_util, file_util, archive_util
@@ -82,7 +79,7 @@ class sdist (Command):
default_format = { 'posix': 'gztar',
'nt': 'zip' }
- def initialize_options (self):
+ def initialize_options(self):
# 'template' and 'manifest' are, respectively, the names of
# the manifest template and manifest file.
self.template = None
@@ -103,7 +100,7 @@ class sdist (Command):
self.archive_files = None
- def finalize_options (self):
+ def finalize_options(self):
if self.manifest is None:
self.manifest = "MANIFEST"
if self.template is None:
@@ -114,21 +111,20 @@ class sdist (Command):
try:
self.formats = [self.default_format[os.name]]
except KeyError:
- raise DistutilsPlatformError, \
- "don't know how to create source distributions " + \
- "on platform %s" % os.name
+ raise DistutilsPlatformError(
+ "don't know how to create source distributions "
+ "on platform %s" % os.name)
bad_format = archive_util.check_archive_formats(self.formats)
if bad_format:
- raise DistutilsOptionError, \
- "unknown archive format '%s'" % bad_format
+ raise DistutilsOptionError(
+ "unknown archive format '%s'" % bad_format)
if self.dist_dir is None:
self.dist_dir = "dist"
- def run (self):
-
+ def run(self):
# 'filelist' contains the list of files that will make up the
# manifest
self.filelist = FileList()
@@ -150,8 +146,7 @@ class sdist (Command):
# or zipfile, or whatever.
self.make_distribution()
-
- def check_metadata (self):
+ def check_metadata(self):
"""Ensure that all required elements of meta-data (name, version,
URL, (author and author_email) or (maintainer and
maintainer_email)) are supplied by the Distribution object; warn if
@@ -181,17 +176,13 @@ class sdist (Command):
"or (maintainer and maintainer_email) " +
"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
distribution, and put it in 'self.filelist'. This might involve
reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all
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
# manifest; if so, we'll regenerate the manifest.
template_exists = os.path.isfile(self.template)
@@ -231,9 +222,9 @@ class sdist (Command):
# Regenerate the manifest if necessary (or if explicitly told to)
if manifest_outofdate or neither_exists or force_regen:
if not template_exists:
- self.warn(("manifest template '%s' does not exist " +
- "(using default file list)") %
- self.template)
+ self.warn("manifest template '%s' does not exist "
+ "(using default file list)"
+ % self.template)
self.filelist.findall()
if self.use_defaults:
@@ -251,10 +242,8 @@ class sdist (Command):
else:
self.read_manifest()
- # get_file_list ()
-
- def add_defaults (self):
+ def add_defaults(self):
"""Add all the default files to self.filelist:
- README or README.txt
- setup.py
@@ -265,15 +254,14 @@ class sdist (Command):
Warns if (README or README.txt) or setup.py are missing; everything
else is optional.
"""
-
standards = [('README', 'README.txt'), self.distribution.script_name]
for fn in standards:
- if type(fn) is TupleType:
+ if isinstance(fn, tuple):
alts = fn
- got_it = 0
+ got_it = False
for fn in alts:
if os.path.exists(fn):
- got_it = 1
+ got_it = True
self.filelist.append(fn)
break
@@ -308,25 +296,18 @@ class sdist (Command):
build_scripts = self.get_finalized_command('build_scripts')
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.
(usually "MANIFEST.in") The parsing and processing is done by
'self.filelist', which updates itself accordingly.
"""
log.info("reading manifest template '%s'", self.template)
- template = TextFile(self.template,
- strip_comments=1,
- skip_blanks=1,
- join_lines=1,
- lstrip_ws=1,
- rstrip_ws=1,
+ template = TextFile(self.template, strip_comments=1, skip_blanks=1,
+ join_lines=1, lstrip_ws=1, rstrip_ws=1,
collapse_join=1)
- while 1:
+ while True:
line = template.readline()
if line is None: # end of file
break
@@ -338,10 +319,7 @@ class sdist (Command):
template.current_line,
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
by 'read_template()', but really don't belong there:
* the build tree (typically "build")
@@ -356,8 +334,7 @@ class sdist (Command):
self.filelist.exclude_pattern(None, prefix=base_dir)
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
by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'.
@@ -366,17 +343,14 @@ class sdist (Command):
(self.manifest, self.filelist.files),
"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
fill in 'self.filelist', the list of files to include in the source
distribution.
"""
log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest)
- while 1:
+ while True:
line = manifest.readline()
if line == '': # end of file
break
@@ -384,10 +358,7 @@ class sdist (Command):
line = line[0:-1]
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
distribution archive. All directories implied by the filenames in
'files' are created under 'base_dir', and then we hard link or copy
@@ -429,9 +400,7 @@ class sdist (Command):
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
tree with 'make_release_tree()'; then, we create all required
archive files (according to 'self.formats') from the release tree.
@@ -456,10 +425,8 @@ class sdist (Command):
if not self.keep_temp:
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
was run, or None if the command hasn't run yet.
"""
return self.archive_files
-
-# class sdist
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index 1ca2fb9..b49acd1 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -170,7 +170,7 @@ class upload(Command):
elif schema == 'https':
http = httplib.HTTPSConnection(netloc)
else:
- raise AssertionError, "unsupported schema "+schema
+ raise AssertionError("unsupported schema "+schema)
data = ''
loglevel = log.INFO