[Python-checkins] distutils2: finished the removal of the log module

tarek.ziade python-checkins at python.org
Fri Nov 5 02:29:57 CET 2010


tarek.ziade pushed f6ef30a22a24 to distutils2:
http://hg.python.org/distutils2/rev/f6ef30a22a24
changeset: 789:f6ef30a22a24
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Fri Nov 05 02:29:52 2010 +0100
summary: finished the removal of the log module
files: distutils2/__init__.py, distutils2/_backport/tests/test_pkgutil.py, distutils2/command/bdist_dumb.py, distutils2/command/bdist_wininst.py, distutils2/command/build_clib.py, distutils2/command/build_ext.py, distutils2/command/build_scripts.py, distutils2/command/clean.py, distutils2/command/cmd.py, distutils2/command/config.py, distutils2/command/install_dist.py, distutils2/command/install_distinfo.py, distutils2/command/install_scripts.py, distutils2/command/register.py, distutils2/command/sdist.py, distutils2/command/upload.py, distutils2/command/upload_docs.py, distutils2/log.py, distutils2/metadata.py, distutils2/tests/support.py, distutils2/tests/test_Mixin2to3.py, distutils2/tests/test_command_config.py, distutils2/tests/test_command_sdist.py, distutils2/tests/test_command_upload_docs.py, distutils2/tests/test_depgraph.py, distutils2/tests/test_metadata.py, distutils2/util.py
diff --git a/distutils2/__init__.py b/distutils2/__init__.py
--- a/distutils2/__init__.py
+++ b/distutils2/__init__.py
@@ -14,7 +14,6 @@
 __version__ = "1.0a3"
 logger = getLogger('distutils2')
 
-
 # when set to True, converts doctests by default too
 run_2to3_on_doctests = True
 # Standard package names for fixer packages
diff --git a/distutils2/_backport/tests/test_pkgutil.py b/distutils2/_backport/tests/test_pkgutil.py
--- a/distutils2/_backport/tests/test_pkgutil.py
+++ b/distutils2/_backport/tests/test_pkgutil.py
@@ -13,8 +13,8 @@
 from distutils2._backport.hashlib import md5
 
 from test.test_support import TESTFN
-from distutils2.tests import unittest, run_unittest
 
+from distutils2.tests import unittest, run_unittest, support
 from distutils2._backport import pkgutil
 
 try:
@@ -323,7 +323,8 @@
 self.assertEqual(sorted(found), sorted(distinfo_record_paths))
 
 
-class TestPkgUtilPEP376(unittest.TestCase):
+class TestPkgUtilPEP376(support.LoggingCatcher, support.WarningsCatcher,
+ unittest.TestCase):
 # Tests for the new functionality added in PEP 376.
 
 def setUp(self):
diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py
--- a/distutils2/command/bdist_dumb.py
+++ b/distutils2/command/bdist_dumb.py
@@ -14,7 +14,7 @@
 from distutils2.util import get_platform
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsPlatformError
-from distutils2 import log
+from distutils2 import logger
 
 class bdist_dumb (Command):
 
@@ -87,7 +87,7 @@
 install.skip_build = self.skip_build
 install.warn_dir = 0
 
- log.info("installing to %s" % self.bdist_dir)
+ logger.info("installing to %s" % self.bdist_dir)
 self.run_command('install_dist')
 
 # And make an archive relative to the root of the
@@ -129,7 +129,7 @@
 
 if not self.keep_temp:
 if self.dry_run:
- log.info('Removing %s' % self.bdist_dir)
+ logger.info('Removing %s' % self.bdist_dir)
 else:
 rmtree(self.bdist_dir)
 
diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py
--- a/distutils2/command/bdist_wininst.py
+++ b/distutils2/command/bdist_wininst.py
@@ -14,7 +14,7 @@
 from distutils2._backport.sysconfig import get_python_version
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsOptionError, DistutilsPlatformError
-from distutils2 import log
+from distutils2 import logger
 from distutils2.util import get_platform
 
 class bdist_wininst (Command):
@@ -160,7 +160,7 @@
 'install_' + key,
 value)
 
- log.info("installing to %s", self.bdist_dir)
+ logger.info("installing to %s", self.bdist_dir)
 install.ensure_finalized()
 
 # avoid warning of 'install_lib' about installing
@@ -187,12 +187,12 @@
 self.distribution.dist_files.append(('bdist_wininst', pyversion,
 self.get_installer_filename(fullname)))
 # remove the zip-file again
- log.debug("removing temporary file '%s'", arcname)
+ logger.debug("removing temporary file '%s'", arcname)
 os.remove(arcname)
 
 if not self.keep_temp:
 if self.dry_run:
- log.info('Removing %s' % self.bdist_dir)
+ logger.info('Removing %s' % self.bdist_dir)
 else:
 rmtree(self.bdist_dir)
 
diff --git a/distutils2/command/build_clib.py b/distutils2/command/build_clib.py
--- a/distutils2/command/build_clib.py
+++ b/distutils2/command/build_clib.py
@@ -19,7 +19,7 @@
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsSetupError
 from distutils2.compiler.ccompiler import customize_compiler
