diff --git a/distutils/_log.py b/distutils/_log.py new file mode 100644 index 00000000..129cb18a --- /dev/null +++ b/distutils/_log.py @@ -0,0 +1,4 @@ +import logging + + +log = logging.getLogger('distutils') diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index d25dec1c..8b4023c4 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -30,7 +30,7 @@ LinkError, ) from .ccompiler import CCompiler, gen_lib_options -from . import log +from ._log import log from .util import get_platform from itertools import count diff --git a/distutils/archive_util.py b/distutils/archive_util.py index f9c4ed62..7f9e1e00 100644 --- a/distutils/archive_util.py +++ b/distutils/archive_util.py @@ -16,7 +16,7 @@ from .errors import DistutilsExecError from .spawn import spawn from .dir_util import mkpath -from . import log +from ._log import log try: from pwd import getpwnam diff --git a/distutils/bcppcompiler.py b/distutils/bcppcompiler.py index 4aa1edf2..5d6b8653 100644 --- a/distutils/bcppcompiler.py +++ b/distutils/bcppcompiler.py @@ -25,7 +25,7 @@ from .ccompiler import CCompiler, gen_preprocess_options from .file_util import write_file from .dep_util import newer -from . import log +from ._log import log warnings.warn( @@ -210,7 +210,7 @@ def link( # noqa: C901 ) if runtime_library_dirs: - log.warn( + log.warning( "I don't know what to do with 'runtime_library_dirs': %s", str(runtime_library_dirs), ) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 1e79e8e4..64635311 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -19,7 +19,7 @@ from .dir_util import mkpath from .dep_util import newer_group from .util import split_quoted, execute -from . import log +from ._log import log class CCompiler: diff --git a/distutils/cmd.py b/distutils/cmd.py index 0cf7dd02..918db853 100644 --- a/distutils/cmd.py +++ b/distutils/cmd.py @@ -10,7 +10,8 @@ import logging from .errors import DistutilsOptionError -from . import util, dir_util, file_util, archive_util, dep_util, log +from . import util, dir_util, file_util, archive_util, dep_util +from ._log import log class Command: @@ -157,14 +158,14 @@ 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.translate(longopt_xlate) if option[-1] == "=": option = option[:-1] value = getattr(self, option) - self.announce(indent + "{} = {}".format(option, value), level=log.INFO) + self.announce(indent + "{} = {}".format(option, value), level=logging.INFO) def run(self): """A command's raison d'etre: carry out the action it exists to @@ -332,7 +333,7 @@ def get_sub_commands(self): # -- External world manipulation ----------------------------------- def warn(self, msg): - log.warn("warning: %s: %s\n", self.get_command_name(), msg) + log.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) diff --git a/distutils/command/bdist_dumb.py b/distutils/command/bdist_dumb.py index 4afea28c..071da77e 100644 --- a/distutils/command/bdist_dumb.py +++ b/distutils/command/bdist_dumb.py @@ -10,7 +10,7 @@ from ..dir_util import remove_tree, ensure_relative from ..errors import DistutilsPlatformError from ..sysconfig import get_python_version -from distutils import log +from distutils._log import log class bdist_dumb(Command): diff --git a/distutils/command/bdist_rpm.py b/distutils/command/bdist_rpm.py index 52431438..340527b0 100644 --- a/distutils/command/bdist_rpm.py +++ b/distutils/command/bdist_rpm.py @@ -17,7 +17,7 @@ DistutilsExecError, ) from ..sysconfig import get_python_version -from distutils import log +from distutils._log import log class bdist_rpm(Command): diff --git a/distutils/command/build_clib.py b/distutils/command/build_clib.py index 442cd54a..f90c5664 100644 --- a/distutils/command/build_clib.py +++ b/distutils/command/build_clib.py @@ -18,7 +18,7 @@ from ..core import Command from ..errors import DistutilsSetupError from ..sysconfig import customize_compiler -from distutils import log +from distutils._log import log def show_compilers(): diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index 3019c757..f4c0eccd 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -22,7 +22,7 @@ from ..dep_util import newer_group from ..extension import Extension from ..util import get_platform -from distutils import log +from distutils._log import log from . import py37compat from site import USER_BASE @@ -373,7 +373,7 @@ def check_extensions_list(self, extensions): # noqa: C901 ext_name, build_info = ext - log.warn( + log.warning( "old-style (ext_name, build_info) tuple found in " "ext_modules for extension '%s' " "-- please convert to Extension instance", @@ -413,7 +413,9 @@ def check_extensions_list(self, extensions): # noqa: C901 # Medium-easy stuff: same syntax/semantics, different names. ext.runtime_library_dirs = build_info.get('rpath') if 'def_file' in build_info: - log.warn("'def_file' element of build info dict " "no longer supported") + log.warning( + "'def_file' element of build info dict " "no longer supported" + ) # Non-trivial stuff: 'macros' split into 'define_macros' # and 'undef_macros'. @@ -597,7 +599,7 @@ def swig_sources(self, sources, extension): # the temp dir. if self.swig_cpp: - log.warn("--swig-cpp is deprecated - use --swig-opts=-c++") + log.warning("--swig-cpp is deprecated - use --swig-opts=-c++") if ( self.swig_cpp diff --git a/distutils/command/build_py.py b/distutils/command/build_py.py index d3dfbf8b..9f783244 100644 --- a/distutils/command/build_py.py +++ b/distutils/command/build_py.py @@ -10,7 +10,7 @@ from ..core import Command from ..errors import DistutilsOptionError, DistutilsFileError from ..util import convert_path -from distutils import log +from distutils._log import log class build_py(Command): @@ -212,7 +212,7 @@ def check_package(self, package, package_dir): 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) + log.warning("file %s (for module %s) not found", module_file, module) return False else: return True diff --git a/distutils/command/build_scripts.py b/distutils/command/build_scripts.py index 728535da..87174f6b 100644 --- a/distutils/command/build_scripts.py +++ b/distutils/command/build_scripts.py @@ -9,7 +9,7 @@ from ..core import Command from ..dep_util import newer from ..util import convert_path -from distutils import log +from distutils._log import log import tokenize shebang_pattern = re.compile('^#!.*python[0-9.]*([ \t].*)?$') diff --git a/distutils/command/clean.py b/distutils/command/clean.py index d1b8a206..d6eb3eba 100644 --- a/distutils/command/clean.py +++ b/distutils/command/clean.py @@ -7,7 +7,7 @@ import os from ..core import Command from ..dir_util import remove_tree -from distutils import log +from distutils._log import log class clean(Command): @@ -64,7 +64,7 @@ def run(self): if os.path.exists(directory): remove_tree(directory, dry_run=self.dry_run) else: - log.warn("'%s' does not exist -- can't clean it", directory) + log.warning("'%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 diff --git a/distutils/command/config.py b/distutils/command/config.py index e7ae83f1..8bf0e489 100644 --- a/distutils/command/config.py +++ b/distutils/command/config.py @@ -15,7 +15,7 @@ from ..core import Command from ..errors import DistutilsExecError from ..sysconfig import customize_compiler -from distutils import log +from distutils._log import log LANG_EXT = {"c": ".c", "c++": ".cxx"} diff --git a/distutils/command/install.py b/distutils/command/install.py index 9db4ad99..08d2f881 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -8,7 +8,7 @@ import sysconfig import itertools -from distutils import log +from distutils._log import log from ..core import Command from ..debug import DEBUG from ..sysconfig import get_config_vars @@ -644,7 +644,7 @@ def handle_extra_path(self): self.extra_path = self.distribution.extra_path if self.extra_path is not None: - log.warn( + log.warning( "Distribution option extra_path is deprecated. " "See issue27919 for details." ) diff --git a/distutils/command/install_egg_info.py b/distutils/command/install_egg_info.py index ff9f0284..f3e8f344 100644 --- a/distutils/command/install_egg_info.py +++ b/distutils/command/install_egg_info.py @@ -10,7 +10,8 @@ import re from ..cmd import Command -from distutils import log, dir_util +from .. import dir_util +from .._log import log class install_egg_info(Command): diff --git a/distutils/command/install_scripts.py b/distutils/command/install_scripts.py index d4d3e3f3..ec6ec5ac 100644 --- a/distutils/command/install_scripts.py +++ b/distutils/command/install_scripts.py @@ -7,7 +7,7 @@ import os from ..core import Command -from distutils import log +from distutils._log import log from stat import ST_MODE diff --git a/distutils/command/register.py b/distutils/command/register.py index 1a62ee3f..55c1045e 100644 --- a/distutils/command/register.py +++ b/distutils/command/register.py @@ -7,12 +7,13 @@ import getpass import io +import logging import urllib.parse import urllib.request from warnings import warn from ..core import PyPIRCCommand -from distutils import log +from distutils._log import log class register(PyPIRCCommand): @@ -153,7 +154,7 @@ def send_metadata(self): # noqa: C901 3. have the server generate a new password for you (and email it to you), or 4. quit Your selection [default 1]: ''', - log.INFO, + logging.INFO, ) choice = input() if not choice: @@ -174,7 +175,7 @@ def send_metadata(self): # noqa: C901 auth.add_password(self.realm, host, username, password) # send the info to the server and report the result code, result = self.post_to_server(self.build_post_data('submit'), auth) - self.announce('Server response ({}): {}'.format(code, result), log.INFO) + self.announce('Server response ({}): {}'.format(code, result), logging.INFO) # possibly save the login if code == 200: @@ -188,11 +189,11 @@ def send_metadata(self): # noqa: C901 'I can store your PyPI login so future ' 'submissions will be faster.' ), - log.INFO, + logging.INFO, ) self.announce( '(the login will be stored in %s)' % self._get_rc_file(), - log.INFO, + logging.INFO, ) choice = 'X' while choice.lower() not in 'yn': @@ -265,7 +266,8 @@ def post_to_server(self, data, auth=None): # noqa: C901 '''Post a query to the server, and return a string response.''' if 'name' in data: self.announce( - 'Registering {} to {}'.format(data['name'], self.repository), log.INFO + 'Registering {} to {}'.format(data['name'], self.repository), + logging.INFO, ) # Build up the MIME payload for the urllib2 POST data boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' @@ -315,5 +317,5 @@ def post_to_server(self, data, auth=None): # noqa: C901 result = 200, 'OK' if self.show_response: msg = '\n'.join(('-' * 75, data, '-' * 75)) - self.announce(msg, log.INFO) + self.announce(msg, logging.INFO) return result diff --git a/distutils/command/sdist.py b/distutils/command/sdist.py index 86e41e5f..5cfd4c14 100644 --- a/distutils/command/sdist.py +++ b/distutils/command/sdist.py @@ -13,7 +13,7 @@ from distutils import archive_util from ..text_file import TextFile from ..filelist import FileList -from distutils import log +from distutils._log import log from ..util import convert_path from ..errors import DistutilsOptionError, DistutilsTemplateError @@ -481,12 +481,12 @@ def make_release_tree(self, base_dir, files): msg = "copying files to %s..." % base_dir if not files: - log.warn("no files to distribute -- empty manifest?") + log.warning("no files to distribute -- empty manifest?") else: log.info(msg) for file in files: if not os.path.isfile(file): - log.warn("'%s' not a regular file -- skipping", file) + log.warning("'%s' not a regular file -- skipping", file) else: dest = os.path.join(base_dir, file) self.copy_file(file, dest, link=link) diff --git a/distutils/command/upload.py b/distutils/command/upload.py index 633273ee..16e15d8b 100644 --- a/distutils/command/upload.py +++ b/distutils/command/upload.py @@ -8,13 +8,13 @@ import os import io import hashlib +import logging from base64 import standard_b64encode from urllib.request import urlopen, Request, HTTPError from urllib.parse import urlparse from ..errors import DistutilsError, DistutilsOptionError from ..core import PyPIRCCommand from ..spawn import spawn -from distutils import log # PyPI Warehouse supports MD5, SHA256, and Blake2 (blake2-256) @@ -171,7 +171,7 @@ def upload_file(self, command, pyversion, filename): # noqa: C901 body = body.getvalue() msg = "Submitting {} to {}".format(filename, self.repository) - self.announce(msg, log.INFO) + self.announce(msg, logging.INFO) # build the Request headers = { @@ -190,16 +190,18 @@ def upload_file(self, command, pyversion, filename): # noqa: C901 status = e.code reason = e.msg except OSError as e: - self.announce(str(e), log.ERROR) + self.announce(str(e), logging.ERROR) raise if status == 200: - self.announce('Server response ({}): {}'.format(status, reason), log.INFO) + self.announce( + 'Server response ({}): {}'.format(status, reason), logging.INFO + ) if self.show_response: text = self._read_pypi_response(result) msg = '\n'.join(('-' * 75, text, '-' * 75)) - self.announce(msg, log.INFO) + self.announce(msg, logging.INFO) else: msg = 'Upload failed ({}): {}'.format(status, reason) - self.announce(msg, log.ERROR) + self.announce(msg, logging.ERROR) raise DistutilsError(msg) diff --git a/distutils/dir_util.py b/distutils/dir_util.py index 54f54103..80f77649 100644 --- a/distutils/dir_util.py +++ b/distutils/dir_util.py @@ -5,7 +5,7 @@ import os import errno from .errors import DistutilsInternalError, DistutilsFileError -from . import log +from ._log import log # cache for by mkpath() -- in addition to cheapening redundant calls, # eliminates redundant "creating /foo/bar/baz" messages in dry-run mode @@ -229,7 +229,7 @@ def remove_tree(directory, verbose=1, dry_run=0): if abspath in _path_created: del _path_created[abspath] except OSError as exc: - log.warn("error removing %s: %s", directory, exc) + log.warning("error removing %s: %s", directory, exc) def ensure_relative(path): diff --git a/distutils/dist.py b/distutils/dist.py index d6677b62..f6dd50a0 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -9,6 +9,7 @@ import re import pathlib import contextlib +import logging from email import message_from_file try: @@ -24,7 +25,7 @@ ) from .fancy_getopt import FancyGetopt, translate_longopt from .util import check_environ, strtobool, rfc822_escape -from . import log +from ._log import log from .debug import DEBUG # Regex to define acceptable Distutils command names. This is not *quite* @@ -44,7 +45,7 @@ def _ensure_list(value, fieldname): typename = type(value).__name__ msg = "Warning: '{fieldname}' should be a list, got type '{typename}'" msg = msg.format(**locals()) - log.log(log.WARN, msg) + log.warning(msg) value = list(value) return value @@ -465,7 +466,7 @@ def parse_command_line(self): parser.set_aliases({'licence': 'license'}) args = parser.getopt(args=self.script_args, object=self) option_order = parser.get_option_order() - log.set_verbosity(self.verbose) + log.setLevel(logging.WARN - 10 * self.verbose) # for display options we return immediately if self.handle_display_options(option_order): @@ -956,7 +957,7 @@ def reinitialize_command(self, command, reinit_subcommands=0): # -- Methods that operate on the Distribution ---------------------- - def announce(self, msg, level=log.INFO): + def announce(self, msg, level=logging.INFO): log.log(level, msg) def run_commands(self): diff --git a/distutils/file_util.py b/distutils/file_util.py index bead68eb..1b7cd53b 100644 --- a/distutils/file_util.py +++ b/distutils/file_util.py @@ -5,7 +5,7 @@ import os from .errors import DistutilsFileError -from . import log +from ._log import log # for generating verbose output in 'copy_file()' _copy_action = {None: 'copying', 'hard': 'hard linking', 'sym': 'symbolically linking'} diff --git a/distutils/filelist.py b/distutils/filelist.py index 619d6338..6dadf923 100644 --- a/distutils/filelist.py +++ b/distutils/filelist.py @@ -11,7 +11,7 @@ from .util import convert_path from .errors import DistutilsTemplateError, DistutilsInternalError -from . import log +from ._log import log class FileList: @@ -120,13 +120,13 @@ def process_template_line(self, line): # noqa: C901 self.debug_print("include " + ' '.join(patterns)) for pattern in patterns: if not self.include_pattern(pattern, anchor=1): - log.warn("warning: no files found matching '%s'", pattern) + log.warning("warning: no files found matching '%s'", pattern) elif action == 'exclude': self.debug_print("exclude " + ' '.join(patterns)) for pattern in patterns: if not self.exclude_pattern(pattern, anchor=1): - log.warn( + log.warning( ( "warning: no previously-included files " "found matching '%s'" @@ -138,7 +138,7 @@ def process_template_line(self, line): # noqa: C901 self.debug_print("global-include " + ' '.join(patterns)) for pattern in patterns: if not self.include_pattern(pattern, anchor=0): - log.warn( + log.warning( ( "warning: no files found matching '%s' " "anywhere in distribution" @@ -150,7 +150,7 @@ def process_template_line(self, line): # noqa: C901 self.debug_print("global-exclude " + ' '.join(patterns)) for pattern in patterns: if not self.exclude_pattern(pattern, anchor=0): - log.warn( + log.warning( ( "warning: no previously-included files matching " "'%s' found anywhere in distribution" @@ -165,13 +165,13 @@ def process_template_line(self, line): # noqa: C901 msg = ( "warning: no files found matching '%s' " "under directory '%s'" ) - log.warn(msg, pattern, dir) + log.warning(msg, pattern, dir) elif action == 'recursive-exclude': self.debug_print("recursive-exclude {} {}".format(dir, ' '.join(patterns))) for pattern in patterns: if not self.exclude_pattern(pattern, prefix=dir): - log.warn( + log.warning( ( "warning: no previously-included files matching " "'%s' found under directory '%s'" @@ -183,12 +183,12 @@ def process_template_line(self, line): # noqa: C901 elif action == 'graft': self.debug_print("graft " + dir_pattern) if not self.include_pattern(None, prefix=dir_pattern): - log.warn("warning: no directories found matching '%s'", dir_pattern) + log.warning("warning: no directories found matching '%s'", dir_pattern) elif action == 'prune': self.debug_print("prune " + dir_pattern) if not self.exclude_pattern(None, prefix=dir_pattern): - log.warn( + log.warning( ("no previously-included directories found " "matching '%s'"), dir_pattern, ) diff --git a/distutils/log.py b/distutils/log.py index d0365e68..bb789c30 100644 --- a/distutils/log.py +++ b/distutils/log.py @@ -6,6 +6,8 @@ import logging +from ._log import log as _global_log + DEBUG = logging.DEBUG INFO = logging.INFO @@ -13,7 +15,6 @@ ERROR = logging.ERROR FATAL = logging.FATAL -_global_log = logging.getLogger('distutils') log = _global_log.log debug = _global_log.debug info = _global_log.info diff --git a/distutils/msvc9compiler.py b/distutils/msvc9compiler.py index e9f02c1a..a4714a55 100644 --- a/distutils/msvc9compiler.py +++ b/distutils/msvc9compiler.py @@ -26,7 +26,7 @@ LinkError, ) from .ccompiler import CCompiler, gen_lib_options -from . import log +from ._log import log from .util import get_platform import winreg diff --git a/distutils/msvccompiler.py b/distutils/msvccompiler.py index d15499d7..59ebe99c 100644 --- a/distutils/msvccompiler.py +++ b/distutils/msvccompiler.py @@ -19,7 +19,7 @@ LinkError, ) from .ccompiler import CCompiler, gen_lib_options -from . import log +from ._log import log _can_read_reg = False try: diff --git a/distutils/spawn.py b/distutils/spawn.py index 7ae36448..afefe525 100644 --- a/distutils/spawn.py +++ b/distutils/spawn.py @@ -12,7 +12,7 @@ from .errors import DistutilsExecError from .debug import DEBUG -from . import log +from ._log import log def spawn(cmd, search_path=1, verbose=0, dry_run=0, env=None): # noqa: C901 diff --git a/distutils/tests/test_config_cmd.py b/distutils/tests/test_config_cmd.py index 6d13c24f..e72a7c5f 100644 --- a/distutils/tests/test_config_cmd.py +++ b/distutils/tests/test_config_cmd.py @@ -7,7 +7,7 @@ from distutils.command.config import dump_file, config from distutils.tests import support -from distutils import log +from distutils._log import log @pytest.fixture(autouse=True) diff --git a/distutils/tests/test_log.py b/distutils/tests/test_log.py index d346d07b..ec6a0c80 100644 --- a/distutils/tests/test_log.py +++ b/distutils/tests/test_log.py @@ -2,7 +2,7 @@ import logging -from distutils import log +from distutils._log import log class TestLog: diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index 62e34ef5..4bf2e6a6 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -23,7 +23,7 @@ from .dep_util import newer from .ccompiler import CCompiler, gen_preprocess_options, gen_lib_options from .errors import DistutilsExecError, CompileError, LibError, LinkError -from . import log +from ._log import log from ._macos_compat import compiler_fixup # XXX Things not currently handled: diff --git a/distutils/util.py b/distutils/util.py index f1864176..8668b436 100644 --- a/distutils/util.py +++ b/distutils/util.py @@ -16,7 +16,7 @@ from .errors import DistutilsPlatformError, DistutilsByteCompileError from .dep_util import newer from .spawn import spawn -from . import log +from ._log import log def get_host_platform():