[Python-checkins] distutils2: A touch of PEP 8 and pyflaking
tarek.ziade
python-checkins at python.org
Sun Dec 26 14:21:44 CET 2010
tarek.ziade pushed 89c74f518a58 to distutils2:
http://hg.python.org/distutils2/rev/89c74f518a58
changeset: 833:89c74f518a58
user: ?ric Araujo <merwok at netwok.org>
date: Tue Nov 16 06:27:08 2010 +0100
summary:
A touch of PEP 8 and pyflaking
files:
distutils2/command/__init__.py
distutils2/command/build.py
distutils2/command/cmd.py
distutils2/command/install_dist.py
distutils2/compiler/__init__.py
distutils2/tests/test_command_install_dist.py
distutils2/tests/test_index_simple.py
distutils2/tests/test_metadata.py
diff --git a/distutils2/command/__init__.py b/distutils2/command/__init__.py
--- a/distutils2/command/__init__.py
+++ b/distutils2/command/__init__.py
@@ -31,24 +31,23 @@
def get_command_names():
- """Returns registered commands"""
return sorted(_COMMANDS.keys())
+ """Return registered commands"""
def set_command(location):
- klass = resolve_name(location)
- # we want to do the duck-type checking here
- # XXX
- _COMMANDS[klass.get_command_name()] = klass
+ cls = resolve_name(location)
+ # XXX we want to do the duck-type checking here
+ _COMMANDS[cls.get_command_name()] = cls
def get_command_class(name):
"""Return the registered command"""
try:
- klass = _COMMANDS[name]
- if isinstance(klass, str):
- klass = resolve_name(klass)
- _COMMANDS[name] = klass
- return klass
+ cls = _COMMANDS[name]
+ if isinstance(cls, str):
+ cls = resolve_name(cls)
+ _COMMANDS[name] = cls
+ return cls
except KeyError:
raise DistutilsModuleError("Invalid command %s" % name)
diff --git a/distutils2/command/build.py b/distutils2/command/build.py
--- a/distutils2/command/build.py
+++ b/distutils2/command/build.py
@@ -127,27 +127,27 @@
# Run all relevant sub-commands. This will be some subset of:
# - build_py - pure Python modules
# - build_clib - standalone C libraries
- # - build_ext - Python extensions
- # - build_scripts - (Python) scripts
+ # - build_ext - Python extension modules
+ # - build_scripts - Python scripts
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
# -- 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()
- sub_commands = [('build_py', has_pure_modules),
- ('build_clib', has_c_libraries),
- ('build_ext', has_ext_modules),
+ sub_commands = [('build_py', has_pure_modules),
+ ('build_clib', has_c_libraries),
+ ('build_ext', has_ext_modules),
('build_scripts', has_scripts),
]
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -19,6 +19,7 @@
except ImportError:
from distutils2._backport.shutil import make_archive
+
class Command(object):
"""Abstract base class for defining command classes, the "worker bees"
of the Distutils. A useful analogy for command classes is to think of
@@ -57,7 +58,6 @@
pre_hook = None
post_hook = None
-
# -- Creation/initialization methods -------------------------------
def __init__(self, dist):
@@ -69,9 +69,9 @@
from distutils2.dist import Distribution
if not isinstance(dist, Distribution):
- raise TypeError, "dist must be a Distribution instance"
+ raise TypeError("dist must be a Distribution instance")
if self.__class__ is Command:
- raise RuntimeError, "Command is an abstract class"
+ raise RuntimeError("Command is an abstract class")
self.distribution = dist
self.initialize_options()
@@ -143,8 +143,8 @@
This method must be implemented by all command classes.
"""
- raise RuntimeError, \
- "abstract method -- subclass %s must override" % self.__class__
+ raise RuntimeError(
+ "abstract method -- subclass %s must override" % self.__class__)
def finalize_options(self):
"""Set final values for all the options that this command supports.
@@ -157,9 +157,8 @@
This method must be implemented by all command classes.
"""
- raise RuntimeError, \
- "abstract method -- subclass %s must override" % self.__class__
-
+ raise RuntimeError(
+ "abstract method -- subclass %s must override" % self.__class__)
def dump_options(self, header=None, indent=""):
if header is None:
@@ -184,8 +183,8 @@
This method must be implemented by all command classes.
"""
- raise RuntimeError, \
- "abstract method -- subclass %s must override" % self.__class__
+ raise RuntimeError(
+ "abstract method -- subclass %s must override" % self.__class__)
def announce(self, msg, level=logging.INFO):
"""If the current verbosity level is of greater than or equal to
@@ -237,8 +236,8 @@
setattr(self, option, default)
return default
elif not isinstance(val, str):
- raise DistutilsOptionError, \
- "'%s' must be a %s (got `%s`)" % (option, what, val)
+ raise DistutilsOptionError("'%s' must be a %s (got `%s`)" %
+ (option, what, val))
return val
def ensure_string(self, option, default=None):
@@ -248,7 +247,7 @@
self._ensure_stringlike(option, "string", default)
def ensure_string_list(self, option):
- """Ensure that 'option' is a list of strings. If 'option' is
+ r"""Ensure that 'option' is a list of strings. If 'option' is
currently a string, we split it either on /,\s*/ or /\s+/, so
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
["foo", "bar", "baz"].
@@ -270,17 +269,15 @@
ok = 0
if not ok:
- raise DistutilsOptionError, \
- "'%s' must be a list of strings (got %r)" % \
- (option, val)
-
+ raise DistutilsOptionError(
+ "'%s' must be a list of strings (got %r)" % (option, val))
def _ensure_tested_string(self, option, tester,
what, error_fmt, default=None):
val = self._ensure_stringlike(option, what, default)
if val is not None and not tester(val):
- raise DistutilsOptionError, \
- ("error in '%s' option: " + error_fmt) % (option, val)
+ raise DistutilsOptionError(
+ ("error in '%s' option: " + error_fmt) % (option, val))
def ensure_filename(self, option):
"""Ensure that 'option' is the name of an existing file."""
@@ -293,7 +290,6 @@
"directory name",
"'%s' does not exist or is not a directory")
-
# -- Convenience methods for commands ------------------------------
@classmethod
@@ -369,12 +365,10 @@
commands.append(sub_command)
return commands
-
# -- External world manipulation -----------------------------------
def warn(self, msg):
- logger.warning("warning: %s: %s\n" %
- (self.get_command_name(), msg))
+ logger.warning("warning: %s: %s\n" % (self.get_command_name(), msg))
def execute(self, func, args, msg=None, level=1):
util.execute(func, args, msg, dry_run=self.dry_run)
@@ -413,19 +407,19 @@
and force flags.
"""
if self.dry_run:
- return # see if we want to display something
+ return # see if we want to display something
return copytree(infile, outfile, preserve_symlinks)
def move_file(self, src, dst, level=1):
"""Move a file respectin dry-run flag."""
if self.dry_run:
- return # XXX log ?
+ return # XXX log ?
return move(src, dst)
def spawn(self, cmd, search_path=1, level=1):
"""Spawn an external command respecting dry-run flag."""
from distutils2.util import spawn
- spawn(cmd, search_path, dry_run= self.dry_run)
+ spawn(cmd, search_path, dry_run=self.dry_run)
def make_archive(self, base_name, format, root_dir=None, base_dir=None,
owner=None, group=None):
@@ -450,12 +444,11 @@
if isinstance(infiles, str):
infiles = (infiles,)
elif not isinstance(infiles, (list, tuple)):
- raise TypeError, \
- "'infiles' must be a string, or a list or tuple of strings"
+ raise TypeError(
+ "'infiles' must be a string, or a list or tuple of strings")
if exec_msg is None:
- exec_msg = "generating %s from %s" % \
- (outfile, ', '.join(infiles))
+ exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
# If 'outfile' must be regenerated (either because it doesn't
# exist, is out-of-date, or the 'force' flag is true) then
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -520,7 +520,6 @@
raise DistutilsPlatformError("Can't install when "
"cross-compiling")
-
# Run all sub-commands (at least those that need to be run)
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
diff --git a/distutils2/compiler/__init__.py b/distutils2/compiler/__init__.py
--- a/distutils2/compiler/__init__.py
+++ b/distutils2/compiler/__init__.py
@@ -4,7 +4,7 @@
from distutils2._backport import sysconfig
from distutils2.util import resolve_name
-from distutils2.errors import DistutilsModuleError, DistutilsPlatformError
+from distutils2.errors import DistutilsPlatformError
def customize_compiler(compiler):
@@ -115,9 +115,9 @@
def set_compiler(location):
"""Add or change a compiler"""
- klass = resolve_name(location)
+ cls = resolve_name(location)
# XXX we want to check the class here
- _COMPILERS[klass.name] = klass
+ _COMPILERS[cls.name] = cls
def show_compilers():
@@ -127,12 +127,12 @@
from distutils2.fancy_getopt import FancyGetopt
compilers = []
- for name, klass in _COMPILERS.items():
- if isinstance(klass, str):
- klass = resolve_name(klass)
- _COMPILERS[name] = klass
+ for name, cls in _COMPILERS.items():
+ if isinstance(cls, str):
+ cls = resolve_name(cls)
+ _COMPILERS[name] = cls
- compilers.append(("compiler=" + compiler, None, klass.description))
+ compilers.append(("compiler=" + name, None, cls.description))
compilers.sort()
pretty_printer = FancyGetopt(compilers)
@@ -157,22 +157,22 @@
if compiler is None:
compiler = get_default_compiler(plat)
- klass = _COMPILERS[compiler]
+ cls = _COMPILERS[compiler]
except KeyError:
msg = "don't know how to compile C/C++ code on platform '%s'" % plat
if compiler is not None:
msg = msg + " with '%s' compiler" % compiler
raise DistutilsPlatformError(msg)
- if isinstance(klass, str):
- klass = resolve_name(klass)
- _COMPILERS[compiler] = klass
+ if isinstance(cls, str):
+ cls = resolve_name(cls)
+ _COMPILERS[compiler] = cls
# XXX The None is necessary to preserve backwards compatibility
# with classes that expect verbose to be the first positional
# argument.
- return klass(None, dry_run, force)
+ return cls(None, dry_run, force)
def gen_preprocess_options(macros, include_dirs):
diff --git a/distutils2/tests/test_command_install_dist.py b/distutils2/tests/test_command_install_dist.py
--- a/distutils2/tests/test_command_install_dist.py
+++ b/distutils2/tests/test_command_install_dist.py
@@ -19,6 +19,7 @@
from distutils2.tests import unittest, support
+
class InstallTestCase(support.TempdirManager,
support.EnvironGuard,
support.LoggingCatcher,
@@ -83,10 +84,12 @@
_CONFIG_VARS['userbase'] = self.user_base
scheme = '%s_user' % os.name
_SCHEMES.set(scheme, 'purelib', self.user_site)
+
def _expanduser(path):
if path[0] == '~':
path = os.path.normpath(self.tmpdir) + path[1:]
return path
+
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
@@ -212,6 +215,7 @@
install_module.DEBUG = False
self.assertTrue(len(self.logs) > old_logs_len)
+
def test_suite():
return unittest.makeSuite(InstallTestCase)
diff --git a/distutils2/tests/test_index_simple.py b/distutils2/tests/test_index_simple.py
--- a/distutils2/tests/test_index_simple.py
+++ b/distutils2/tests/test_index_simple.py
@@ -250,7 +250,7 @@
# Test that the simple link matcher yield the good links.
generator = crawler._simple_link_matcher(content, crawler.index_url)
- self.assertEqual(('%stest/foobar-1.tar.gz#md5=abcdef' % crawler.index_url,
+ self.assertEqual(('%stest/foobar-1.tar.gz#md5=abcdef' % crawler.index_url,
True), generator.next())
self.assertEqual(('http://dl-link1', True), generator.next())
self.assertEqual(('%stest' % crawler.index_url, False),
@@ -260,7 +260,7 @@
# Follow the external links is possible (eg. homepages)
crawler.follow_externals = True
generator = crawler._simple_link_matcher(content, crawler.index_url)
- self.assertEqual(('%stest/foobar-1.tar.gz#md5=abcdef' % crawler.index_url,
+ self.assertEqual(('%stest/foobar-1.tar.gz#md5=abcdef' % crawler.index_url,
True), generator.next())
self.assertEqual(('http://dl-link1', True), generator.next())
self.assertEqual(('http://dl-link2', False), generator.next())
@@ -304,8 +304,8 @@
# we can search the index for some projects, on their names
# the case used no matters here
crawler = self._get_simple_crawler(server)
- tests = (('Foobar', ['FooBar-bar', 'Foobar-baz', 'Baz-FooBar']),
- ('foobar*', ['FooBar-bar', 'Foobar-baz']),
+ tests = (('Foobar', ['FooBar-bar', 'Foobar-baz', 'Baz-FooBar']),
+ ('foobar*', ['FooBar-bar', 'Foobar-baz']),
('*foobar', ['Baz-FooBar',]))
for search, expected in tests:
diff --git a/distutils2/tests/test_metadata.py b/distutils2/tests/test_metadata.py
--- a/distutils2/tests/test_metadata.py
+++ b/distutils2/tests/test_metadata.py
@@ -11,6 +11,7 @@
from distutils2.errors import (MetadataConflictError,
MetadataUnrecognizedVersionError)
+
class DistributionMetadataTestCase(LoggingCatcher, WarningsCatcher,
unittest.TestCase):
@@ -95,7 +96,6 @@
{'python_version': '0.1'}))
def test_metadata_read_write(self):
-
PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
metadata = DistributionMetadata(PKG_INFO)
out = StringIO()
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list