From a85d24ee278360f3314f0874644ccc6944df7fdb Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 11 Aug 2024 22:13:04 +0200 Subject: [PATCH] :mute: Fix sh logs too verbose When setuptools is not present and the root logger has no handlers, Wheels would configure the root logger with DEBUG level, refs: - https://github.com/pypa/wheel/blob/0.44.0/src/wheel/util.py - https://github.com/pypa/wheel/blob/0.44.0/src/wheel/_setuptools_logging.py Both of these conditions are met in our CI, leading to very verbose and unreadable `sh` logs. Patching it prevents that. --- pythonforandroid/recipe.py | 7 ++++--- pythonforandroid/util.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index c4131c53e6..5165f19030 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -12,8 +12,6 @@ from urllib.request import urlretrieve from os import listdir, unlink, environ, curdir, walk from sys import stdout -from wheel.wheelfile import WheelFile -from wheel.cli.tags import tags as wheel_tags import time try: from urlparse import urlparse @@ -26,7 +24,7 @@ logger, info, warning, debug, shprint, info_main, error) from pythonforandroid.util import ( current_directory, ensure_dir, BuildInterruptingException, rmdir, move, - touch) + touch, patch_wheel_setuptools_logging) from pythonforandroid.util import load_source as import_recipe @@ -1205,6 +1203,9 @@ def get_wheel_platform_tag(self, arch): }[arch.arch] def install_wheel(self, arch, built_wheels): + with patch_wheel_setuptools_logging(): + from wheel.cli.tags import tags as wheel_tags + from wheel.wheelfile import WheelFile _wheel = built_wheels[0] built_wheel_dir = dirname(_wheel) # Fix wheel platform tag diff --git a/pythonforandroid/util.py b/pythonforandroid/util.py index 2738d59990..13f38e6c0f 100644 --- a/pythonforandroid/util.py +++ b/pythonforandroid/util.py @@ -1,4 +1,5 @@ import contextlib +from unittest import mock from fnmatch import fnmatch import logging from os.path import exists, join @@ -163,3 +164,16 @@ def max_build_tool_version( """ return max(build_tools_versions, key=build_tools_version_sort_key) + + +def patch_wheel_setuptools_logging(): + """ + When setuptools is not present and the root logger has no handlers, + Wheels would configure the root logger with DEBUG level, refs: + - https://github.com/pypa/wheel/blob/0.44.0/src/wheel/util.py + - https://github.com/pypa/wheel/blob/0.44.0/src/wheel/_setuptools_logging.py + + Both of these conditions are met in our CI, leading to very verbose + and unreadable `sh` logs. Patching it prevents that. + """ + return mock.patch("wheel._setuptools_logging.configure")