From c79014c755cd9bd0dbbceda25b1c2418d45c29ea Mon Sep 17 00:00:00 2001 From: Prathmesh Sambrekar Date: Wed, 26 Oct 2022 13:06:56 -0700 Subject: [PATCH 1/2] Added color output for buildtest bc maintainers --- buildtest/cli/buildspec.py | 32 +++++++++++++++----- buildtest/main.py | 1 + docs/gettingstarted/buildspecs_interface.rst | 6 ++++ tests/cli/test_buildspec.py | 13 ++++++-- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/buildtest/cli/buildspec.py b/buildtest/cli/buildspec.py index e38997f1f..f210b4865 100644 --- a/buildtest/cli/buildspec.py +++ b/buildtest/cli/buildspec.py @@ -805,8 +805,14 @@ def list_maintainers(self): """Return a list of maintainers""" return self.cache["maintainers"] - def print_maintainer(self): - """This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command.""" + def print_maintainer(self, color=None): + """This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command. + + Args: + color (bool, optional): Print table output of ``buildtest buildspec maintainers --list`` with selected color + """ + + consoleColor = checkColor(color) if self.terse: if not self.header: @@ -821,7 +827,7 @@ def print_maintainer(self): Column("Maintainers", overflow="fold"), header_style="blue", title_style="red", - row_styles=["green"], + row_styles=[consoleColor], ) for maintainer in self.cache["maintainers"].keys(): @@ -847,9 +853,15 @@ def print_maintainers_find(self, name): for file in self.cache["maintainers"][name]: console.print(file) - def print_maintainers_by_buildspecs(self): + def print_maintainers_by_buildspecs(self, color=None): + """This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown`` + + Args: + color (bool, optional): Print table output of ``buildtest buildspec maintainers --breakdown`` with selected color + """ + + consoleColor = checkColor(color) - """This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown``""" if self.terse: if not self.header: print("maintainers|buildspec") @@ -865,7 +877,7 @@ def print_maintainers_by_buildspecs(self): header_style="blue", style="cyan", title_style="red", - row_styles=["green"], + row_styles=[consoleColor], show_lines=True, ) @@ -1273,6 +1285,7 @@ def buildspec_maintainers( breakdown=None, terse=None, header=None, + color=None, name=None, ): """Entry point for ``buildtest buildspec maintainers`` command. @@ -1282,16 +1295,19 @@ def buildspec_maintainers( list_maintainers (bool, optional): List all maintainers terse (bool, optional): Print in terse mode header (bool, optional): If True disable printing of headers + color (bool, optional): Print output of table with selected color name (str, optional): List all buildspecs corresponding to maintainer name. This command is specified via ``buildtest buildspec maintainers find `` """ + consoleColor = checkColor(color) + cache = BuildspecCache(configuration=configuration, terse=terse, header=header) if list_maintainers: - cache.print_maintainer() + cache.print_maintainer(color=consoleColor) if breakdown: - cache.print_maintainers_by_buildspecs() + cache.print_maintainers_by_buildspecs(color=consoleColor) if name: cache.print_maintainers_find(name=name) diff --git a/buildtest/main.py b/buildtest/main.py index faa794cd2..b47c64eb3 100644 --- a/buildtest/main.py +++ b/buildtest/main.py @@ -222,6 +222,7 @@ def main(): breakdown=args.breakdown, terse=args.terse, header=args.no_header, + color=args.color, name=name, ) diff --git a/docs/gettingstarted/buildspecs_interface.rst b/docs/gettingstarted/buildspecs_interface.rst index 0ee8da59f..1884e6894 100644 --- a/docs/gettingstarted/buildspecs_interface.rst +++ b/docs/gettingstarted/buildspecs_interface.rst @@ -263,6 +263,9 @@ If you want to see a listing of all maintainers you can use the ``--list`` as sh .. command-output:: buildtest buildspec maintainers --list +If you want to see the table output of ``buildtest buildspec maintainers --list`` with a specific color option you can use ``buildtest --color= buildspec maintainers --list`` +command. + If you prefer a machine readable format, then you can use ``--terse`` and ``--no-header``. .. dropdown:: ``buildtest buildspec maintainers --list --terse --no-header`` @@ -276,6 +279,9 @@ display the following information .. command-output:: buildtest buildspec maintainers --breakdown +If you want to see the table output of ``buildtest buildspec maintainers --breakdown`` with a specific color option you can use ``buildtest --color= buildspec maintainers --breakdown`` +command. + The ``buildtest buildspec maintainers find`` command can be used to report buildspec given a maintainer name which works similar to `--breakdown` but doesn't report information for all maintainers. Shown below, we query all buildspecs by maintainer **@shahzebsiddiqui** diff --git a/tests/cli/test_buildspec.py b/tests/cli/test_buildspec.py index 3b4c9d656..008ce548d 100644 --- a/tests/cli/test_buildspec.py +++ b/tests/cli/test_buildspec.py @@ -18,6 +18,7 @@ from buildtest.config import SiteConfiguration from buildtest.defaults import BUILDTEST_ROOT from buildtest.exceptions import BuildTestError +from rich.color import Color configuration = SiteConfiguration() configuration.detect_system() @@ -149,10 +150,18 @@ def test_buildspec_find_terse(): @pytest.mark.cli def test_buildspec_maintainers(): buildspec_maintainers( - configuration=configuration, list_maintainers=True, terse=True, header=True + configuration=configuration, + list_maintainers=True, + terse=True, + header=True, + color=Color.default().name, ) buildspec_maintainers( - configuration=configuration, breakdown=True, terse=True, header=True + configuration=configuration, + breakdown=True, + terse=True, + header=True, + color=Color.default().name, ) buildspec_maintainers(configuration=configuration, name="@shahzebsiddiqui") From b01048dbda43652b13d38d38cfb454d455b14b76 Mon Sep 17 00:00:00 2001 From: Prathmesh Sambrekar Date: Wed, 26 Oct 2022 14:13:32 -0700 Subject: [PATCH 2/2] Updated docs --- docs/gettingstarted/buildspecs_interface.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/gettingstarted/buildspecs_interface.rst b/docs/gettingstarted/buildspecs_interface.rst index 1884e6894..0ee8da59f 100644 --- a/docs/gettingstarted/buildspecs_interface.rst +++ b/docs/gettingstarted/buildspecs_interface.rst @@ -263,9 +263,6 @@ If you want to see a listing of all maintainers you can use the ``--list`` as sh .. command-output:: buildtest buildspec maintainers --list -If you want to see the table output of ``buildtest buildspec maintainers --list`` with a specific color option you can use ``buildtest --color= buildspec maintainers --list`` -command. - If you prefer a machine readable format, then you can use ``--terse`` and ``--no-header``. .. dropdown:: ``buildtest buildspec maintainers --list --terse --no-header`` @@ -279,9 +276,6 @@ display the following information .. command-output:: buildtest buildspec maintainers --breakdown -If you want to see the table output of ``buildtest buildspec maintainers --breakdown`` with a specific color option you can use ``buildtest --color= buildspec maintainers --breakdown`` -command. - The ``buildtest buildspec maintainers find`` command can be used to report buildspec given a maintainer name which works similar to `--breakdown` but doesn't report information for all maintainers. Shown below, we query all buildspecs by maintainer **@shahzebsiddiqui**