mlog: add __str__ method to AnsiDecorator

Automatically colorize the text when printing the AnsiDecorator, based
on the result of mlog.colorize_console().  This is how AnsiDecorator
is used most of the time anyway.
pull/8240/head
Paolo Bonzini 4 years ago committed by Xavier Claessens
parent 05ab792d58
commit 9ba7b0ebd0
  1. 3
      mesonbuild/mlog.py
  2. 17
      run_project_tests.py
  3. 6
      run_tests.py

@ -130,6 +130,9 @@ class AnsiDecorator:
text = '"{}"'.format(text)
return text
def __str__(self) -> str:
return self.get_text(colorize_console())
def bold(text: str, quoted: bool = False) -> AnsiDecorator:
return AnsiDecorator(text, "\033[1m", quoted=quoted)

@ -43,6 +43,7 @@ from mesonbuild import mlog
from mesonbuild import mtest
from mesonbuild.build import ConfigurationData
from mesonbuild.mesonlib import MachineChoice, Popen_safe, TemporaryDirectoryWinProof
from mesonbuild.mlog import bold, green, red, yellow
from mesonbuild.coredata import backendlist, version as meson_version
from run_tests import get_fake_options, run_configure, get_meson_script
@ -345,22 +346,6 @@ def log_text_file(logfile, testdir, stdo, stde):
raise StopException()
def bold(text):
return mlog.bold(text).get_text(mlog.colorize_console())
def green(text):
return mlog.green(text).get_text(mlog.colorize_console())
def red(text):
return mlog.red(text).get_text(mlog.colorize_console())
def yellow(text):
return mlog.yellow(text).get_text(mlog.colorize_console())
def _run_ci_include(args: T.List[str]) -> str:
if not args:
return 'At least one parameter required'

@ -290,7 +290,7 @@ def run_configure(commandlist, env=None):
return run_configure_inprocess(commandlist, env=env)
def print_system_info():
print(mlog.bold('System information.').get_text(mlog.colorize_console()))
print(mlog.bold('System information.'))
print('Architecture:', platform.architecture())
print('Machine:', platform.machine())
print('Platform:', platform.system())
@ -364,7 +364,7 @@ def main():
print(flush=True)
returncode = 0
else:
print(mlog.bold('Running unittests.').get_text(mlog.colorize_console()))
print(mlog.bold('Running unittests.'))
print(flush=True)
cmd = mesonlib.python_command + ['run_unittests.py', '-v']
if options.failfast:
@ -377,7 +377,7 @@ def main():
else:
cross_test_args = mesonlib.python_command + ['run_cross_test.py']
for cf in options.cross:
print(mlog.bold('Running {} cross tests.'.format(cf)).get_text(mlog.colorize_console()))
print(mlog.bold('Running {} cross tests.'.format(cf)))
print(flush=True)
cmd = cross_test_args + ['cross/' + cf]
if options.failfast:

Loading…
Cancel
Save