[Python-checkins] distutils2: s/klass/cls/g for PEP 8 and PEP 20 compliance

tarek.ziade python-checkins at python.org
Sat Jul 3 16:19:06 CEST 2010


tarek.ziade pushed b1766b6037b9 to distutils2:

http://hg.python.org/distutils2/rev/b1766b6037b9
changeset:   236:b1766b6037b9
user:        ?ric Araujo <merwok at netwok.org>
date:        Sat Jun 26 12:37:06 2010 +0200
summary:     s/klass/cls/g for PEP 8 and PEP 20 compliance
files:       src/distutils2/compiler/ccompiler.py, src/distutils2/core.py, src/distutils2/dist.py, src/distutils2/tests/test_dist.py

diff --git a/src/distutils2/compiler/ccompiler.py b/src/distutils2/compiler/ccompiler.py
--- a/src/distutils2/compiler/ccompiler.py
+++ b/src/distutils2/compiler/ccompiler.py
@@ -1048,7 +1048,7 @@
         module_name = "distutils2.compiler." + module_name
         __import__ (module_name)
         module = sys.modules[module_name]
-        klass = vars(module)[class_name]
+        cls = vars(module)[class_name]
     except ImportError:
         raise DistutilsModuleError, \
               "can't compile C/C++ code: unable to load module '%s'" % \
@@ -1061,7 +1061,7 @@
     # 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/src/distutils2/core.py b/src/distutils2/core.py
--- a/src/distutils2/core.py
+++ b/src/distutils2/core.py
@@ -94,11 +94,7 @@
 
     # Determine the distribution class -- either caller-supplied or
     # our Distribution (see below).
-    klass = attrs.get('distclass')
-    if klass:
-        del attrs['distclass']
-    else:
-        klass = Distribution
+    distclass = attrs.pop('distclass', Distribution)
 
     if 'script_name' not in attrs:
         attrs['script_name'] = os.path.basename(sys.argv[0])
@@ -108,7 +104,7 @@
     # Create the Distribution instance, using the remaining arguments
     # (ie. everything except distclass) to initialize it
     try:
-        _setup_distribution = dist = klass(attrs)
+        _setup_distribution = dist = distclass(attrs)
     except DistutilsSetupError, msg:
         if 'name' in attrs:
             raise SystemExit, "error in %s setup command: %s" % \
diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py
--- a/src/distutils2/dist.py
+++ b/src/distutils2/dist.py
@@ -627,16 +627,16 @@
 
         for command in self.commands:
             if isinstance(command, type) and issubclass(command, Command):
-                klass = command
+                cls = command
             else:
-                klass = self.get_command_class(command)
-            if (hasattr(klass, 'help_options') and
-                isinstance(klass.help_options, list)):
-                parser.set_option_table(klass.user_options +
-                                        fix_help_options(klass.help_options))
+                cls = self.get_command_class(command)
+            if (hasattr(cls, 'help_options') and
+                isinstance(cls.help_options, list)):
+                parser.set_option_table(cls.user_options +
+                                        fix_help_options(cls.help_options))
             else:
-                parser.set_option_table(klass.user_options)
-            parser.print_help("Options for '%s' command:" % klass.__name__)
+                parser.set_option_table(cls.user_options)
+            parser.print_help("Options for '%s' command:" % cls.__name__)
             print('')
 
         print(gen_usage(self.script_name))
@@ -688,11 +688,11 @@
         print(header + ":")
 
         for cmd in commands:
-            klass = self.cmdclass.get(cmd)
-            if not klass:
-                klass = self.get_command_class(cmd)
+            cls = self.cmdclass.get(cmd)
+            if not cls:
+                cls = self.get_command_class(cmd)
             try:
-                description = klass.description
+                description = cls.description
             except AttributeError:
                 description = "(no description available)"
 
@@ -754,11 +754,11 @@
 
         rv = []
         for cmd in (std_commands + extra_commands):
-            klass = self.cmdclass.get(cmd)
-            if not klass:
-                klass = self.get_command_class(cmd)
+            cls = self.cmdclass.get(cmd)
+            if not cls:
+                cls = self.get_command_class(cmd)
             try:
