Skip to content

Commit

Permalink
Avoid use of the distutils.log module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 13, 2022
1 parent 74652ca commit 8e5842a
Show file tree
Hide file tree
Showing 32 changed files with 80 additions and 66 deletions.
4 changes: 4 additions & 0 deletions distutils/_log.py
@@ -0,0 +1,4 @@
import logging


log = logging.getLogger('distutils')
2 changes: 1 addition & 1 deletion distutils/_msvccompiler.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/archive_util.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions distutils/bcppcompiler.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
)
Expand Down
2 changes: 1 addition & 1 deletion distutils/ccompiler.py
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions distutils/cmd.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/bdist_dumb.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/bdist_rpm.py
Expand Up @@ -17,7 +17,7 @@
DistutilsExecError,
)
from ..sysconfig import get_python_version
from distutils import log
from distutils._log import log


class bdist_rpm(Command):
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/build_clib.py
Expand Up @@ -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():
Expand Down
10 changes: 6 additions & 4 deletions distutils/command/build_ext.py
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions distutils/command/build_py.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/build_scripts.py
Expand Up @@ -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].*)?$')
Expand Down
4 changes: 2 additions & 2 deletions distutils/command/clean.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/config.py
Expand Up @@ -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"}

Expand Down
4 changes: 2 additions & 2 deletions distutils/command/install.py
Expand Up @@ -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
Expand Down Expand Up @@ -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."
)
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/install_egg_info.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion distutils/command/install_scripts.py
Expand Up @@ -7,7 +7,7 @@

import os
from ..core import Command
from distutils import log
from distutils._log import log
from stat import ST_MODE


Expand Down
16 changes: 9 additions & 7 deletions distutils/command/register.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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':
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions distutils/command/sdist.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions distutils/command/upload.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
4 changes: 2 additions & 2 deletions distutils/dir_util.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8e5842a

Please sign in to comment.