[Python-checkins] distutils2: Some pep8 and pychecker improvements
tarek.ziade
python-checkins at python.org
Sun Aug 8 11:50:47 CEST 2010
tarek.ziade pushed 292c0b541b47 to distutils2:
http://hg.python.org/distutils2/rev/292c0b541b47
changeset: 494:292c0b541b47
user: ?ric Araujo <merwok at netwok.org>
date: Fri Aug 06 06:33:22 2010 +0200
summary: Some pep8 and pychecker improvements
files: src/distutils2/dist.py, src/distutils2/metadata.py
diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py
--- a/src/distutils2/dist.py
+++ b/src/distutils2/dist.py
@@ -41,7 +41,6 @@
See the code for 'setup()', in core.py, for details.
"""
-
# 'global_options' describes the command-line options that may be
# supplied to the setup script prior to any actual commands.
# Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
@@ -274,10 +273,10 @@
and return the new dictionary; otherwise, return the existing
option dictionary.
"""
- dict = self.command_options.get(command)
- if dict is None:
- dict = self.command_options[command] = {}
- return dict
+ d = self.command_options.get(command)
+ if d is None:
+ d = self.command_options[command] = {}
+ return d
def get_fullname(self):
return self.metadata.get_fullname()
@@ -373,7 +372,7 @@
for opt in options:
if opt != '__name__':
- val = parser.get(section,opt)
+ val = parser.get(section, opt)
opt = opt.replace('-', '_')
# ... although practicality beats purity :(
@@ -402,12 +401,12 @@
try:
if alias:
setattr(self, alias, not strtobool(val))
- elif opt in ('verbose', 'dry_run'): # ugh!
+ elif opt in ('verbose', 'dry_run'): # ugh!
setattr(self, opt, strtobool(val))
else:
setattr(self, opt, val)
except ValueError, msg:
- raise DistutilsOptionError, msg
+ raise DistutilsOptionError(msg)
# -- Command-line parsing methods ----------------------------------
@@ -473,7 +472,7 @@
# Oops, no commands found -- an end-user error
if not self.commands:
- raise DistutilsArgError, "no commands supplied"
+ raise DistutilsArgError("no commands supplied")
# All is well: return true
return 1
@@ -504,7 +503,7 @@
# Pull the current command from the head of the command line
command = args[0]
if not command_re.match(command):
- raise SystemExit, "invalid command name '%s'" % command
+ raise SystemExit("invalid command name '%s'" % command)
self.commands.append(command)
# Dig up the command class that implements this command, so we
@@ -513,22 +512,21 @@
try:
cmd_class = self.get_command_class(command)
except DistutilsModuleError, msg:
- raise DistutilsArgError, msg
+ raise DistutilsArgError(msg)
# Require that the command class be derived from Command -- want
# to be sure that the basic "command" interface is implemented.
if not issubclass(cmd_class, Command):
- raise DistutilsClassError, \
- "command class %s must subclass Command" % cmd_class
+ raise DistutilsClassError(
+ "command class %s must subclass Command" % cmd_class)
# Also make sure that the command object provides a list of its
# known options.
if not (hasattr(cmd_class, 'user_options') and
isinstance(cmd_class.user_options, list)):
- raise DistutilsClassError, \
- ("command class %s must provide " +
- "'user_options' attribute (a list of tuples)") % \
- cmd_class
+ raise DistutilsClassError(
+ ("command class %s must provide "
+ "'user_options' attribute (a list of tuples)") % cmd_class)
# If the command class has a list of negative alias options,
# merge it in with the global negative aliases.
@@ -545,7 +543,6 @@
else:
help_options = []
-
# All commands support the global options too, just by adding
# in 'global_options'.
parser.set_option_table(self.global_options +
@@ -809,9 +806,9 @@
try:
cls = getattr(module, class_name)
except AttributeError:
- raise DistutilsModuleError, \
- "invalid command '%s' (no class '%s' in module '%s')" \
- % (command, class_name, module_name)
+ raise DistutilsModuleError(
+ "invalid command '%s' (no class '%s' in module '%s')" %
+ (command, class_name, module_name))
self.cmdclass[command] = cls
return cls
@@ -880,11 +877,11 @@
elif hasattr(command_obj, option):
setattr(command_obj, option, value)
else:
- raise DistutilsOptionError, \
- ("error in %s: command '%s' has no such option '%s'"
- % (source, command_name, option))
+ raise DistutilsOptionError(
+ "error in %s: command '%s' has no such option '%s'" %
+ (source, command_name, option))
except ValueError, msg:
- raise DistutilsOptionError, msg
+ raise DistutilsOptionError(msg)
def get_reinitialized_command(self, command, reinit_subcommands=0):
"""Reinitializes a command to the state it was in when first
diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py
--- a/src/distutils2/metadata.py
+++ b/src/distutils2/metadata.py
@@ -3,10 +3,10 @@
Supports all metadata formats (1.0, 1.1, 1.2).
"""
-import re
import os
import sys
import platform
+import re
from StringIO import StringIO
from email import message_from_file
from tokenize import tokenize, NAME, OP, STRING, ENDMARKER
@@ -92,6 +92,7 @@
return _345_FIELDS
raise MetadataUnrecognizedVersionError(version)
+
def _best_version(fields):
"""Detect the best version depending on the fields used."""
def _has_marker(keys, markers):
@@ -448,7 +449,7 @@
missing.append(attr)
if _HAS_DOCUTILS:
- warnings = self._check_rst_data(self['Description'])
+ warnings.extend(self._check_rst_data(self['Description']))
# checking metadata 1.2 (XXX needs to check 1.1, 1.0)
if self['Metadata-Version'] != '1.2':
@@ -497,6 +498,7 @@
'in': lambda x, y: x in y,
'not in': lambda x, y: x not in y}
+
def _operate(operation, x, y):
return _OPERATORS[operation](x, y)
@@ -508,6 +510,7 @@
'platform.version': platform.version(),
'platform.machine': platform.machine()}
+
class _Operation(object):
def __init__(self, execution_context=None):
@@ -568,6 +571,7 @@
right = self._convert(self.right)
return _operate(self.op, left, right)
+
class _OR(object):
def __init__(self, left, right=None):
self.left = left
@@ -597,6 +601,7 @@
def __call__(self):
return self.left() and self.right()
+
class _CHAIN(object):
def __init__(self, execution_context=None):
@@ -658,6 +663,7 @@
return False
return True
+
def _interpret(marker, execution_context=None):
"""Interpret a marker and return a result depending on environment."""
marker = marker.strip()
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list