-                description = klass.description
+                description = cls.description
             except AttributeError:
                 description = "(no description available)"
             rv.append((cmd, description))
@@ -790,13 +790,13 @@
         Raises DistutilsModuleError if the expected module could not be
         found, or if that module does not define the expected class.
         """
-        klass = self.cmdclass.get(command)
-        if klass:
-            return klass
+        cls = self.cmdclass.get(command)
+        if cls:
+            return cls
 
         for pkgname in self.get_command_packages():
             module_name = "%s.%s" % (pkgname, command)
-            klass_name = command
+            class_name = command
 
             try:
                 __import__ (module_name)
@@ -805,14 +805,14 @@
                 continue
 
             try:
-                klass = getattr(module, klass_name)
+                cls = getattr(module, class_name)
             except AttributeError:
                 raise DistutilsModuleError, \
                       "invalid command '%s' (no class '%s' in module '%s')" \
-                      % (command, klass_name, module_name)
+                      % (command, class_name, module_name)
 
-            self.cmdclass[command] = klass
-            return klass
+            self.cmdclass[command] = cls
+            return cls
 
         raise DistutilsModuleError("invalid command '%s'" % command)
 
@@ -828,8 +828,8 @@
             log.debug("Distribution.get_command_obj(): " \
                       "creating '%s' command object" % command)
 
-            klass = self.get_command_class(command)
-            cmd_obj = self.command_obj[command] = klass(self)
+            cls = self.get_command_class(command)
+            cmd_obj = self.command_obj[command] = cls(self)
             self.have_run[command] = 0
 
             # Set any options that were supplied in config files
diff --git a/src/distutils2/tests/test_dist.py b/src/distutils2/tests/test_dist.py
--- a/src/distutils2/tests/test_dist.py
+++ b/src/distutils2/tests/test_dist.py
@@ -129,13 +129,13 @@
         # Check DistributionMetadata handling of Unicode fields
         tmp_dir = self.mkdtemp()
         my_file = os.path.join(tmp_dir, 'f')
-        klass = Distribution
+        cls = Distribution
 
-        dist = klass(attrs={'author': u'Mister Café',
-                            'name': 'my.package',
-                            'maintainer': u'Café Junior',
-                            'summary': u'Café torréfié',
-                            'description': u'Héhéhé'})
+        dist = cls(attrs={'author': u'Mister Café',
+                          'name': 'my.package',
+                          'maintainer': u'Café Junior',
+                          'summary': u'Café torréfié',
+                          'description': u'Héhéhé'})
 
 
         # let's make sure the file can be written
@@ -144,11 +144,11 @@
         dist.metadata.write_file(open(my_file, 'w'))
 
         # regular ascii is of course always usable
-        dist = klass(attrs={'author': 'Mister Cafe',
-                            'name': 'my.package',
-                            'maintainer': 'Cafe Junior',
-                            'summary': 'Cafe torrefie',
-                            'description': 'Hehehe'})
+        dist = cls(attrs={'author': 'Mister Cafe',
+                          'name': 'my.package',
+                          'maintainer': 'Cafe Junior',
+                          'summary': 'Cafe torrefie',
+                          'description': 'Hehehe'})
 
         my_file2 = os.path.join(tmp_dir, 'f2')
         dist.metadata.write_file(open(my_file, 'w'))
@@ -156,7 +156,7 @@
     def test_empty_options(self):
         # an empty options dictionary should not stay in the
         # list of attributes
-        klass = Distribution
+        cls = Distribution
 
         # catching warnings
         warns = []
@@ -166,11 +166,11 @@
         old_warn = warnings.warn
         warnings.warn = _warn
         try:
-            dist = klass(attrs={'author': 'xxx',
-                                'name': 'xxx',
-                                'version': 'xxx',
-                                'url': 'xxxx',
-                                'options': {}})
+            dist = cls(attrs={'author': 'xxx',
+                              'name': 'xxx',
+                              'version': 'xxx',
+                              'url': 'xxxx',
+                              'options': {}})
         finally:
             warnings.warn = old_warn
 

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list