Skip to content

bpo-43425: Update setup.py not to use distutils.log #26969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import importlib._bootstrap
import importlib.machinery
import importlib.util
import logging
import os
import re
import sys
Expand Down Expand Up @@ -44,7 +45,6 @@
DeprecationWarning
)

from distutils import log
from distutils.command.build_ext import build_ext
from distutils.command.build_scripts import build_scripts
from distutils.command.install import install
Expand All @@ -64,6 +64,10 @@
LIST_MODULE_NAMES = False


logging.basicConfig(format='%(message)s', level=logging.INFO)
log = logging.getLogger('setup')


def get_platform():
# Cross compiling
if "_PYTHON_HOST_PLATFORM" in os.environ:
Expand Down Expand Up @@ -241,6 +245,7 @@ def grep_headers_for(function, headers):
return True
return False


def find_file(filename, std_dirs, paths):
"""Searches for the directory where a given file is located,
and returns a possibly-empty list of additional directories, or None
Expand All @@ -259,23 +264,23 @@ def find_file(filename, std_dirs, paths):
sysroot = macosx_sdk_root()

# Check the standard locations
for dir in std_dirs:
f = os.path.join(dir, filename)
for dir_ in std_dirs:
f = os.path.join(dir_, filename)

if MACOS and is_macosx_sdk_path(dir):
f = os.path.join(sysroot, dir[1:], filename)
if MACOS and is_macosx_sdk_path(dir_):
f = os.path.join(sysroot, dir_[1:], filename)

if os.path.exists(f): return []

# Check the additional directories
for dir in paths:
f = os.path.join(dir, filename)
for dir_ in paths:
f = os.path.join(dir_, filename)

if MACOS and is_macosx_sdk_path(dir):
f = os.path.join(sysroot, dir[1:], filename)
if MACOS and is_macosx_sdk_path(dir_):
f = os.path.join(sysroot, dir_[1:], filename)

if os.path.exists(f):
return [dir]
return [dir_]

# Not found anywhere
return None
Expand Down Expand Up @@ -333,6 +338,7 @@ def find_library_file(compiler, libname, std_dirs, paths):
else:
assert False, "Internal error: Path not found in std_dirs or paths"


def validate_tzpath():
base_tzpath = sysconfig.get_config_var('TZPATH')
if not base_tzpath:
Expand All @@ -345,15 +351,16 @@ def validate_tzpath():
+ f'found:\n{tzpaths!r}\nwith invalid paths:\n'
+ f'{bad_paths!r}')


def find_module_file(module, dirlist):
"""Find a module in a set of possible folders. If it is not found
return the unadorned filename"""
list = find_file(module, [], dirlist)
if not list:
dirs = find_file(module, [], dirlist)
if not dirs:
return module
if len(list) > 1:
log.info("WARNING: multiple copies of %s found", module)
return os.path.join(list[0], module)
if len(dirs) > 1:
log.info(f"WARNING: multiple copies of {module} found")
return os.path.join(dirs[0], module)


class PyBuildExt(build_ext):
Expand Down Expand Up @@ -2667,7 +2674,7 @@ def copy_scripts(self):
newfilename = filename + fullversion
else:
newfilename = filename + minoronly
log.info('renaming %s to %s', filename, newfilename)
log.info(f'renaming {filename} to {newfilename}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your change, I no longer see this message. IMO you should mimick distutils setup() function which sets the logging thredshold to INFO:

  File "/home/vstinner/python/main/./setup.py", line 2698, in main
    setup(# PyPI Metadata (PEP 301)
  File "/home/vstinner/python/main/Lib/distutils/core.py", line 134, in setup
    ok = dist.parse_command_line()
  File "/home/vstinner/python/main/Lib/distutils/dist.py", line 477, in parse_command_line
    log.set_verbosity(self.verbose)
  File "/home/vstinner/python/main/Lib/distutils/log.py", line 78, in set_verbosity
    set_threshold(INFO)

To see the message on the main branch:

$ rm -rf build/scripts-3.11/
$ make
(...)
renaming build/scripts-3.11/pydoc3 to build/scripts-3.11/pydoc3.11
renaming build/scripts-3.11/idle3 to build/scripts-3.11/idle3.11
renaming build/scripts-3.11/2to3 to build/scripts-3.11/2to3-3.11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank's nice catch :)

os.rename(filename, newfilename)
newoutfiles.append(newfilename)
if filename in updated_files:
Expand Down