-from distutils2 import log
+from distutils2 import logger
 
 def show_compilers():
 from distutils2.compiler.ccompiler import show_compilers
@@ -185,7 +185,7 @@
 "a list of source filenames") % lib_name
 sources = list(sources)
 
- log.info("building '%s' library", lib_name)
+ logger.info("building '%s' library", lib_name)
 
 # First, compile the source code to object files in the library
 # directory. (This should probably change to putting object
diff --git a/distutils2/command/build_ext.py b/distutils2/command/build_ext.py
--- a/distutils2/command/build_ext.py
+++ b/distutils2/command/build_ext.py
@@ -15,7 +15,7 @@
 from distutils2.compiler.ccompiler import customize_compiler
 from distutils2.util import newer_group
 from distutils2.extension import Extension
-from distutils2 import log
+from distutils2 import logger
 try:
 import sysconfig
 except ImportError:
@@ -449,10 +449,10 @@
 ext_path = self.get_ext_fullpath(ext.name)
 depends = sources + ext.depends
 if not (self.force or newer_group(depends, ext_path, 'newer')):
- log.debug("skipping '%s' extension (up-to-date)", ext.name)
+ logger.debug("skipping '%s' extension (up-to-date)", ext.name)
 return
 else:
- log.info("building '%s' extension", ext.name)
+ logger.info("building '%s' extension", ext.name)
 
 # First, scan the sources for SWIG definition files (.i), run
 # SWIG on 'em to create .c files, and modify the sources list
@@ -536,7 +536,7 @@
 # the temp dir.
 
 if self.swig_cpp:
- log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
+ logger.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
 
 if self.swig_cpp or ('-c++' in self.swig_opts) or \
 ('-c++' in extension.swig_opts):
@@ -569,7 +569,7 @@
 
 for source in swig_sources:
 target = swig_targets[source]
- log.info("swigging %s to %s", source, target)
+ logger.info("swigging %s to %s", source, target)
 self.spawn(swig_cmd + ["-o", target, source])
 
 return new_sources
diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py
--- a/distutils2/command/build_scripts.py
+++ b/distutils2/command/build_scripts.py
@@ -8,7 +8,7 @@
 
 from distutils2.command.cmd import Command
 from distutils2.util import convert_path, newer
-from distutils2 import log
+from distutils2 import logger
 try:
 import sysconfig
 except ImportError:
@@ -74,7 +74,7 @@
 outfiles.append(outfile)
 
 if not self.force and not newer(script, outfile):
- log.debug("not copying %s (up-to-date)", script)
+ logger.debug("not copying %s (up-to-date)", script)
 continue
 
 # Always open the file, but ignore failures in dry-run mode --
@@ -98,7 +98,7 @@
 post_interp = match.group(1) or ''
 
 if adjust:
- log.info("copying and adjusting %s -> %s", script,
+ logger.info("copying and adjusting %s -> %s", script,
 self.build_dir)
 if not self.dry_run:
 outf = open(outfile, "w")
@@ -125,12 +125,12 @@
 if os.name == 'posix':
 for file in outfiles:
 if self.dry_run:
- log.info("changing mode of %s", file)
+ logger.info("changing mode of %s", file)
 else:
 oldmode = os.stat(file)[ST_MODE] & 07777
 newmode = (oldmode | 0555) & 07777
 if newmode != oldmode:
- log.info("changing mode of %s from %o to %o",
+ logger.info("changing mode of %s from %o to %o",
 file, oldmode, newmode)
 os.chmod(file, newmode)
 return outfiles
diff --git a/distutils2/command/clean.py b/distutils2/command/clean.py
--- a/distutils2/command/clean.py
+++ b/distutils2/command/clean.py
@@ -8,7 +8,7 @@
 import os
 from shutil import rmtree
 from distutils2.command.cmd import Command
-from distutils2 import log
+from distutils2 import logger
 
 class clean(Command):
 
@@ -48,11 +48,11 @@
 # gone)
 if os.path.exists(self.build_temp):
 if self.dry_run:
- log.info('Removing %s' % self.build_temp)
+ logger.info('Removing %s' % self.build_temp)
 else:
 rmtree(self.build_temp)
 else:
- log.debug("'%s' does not exist -- can't clean it",
+ logger.debug("'%s' does not exist -- can't clean it",
 self.build_temp)
 
 if self.all:
@@ -62,19 +62,19 @@
 self.build_scripts):
 if os.path.exists(directory):
 if self.dry_run:
- log.info('Removing %s' % directory)
+ logger.info('Removing %s' % directory)
 else:
 rmtree(directory)
 else:
- log.warn("'%s' does not exist -- can't clean it",
- directory)
+ logger.warn("'%s' does not exist -- can't clean it",
+ directory)
 
 # just for the heck of it, try to remove the base build directory:
 # we might have emptied it right now, but if not we don't care
 if not self.dry_run:
 try:
 os.rmdir(self.build_base)
- log.info("removing '%s'", self.build_base)
+ logger.info("removing '%s'", self.build_base)
 except OSError:
 pass
 
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -3,12 +3,13 @@
 Provides the Command class, the base class for the command classes
 in the distutils.command package.
 """
+import os
+import re
+import logging
 
-
-import os, re
 from distutils2.errors import DistutilsOptionError
 from distutils2 import util
-from distutils2 import log
+from distutils2 import logger
 
 # XXX see if we want to backport this
 from distutils2._backport.shutil import copytree, copyfile, move
@@ -163,7 +164,7 @@
 def dump_options(self, header=None, indent=""):
 if header is None:
 header = "command options for '%s':" % self.get_command_name()
- self.announce(indent + header, level=log.INFO)
+ self.announce(indent + header, level=logging.INFO)
 indent = indent + " "
 for (option, _, _) in self.user_options:
 option = option.replace('-', '_')
@@ -171,7 +172,7 @@
 option = option[:-1]
 value = getattr(self, option)
 self.announce(indent + "%s = %s" % (option, value),
- level=log.INFO)
+ level=logging.INFO)
 
 def run(self):
 """A command's raison d'etre: carry out the action it exists to
@@ -186,11 +187,11 @@
 raise RuntimeError, \
 "abstract method -- subclass %s must override" % self.__class__
 
- def announce(self, msg, level=1):
+ def announce(self, msg, level=logging.INFO):
 """If the current verbosity level is of greater than or equal to
 'level' print 'msg' to stdout.
 """
- log.log(level, msg)
+ logger.log(level, msg)
 
 # -- External interface --------------------------------------------
 # (called by outsiders)
@@ -367,7 +368,7 @@
 # -- External world manipulation -----------------------------------
 
 def warn(self, msg):
- log.warn("warning: %s: %s\n" %
+ logger.warning("warning: %s: %s\n" %
 (self.get_command_name(), msg))
 
 def execute(self, func, args, msg=None, level=1):
@@ -382,7 +383,7 @@
 if dry_run:
 head = ''
 for part in name.split(os.sep):
- log.info("created directory %s%s", head, part)
+ logger.info("created directory %s%s", head, part)
 head += part + os.sep
 return
 os.makedirs(name, mode)
@@ -459,7 +460,7 @@
 
 # Otherwise, print the "skip" message
 else:
- log.debug(skip_msg)
+ logger.debug(skip_msg)
 
 # XXX 'install_misc' class not currently used -- it was the base class for
 # both 'install_scripts' and 'install_data', but they outgrew it. It might
diff --git a/distutils2/command/config.py b/distutils2/command/config.py
--- a/distutils2/command/config.py
+++ b/distutils2/command/config.py
@@ -16,7 +16,7 @@
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsExecError
 from distutils2.compiler.ccompiler import customize_compiler
-from distutils2 import log
+from distutils2 import logger
 
 LANG_EXT = {'c': '.c', 'c++': '.cxx'}
 
@@ -156,7 +156,7 @@
 if not filenames:
 filenames = self.temp_files
 self.temp_files = []
- log.info("removing: %s", ' '.join(filenames))
+ logger.info("removing: %s", ' '.join(filenames))
 for filename in filenames:
 try:
 os.remove(filename)
@@ -233,7 +233,7 @@
 except CompileError:
 ok = 0
 
- log.info(ok and "success!" or "failure.")
+ logger.info(ok and "success!" or "failure.")
 self._clean()
 return ok
 
@@ -252,7 +252,7 @@
 except (CompileError, LinkError):
 ok = 0
 
- log.info(ok and "success!" or "failure.")
+ logger.info(ok and "success!" or "failure.")
 self._clean()
 return ok
 
@@ -272,7 +272,7 @@
 except (CompileError, LinkError, DistutilsExecError):
 ok = 0
 
- log.info(ok and "success!" or "failure.")
+ logger.info(ok and "success!" or "failure.")
 self._clean()
 return ok
 
@@ -346,11 +346,11 @@
 If head is not None, will be dumped before the file content.
 """
 if head is None:
- log.info('%s' % filename)
+ logger.info('%s' % filename)
 else:
- log.info(head)
+ logger.info(head)
 file = open(filename)
 try:
- log.info(file.read())
+ logger.info(file.read())
 finally:
 file.close()
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
@@ -10,7 +10,7 @@
 from distutils2._backport.sysconfig import (get_config_vars, get_paths,
 get_path, get_config_var)
 
-from distutils2 import log
+from distutils2 import logger
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsPlatformError
 from distutils2.util import write_file
@@ -406,7 +406,7 @@
 
 def dump_dirs(self, msg):
 """Dump the list of user options."""
- log.debug(msg + ":")
+ logger.debug(msg + ":")
 for opt in self.user_options:
 opt_name = opt[0]
 if opt_name[-1] == "=":
@@ -418,7 +418,7 @@
 else:
 opt_name = opt_name.replace('-', '_')
 val = getattr(self, opt_name)
- log.debug(" %s: %s" % (opt_name, val))
+ logger.debug(" %s: %s" % (opt_name, val))
 
 def select_scheme(self, name):
 """Set the install directories by applying the install schemes."""
@@ -545,7 +545,7 @@
 if (self.warn_dir and
 not (self.path_file and self.install_path_file) and
 install_lib not in sys_path):
- log.debug(("modules installed to '%s', which is not in "
+ logger.debug(("modules installed to '%s', which is not in "
 "Python's module search path (sys.path) -- "
 "you'll have to change the search path yourself"),
 self.install_lib)
diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py
--- a/distutils2/command/install_distinfo.py
+++ b/distutils2/command/install_distinfo.py
@@ -16,7 +16,7 @@
 import csv
 import re
 from distutils2.command.cmd import Command
-from distutils2 import log
+from distutils2 import logger
 from distutils2._backport.shutil import rmtree
 try:
 import hashlib
@@ -93,12 +93,12 @@
 self.execute(os.makedirs, (target,), "creating " + target)
 
 metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
- log.info('creating %s', metadata_path)
+ logger.info('creating %s', metadata_path)
 self.distribution.metadata.write(metadata_path)
 self.outputs.append(metadata_path)
 
 installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
- log.info('creating %s', installer_path)
+ logger.info('creating %s', installer_path)
 f = open(installer_path, 'w')
 try:
 f.write(self.installer)
@@ -108,14 +108,14 @@
 
 if self.requested:
 requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
- log.info('creating %s', requested_path)
+ logger.info('creating %s', requested_path)
 f = open(requested_path, 'w')
 f.close()
 self.outputs.append(requested_path)
 
 if not self.no_record:
 record_path = os.path.join(self.distinfo_dir, 'RECORD')
- log.info('creating %s', record_path)
+ logger.info('creating %s', record_path)
 f = open(record_path, 'wb')
 try:
 writer = csv.writer(f, delimiter=',',
diff --git a/distutils2/command/install_scripts.py b/distutils2/command/install_scripts.py
--- a/distutils2/command/install_scripts.py
+++ b/distutils2/command/install_scripts.py
@@ -8,7 +8,7 @@
 
 import os
 from distutils2.command.cmd import Command
-from distutils2 import log
+from distutils2 import logger
 from stat import ST_MODE
 
 class install_scripts (Command):
@@ -46,10 +46,10 @@
 # all the scripts we just installed.
 for file in self.get_outputs():
 if self.dry_run:
- log.info("changing mode of %s", file)
+ logger.info("changing mode of %s", file)
 else:
 mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777
- log.info("changing mode of %s to %o", file, mode)
+ logger.info("changing mode of %s to %o", file, mode)
 os.chmod(file, mode)
 
 def get_inputs (self):
diff --git a/distutils2/command/register.py b/distutils2/command/register.py
--- a/distutils2/command/register.py
+++ b/distutils2/command/register.py
@@ -10,10 +10,11 @@
 import getpass
 import urlparse
 import StringIO
+import logging
 from warnings import warn
 
 from distutils2.command.cmd import Command
-from distutils2 import log
+from distutils2 import logger
 from distutils2.util import (metadata_to_dict, read_pypirc, generate_pypirc,
 DEFAULT_REPOSITORY, DEFAULT_REALM,
 get_pypirc_path)
@@ -97,14 +98,14 @@
 ''' Fetch the list of classifiers from the server.
 '''
 response = urllib2.urlopen(self.repository+'?:action=list_classifiers')
- log.info(response.read())
+ logger.info(response.read())
 
 def verify_metadata(self):
 ''' Send the metadata to the package index server to be checked.
 '''
 # send the info to the server and report the result
- (code, result) = self.post_to_server(self.build_post_data('verify'))
- log.info('Server response (%s): %s' % (code, result))
+ code, result = self.post_to_server(self.build_post_data('verify'))
+ logger.info('Server response (%s): %s' % (code, result))
 
 
 def send_metadata(self):
@@ -154,7 +155,7 @@
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
-Your selection [default 1]: ''', log.INFO)
+Your selection [default 1]: ''', logging.INFO)
 
 choice = raw_input()
 if not choice:
@@ -177,7 +178,7 @@
 code, result = self.post_to_server(self.build_post_data('submit'),
 auth)
 self.announce('Server response (%s): %s' % (code, result),
- log.INFO)
+ logging.INFO)
 
 # possibly save the login
 if code == 200:
@@ -187,9 +188,10 @@
 self.distribution.password = password
 else:
 self.announce(('I can store your PyPI login so future '
- 'submissions will be faster.'), log.INFO)
+ 'submissions will be faster.'),
+ logging.INFO)
 self.announce('(the login will be stored in %s)' % \
- get_pypirc_path(), log.INFO)
+ get_pypirc_path(), logging.INFO)
 choice = 'X'
 while choice.lower() not in 'yn':
 choice = raw_input('Save your login (y/N)?')
@@ -217,18 +219,18 @@
 data['email'] = raw_input(' EMail: ')
 code, result = self.post_to_server(data)
 if code != 200:
- log.info('Server response (%s): %s' % (code, result))
+ logger.info('Server response (%s): %s' % (code, result))
 else:
- log.info('You will receive an email shortly.')
- log.info(('Follow the instructions in it to '
- 'complete registration.'))
+ logger.info('You will receive an email shortly.')
+ logger.info(('Follow the instructions in it to '
+ 'complete registration.'))
 elif choice == '3':
 data = {':action': 'password_reset'}
 data['email'] = ''
 while not data['email']:
 data['email'] = raw_input('Your email address: ')
 code, result = self.post_to_server(data)
- log.info('Server response (%s): %s' % (code, result))
+ logger.info('Server response (%s): %s' % (code, result))
 
 def build_post_data(self, action):
 # figure the data to send - the metadata plus some additional
@@ -244,7 +246,7 @@
 if 'name' in data:
 self.announce('Registering %s to %s' % (data['name'],
 self.repository),
- log.INFO)
+ logging.INFO)
 # Build up the MIME payload for the urllib2 POST data
 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
 sep_boundary = '\n--' + boundary
diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -19,7 +19,7 @@
 from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError,
 DistutilsTemplateError)
 from distutils2.manifest import Manifest
-from distutils2 import log
+from distutils2 import logger
 from distutils2.util import convert_path
 
 def show_formats():
@@ -287,12 +287,12 @@
 msg = "copying files to %s..." % base_dir
 
 if not files:
- log.warn("no files to distribute -- empty manifest?")
+ logger.warn("no files to distribute -- empty manifest?")
 else:
- log.info(msg)
+ logger.info(msg)
 for file in files:
 if not os.path.isfile(file):
- log.warn("'%s' not a regular file -- skipping" % file)
+ logger.warn("'%s' not a regular file -- skipping" % file)
 else:
 dest = os.path.join(base_dir, file)
 self.copy_file(file, dest, link=link)
@@ -328,7 +328,7 @@
 
 if not self.keep_temp:
 if self.dry_run:
- log.info('Removing %s' % base_dir)
+ logger.info('Removing %s' % base_dir)
 else:
 rmtree(base_dir)
 
diff --git a/distutils2/command/upload.py b/distutils2/command/upload.py
--- a/distutils2/command/upload.py
+++ b/distutils2/command/upload.py
@@ -4,6 +4,7 @@
 import os
 import socket
 import platform
+import logging
 from urllib2 import urlopen, Request, HTTPError
 from base64 import standard_b64encode
 import urlparse
@@ -18,9 +19,7 @@
 
 from distutils2.errors import DistutilsOptionError
 from distutils2.util import spawn
-from distutils2 import log
 from distutils2.command.cmd import Command
-from distutils2 import log
 from distutils2.util import (metadata_to_dict, read_pypirc,
 DEFAULT_REPOSITORY, DEFAULT_REALM)
 
@@ -173,7 +172,7 @@
 body = body.getvalue()
 
 self.announce("Submitting %s to %s" % (filename, self.repository),
- log.INFO)
+ logging.INFO)
 
 # build the Request
 headers = {'Content-type':
@@ -189,7 +188,7 @@
 status = result.code
 reason = result.msg
 except socket.error, e:
- self.announce(str(e), log.ERROR)
+ self.announce(str(e), logging.ERROR)
 return
 except HTTPError, e:
 status = e.code
@@ -197,11 +196,11 @@
 
 if status == 200:
 self.announce('Server response (%s): %s' % (status, reason),
- log.INFO)
+ logging.INFO)
 else:
 self.announce('Upload failed (%s): %s' % (status, reason),
- log.ERROR)
+ logging.ERROR)
 
 if self.show_response:
 msg = '\n'.join(('-' * 75, result.read(), '-' * 75))
- self.announce(msg, log.INFO)
+ self.announce(msg, logging.INFO)
diff --git a/distutils2/command/upload_docs.py b/distutils2/command/upload_docs.py
--- a/distutils2/command/upload_docs.py
+++ b/distutils2/command/upload_docs.py
@@ -4,12 +4,13 @@
 import socket
 import urlparse
 import zipfile
+import logging
 try:
 from cStringIO import StringIO
 except ImportError:
 from StringIO import StringIO
 
-from distutils2 import log
+from distutils2 import logger
 from distutils2.command.upload import upload
 from distutils2.command.cmd import Command
 from distutils2.errors import DistutilsFileError
@@ -114,8 +115,7 @@
 credentials = self.username + ':' + self.password
 auth = "Basic " + base64.encodestring(credentials).strip()
 
- self.announce("Submitting documentation to %s" % (self.repository),
- log.INFO)
+ self.announce("Submitting documentation to %s" % (self.repository))
 
 schema, netloc, url, params, query, fragments = \
 urlparse.urlparse(self.repository)
@@ -135,24 +135,22 @@
 conn.endheaders()
 conn.send(body)
 except socket.error, e:
- self.announce(str(e), log.ERROR)
+ self.announce(str(e), logging.ERROR)
 return
 
 r = conn.getresponse()
 
 if r.status == 200:
- self.announce('Server response (%s): %s' % (r.status, r.reason),
- log.INFO)
+ self.announce('Server response (%s): %s' % (r.status, r.reason))
 elif r.status == 301:
 location = r.getheader('Location')
 if location is None:
 location = 'http://packages.python.org/%s/' % name
- self.announce('Upload successful. Visit %s' % location,
- log.INFO)
+ self.announce('Upload successful. Visit %s' % location)
 else:
 self.announce('Upload failed (%s): %s' % (r.status, r.reason),
- log.ERROR)
+ logging.ERROR)
 
 if self.show_response:
 msg = '\n'.join(('-' * 75, r.read(), '-' * 75))
- self.announce(msg, log.INFO)
+ self.announce(msg)
diff --git a/distutils2/log.py b/distutils2/log.py
deleted file mode 100644
--- a/distutils2/log.py
+++ /dev/null
@@ -1,71 +0,0 @@
-"""A simple log mechanism styled after PEP 282."""
-
-# The class here is styled after PEP 282 so that it could later be
-# replaced with a standard Python logging implementation.
-
-DEBUG = 1
-INFO = 2
-WARN = 3
-ERROR = 4
-FATAL = 5
-
-import sys
-
-class Log(object):
-
- def __init__(self, threshold=WARN):
- self.threshold = threshold
-
- def _log(self, level, msg, args):
- if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
- raise ValueError('%s wrong log level' % level)
-
- if level >= self.threshold:
- if args:
- msg = msg % args
- if level in (WARN, ERROR, FATAL):
- stream = sys.stderr
- else:
- stream = sys.stdout
- stream.write('%s\n' % msg)
- stream.flush()
-
- def log(self, level, msg, *args):
- self._log(level, msg, args)
-
- def debug(self, msg, *args):
- self._log(DEBUG, msg, args)
-
- def info(self, msg, *args):
- self._log(INFO, msg, args)
-
- def warn(self, msg, *args):
- self._log(WARN, msg, args)
-
- def error(self, msg, *args):
- self._log(ERROR, msg, args)
-
- def fatal(self, msg, *args):
- self._log(FATAL, msg, args)
-
-_global_log = Log()
-log = _global_log.log
-debug = _global_log.debug
-info = _global_log.info
-warn = _global_log.warn
-error = _global_log.error
-fatal = _global_log.fatal
-
-def set_threshold(level):
- # return the old threshold for use from tests
- old = _global_log.threshold
- _global_log.threshold = level
- return old
-
-def set_verbosity(v):
- if v <= 0:
- set_threshold(WARN)
- elif v == 1:
- set_threshold(INFO)
- elif v >= 2:
- set_threshold(DEBUG)
diff --git a/distutils2/metadata.py b/distutils2/metadata.py
--- a/distutils2/metadata.py
+++ b/distutils2/metadata.py
@@ -11,7 +11,7 @@
 from email import message_from_file
 from tokenize import tokenize, NAME, OP, STRING, ENDMARKER
 
-from distutils2.log import warn
+from distutils2 import logger
 from distutils2.version import (is_valid_predicate, is_valid_version,
 is_valid_versions)
 from distutils2.errors import (MetadataConflictError,
@@ -391,16 +391,16 @@
 for v in value:
 # check that the values are valid predicates
 if not is_valid_predicate(v.split(';')[0]):
- warn('"%s" is not a valid predicate (field "%s")' %
+ logger.warn('"%s" is not a valid predicate (field "%s")' %
 (v, name))
 # FIXME this rejects UNKNOWN, is that right?
 elif name in _VERSIONS_FIELDS and value is not None:
 if not is_valid_versions(value):
- warn('"%s" is not a valid version (field "%s")' %
+ logger.warn('"%s" is not a valid version (field "%s")' %
 (value, name))
 elif name in _VERSION_FIELDS and value is not None:
 if not is_valid_version(value):
- warn('"%s" is not a valid version (field "%s")' %
+ logger.warn('"%s" is not a valid version (field "%s")' %
 (value, name))
 
 if name in _UNICODEFIELDS:
diff --git a/distutils2/tests/support.py b/distutils2/tests/support.py
--- a/distutils2/tests/support.py
+++ b/distutils2/tests/support.py
@@ -28,10 +28,10 @@
 import tempfile
 import warnings
 from copy import deepcopy
+import logging
 
-from distutils2 import log
+from distutils2 import logger
 from distutils2.dist import Distribution
-from distutils2.log import DEBUG, INFO, WARN, ERROR, FATAL
 from distutils2.tests import unittest
 
 __all__ = ['LoggingCatcher', 'WarningsCatcher', 'TempdirManager',
@@ -49,23 +49,18 @@
 
 def setUp(self):
 super(LoggingCatcher, self).setUp()
- self.threshold = log.set_threshold(FATAL)
- # when log is replaced by logging we won't need
- # such monkey-patching anymore
- self._old_log = log.Log._log
- log.Log._log = self._log
+ self.old_log = logger._log
+ logger._log = self._log
+ logger.setLevel(logging.INFO)
 self.logs = []
 
+ def _log(self, *args, **kw):
+ self.logs.append(args)
+
 def tearDown(self):
- log.set_threshold(self.threshold)
- log.Log._log = self._old_log
+ logger._log = self.old_log
 super(LoggingCatcher, self).tearDown()
 
- def _log(self, level, msg, args):
- if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
- raise ValueError('%s wrong log level' % level)
- self.logs.append((level, msg, args))
-
 def get_logs(self, *levels):
 """Return a list of caught messages with level in `levels`.
 
diff --git a/distutils2/tests/test_Mixin2to3.py b/distutils2/tests/test_Mixin2to3.py
--- a/distutils2/tests/test_Mixin2to3.py
+++ b/distutils2/tests/test_Mixin2to3.py
@@ -7,7 +7,8 @@
 from distutils2.compat import Mixin2to3
 
 
-class Mixin2to3TestCase(support.TempdirManager, unittest.TestCase):
+class Mixin2to3TestCase(support.TempdirManager, support.WarningsCatcher,
+ unittest.TestCase):
 
 @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
 def test_convert_code_only(self):
diff --git a/distutils2/tests/test_command_config.py b/distutils2/tests/test_command_config.py
--- a/distutils2/tests/test_command_config.py
+++ b/distutils2/tests/test_command_config.py
@@ -4,26 +4,11 @@
 
 from distutils2.command.config import dump_file, config
 from distutils2.tests import unittest, support
-from distutils2 import log
 
 class ConfigTestCase(support.LoggingCatcher,
 support.TempdirManager,
 unittest.TestCase):
 
- def _info(self, msg, *args):
- for line in msg.splitlines():
- self._logs.append(line)
-
- def setUp(self):
- super(ConfigTestCase, self).setUp()
- self._logs = []
- self.old_log = log.info
- log.info = self._info
-
- def tearDown(self):
- log.info = self.old_log
- super(ConfigTestCase, self).tearDown()
-
 def test_dump_file(self):
 this_file = os.path.splitext(__file__)[0] + '.py'
 f = open(this_file)
@@ -33,7 +18,11 @@
 f.close()
 
 dump_file(this_file, 'I am the header')
- self.assertEqual(len(self._logs), numlines+1)
+ logs = []
+ for log in self.logs:
+ log = log[1]
+ logs.extend([log for log in log.split('\n')])
+ self.assertEqual(len(logs), numlines+2)
 
 def test_search_cpp(self):
 if sys.platform == 'win32':
diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -3,6 +3,7 @@
 import shutil
 import zipfile
 import tarfile
+import logging
 
 # zlib is not used here, but if it's not available
 # the tests that use zipfile may fail
@@ -30,7 +31,6 @@
 from distutils2.errors import DistutilsExecError, DistutilsOptionError
 from distutils2.util import find_executable
 from distutils2.tests import support
-from distutils2.log import WARN
 try:
 from shutil import get_archive_formats
 except ImportError:
@@ -247,7 +247,7 @@
 # with the `check` subcommand
 cmd.ensure_finalized()
 cmd.run()
- warnings = self.get_logs(WARN)
+ warnings = self.get_logs(logging.WARN)
 self.assertEqual(len(warnings), 1)
 
 # trying with a complete set of metadata
@@ -256,7 +256,7 @@
 cmd.ensure_finalized()
 cmd.metadata_check = 0
 cmd.run()
- warnings = self.get_logs(WARN)
+ warnings = self.get_logs(logging.WARN)
 # removing manifest generated warnings
 warnings = [warn for warn in warnings if
 not warn.endswith('-- skipping')]
diff --git a/distutils2/tests/test_command_upload_docs.py b/distutils2/tests/test_command_upload_docs.py
--- a/distutils2/tests/test_command_upload_docs.py
+++ b/distutils2/tests/test_command_upload_docs.py
@@ -176,7 +176,7 @@
 self.pypi.default_response_status = '301 Moved Permanently'
 self.pypi.default_response_headers.append(("Location", "brand_new_location"))
 self.cmd.run()
- message, _ = calls[-1]
+ message = calls[-1][0]
 self.assertIn('brand_new_location', message)
 
 def test_reads_pypirc_data(self):
diff --git a/distutils2/tests/test_depgraph.py b/distutils2/tests/test_depgraph.py
--- a/distutils2/tests/test_depgraph.py
+++ b/distutils2/tests/test_depgraph.py
@@ -13,6 +13,7 @@
 import StringIO
 
 class DepGraphTestCase(support.LoggingCatcher,
+ support.WarningsCatcher,
 unittest.TestCase):
 
 DISTROS_DIST = ('choxie', 'grammar', 'towel-stuff')
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
@@ -7,11 +7,12 @@
 from distutils2.metadata import (DistributionMetadata, _interpret,
 PKG_INFO_PREFERRED_VERSION)
 from distutils2.tests import run_unittest, unittest
-from distutils2.tests.support import LoggingCatcher
+from distutils2.tests.support import LoggingCatcher, WarningsCatcher
 from distutils2.errors import (MetadataConflictError,
 MetadataUnrecognizedVersionError)
 
-class DistributionMetadataTestCase(LoggingCatcher, unittest.TestCase):
+class DistributionMetadataTestCase(LoggingCatcher, WarningsCatcher,
+ unittest.TestCase):
 
 def test_instantiation(self):
 PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
@@ -195,49 +196,21 @@
 values = (('Requires-Dist', 'Funky (Groovie)'),
 ('Requires-Python', '1-4'))
 
- from distutils2 import metadata as m
- old = m.warn
- m.warns = 0
-
- def _warn(*args):
- m.warns += 1
-
- m.warn = _warn
-
- try:
- for name, value in values:
- metadata.set(name, value)
- finally:
- m.warn = old
- res = m.warns
- del m.warns
+ for name, value in values:
+ metadata.set(name, value)
 
 # we should have a certain amount of warnings
- num_wanted = len(values)
- self.assertEqual(num_wanted, res)
+ self.assertEqual(len(self.logs), 2)
 
 def test_multiple_predicates(self):
 metadata = DistributionMetadata()
 
- from distutils2 import metadata as m
- old = m.warn
- m.warns = 0
-
- def _warn(*args):
- m.warns += 1
-
 # see for "3" instead of "3.0" ???
 # its seems like the MINOR VERSION can be omitted
- m.warn = _warn
- try:
- metadata['Requires-Python'] = '>=2.6, <3.0'
- metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)']
- finally:
- m.warn = old
- res = m.warns
- del m.warns
+ metadata['Requires-Python'] = '>=2.6, <3.0'
+ metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)']
 
- self.assertEqual(res, 0)
+ self.assertEqual(len(self.warnings), 0)
 
 def test_project_url(self):
 metadata = DistributionMetadata()
diff --git a/distutils2/util.py b/distutils2/util.py
--- a/distutils2/util.py
+++ b/distutils2/util.py
@@ -18,7 +18,7 @@
 
 from distutils2.errors import (DistutilsPlatformError, DistutilsFileError,
 DistutilsByteCompileError, DistutilsExecError)
-from distutils2 import log
+from distutils2 import logger
 from distutils2._backport import sysconfig as _sysconfig
 
 _PLATFORM = None
@@ -286,7 +286,7 @@
 if msg[-2:] == ',)': # correct for singleton tuple
 msg = msg[0:-2] + ')'
 
- log.info(msg)
+ logger.info(msg)
 if not dry_run:
 func(*args)
 
@@ -360,7 +360,7 @@
 if not direct:
 from tempfile import mkstemp
 script_fd, script_name = mkstemp(".py")
- log.info("writing byte-compilation script '%s'", script_name)
+ logger.info("writing byte-compilation script '%s'", script_name)
 if not dry_run:
 if script_fd is not None:
 script = os.fdopen(script_fd, "w")
@@ -441,11 +441,11 @@
 cfile_base = os.path.basename(cfile)
 if direct:
 if force or newer(file, cfile):
- log.info("byte-compiling %s to %s", file, cfile_base)
+ logger.info("byte-compiling %s to %s", file, cfile_base)
 if not dry_run:
 compile(file, cfile, dfile)
 else:
- log.debug("skipping byte-compilation of %s to %s",
+ logger.debug("skipping byte-compilation of %s to %s",
 file, cfile_base)
 
 
@@ -831,7 +831,7 @@
 if search_path:
 # either we find one or it stays the same
 executable = find_executable(executable) or executable
- log.info(' '.join([executable] + cmd[1:]))
+ logger.info(' '.join([executable] + cmd[1:]))
 if not dry_run:
 # spawn for NT requires a full path to the .exe
 try:
@@ -855,7 +855,7 @@
 if search_path:
 # either we find one or it stays the same
 executable = find_executable(executable) or executable
- log.info(' '.join([executable] + cmd[1:]))
+ logger.info(' '.join([executable] + cmd[1:]))
 if not dry_run:
 # spawnv for OS/2 EMX requires a full path to the .exe
 try:
@@ -870,13 +870,13 @@
 "command '%s' failed: %s" % (cmd[0], exc[-1]))
 if rc != 0:
 # and this reflects the command running but failing
- log.debug("command '%s' failed with exit status %d" % (cmd[0], rc))
+ logger.debug("command '%s' failed with exit status %d" % (cmd[0], rc))
 raise DistutilsExecError(
 "command '%s' failed with exit status %d" % (cmd[0], rc))
 
 
 def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0, env=None):
- log.info(' '.join(cmd))
+ logger.info(' '.join(cmd))
 if dry_run:
 return
 
--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /