From f30ea153e874ba4d86575d8ff2c6c363a3762e15 Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Fri, 11 Aug 2023 11:39:06 -0400 Subject: [PATCH 1/5] add subparser for command 'buildtest config compilers list' and rewrite implementation when using this command. Create a method for listing compilers and move existing implementation into this method --- buildtest/cli/__init__.py | 17 ++++++++++------- buildtest/cli/compilers.py | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/buildtest/cli/__init__.py b/buildtest/cli/__init__.py index f327f7c47..4c4da281e 100644 --- a/buildtest/cli/__init__.py +++ b/buildtest/cli/__init__.py @@ -1050,19 +1050,22 @@ def config_menu(subparsers, parent_parser): "-i", "--invalid", action="store_true", help="Show invalid executors" ) - # buildtest config compilers - compilers.add_argument( - "-j", "--json", action="store_true", help="List compiler details in JSON format" - ) - compilers.add_argument( - "-y", "--yaml", action="store_true", help="List compiler details in YAML format" - ) subparsers_compiler = compilers.add_subparsers( description="Find new compilers and add them to detected compiler section", dest="compilers", metavar="", ) + compiler_list = subparsers_compiler.add_parser("list", help="List compilers") + # buildtest config compilers + compiler_list.add_argument( + "-j", "--json", action="store_true", + help="List compiler details in JSON format" + ) + compiler_list.add_argument( + "-y", "--yaml", action="store_true", + help="List compiler details in YAML format" + ) compiler_find = subparsers_compiler.add_parser( "find", help="Find compilers", parents=[parent_parser["file"]] diff --git a/buildtest/cli/compilers.py b/buildtest/cli/compilers.py index 643ccb425..ed1c3e0ac 100644 --- a/buildtest/cli/compilers.py +++ b/buildtest/cli/compilers.py @@ -27,25 +27,34 @@ def compiler_cmd(args, configuration): update=args.update, filepath=args.file, ) - return if args.compilers == "test": compiler_test(configuration, args.compiler_names) - return + if args.compilers == "list": + list_compilers(configuration=configuration, print_yaml=args.yaml, print_json=args.json) + + +def list_compilers(configuration, print_yaml=None, print_json=None): + """ This method will print available compilers found in configuration file which + can be retrieved by running ``buildtest config compilers list`` + + Args: + configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class + print_yaml (bool, optional): Print output in YAML format + print_json (bool, optional): Print output in JSON format + """ bc = BuildtestCompilers(configuration) - if args.json: + if print_json: bc.print_json() return - if args.yaml: + if print_yaml: bc.print_yaml() return bc.print_compilers() - - def compiler_test(configuration, compiler_names=None): """This method implements ``buildtest config compilers test`` which tests the compilers with the corresponding modules if set. This command iterates From eec3c041d7630ffda3b6c0042f0941c160c9a8b9 Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Fri, 11 Aug 2023 11:39:52 -0400 Subject: [PATCH 2/5] fix bash completion script for 'buildtest config compilers list' --- bash_completion.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bash_completion.sh b/bash_completion.sh index 6ede65ff5..0b3104cf2 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -247,8 +247,13 @@ _buildtest () case "${COMP_WORDS[2+offset]}" in compilers|co) - local opts="--help --json --yaml -h -j -y find test" + local opts="--help -h list find test" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) + + if [[ "${prev}" == "list" ]]; then + local opts="--json --yaml -j -y" + COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) + fi if [[ "${prev}" == "find" ]]; then local opts="--detailed --file --help --modulepath --update -d -h -m -u" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) From a62103c567c2bde8519a6c7014dff874f567064b Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Fri, 11 Aug 2023 11:41:30 -0400 Subject: [PATCH 3/5] update entry in buildtest show for command 'buildtest config compilers list' --- buildtest/cli/show.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildtest/cli/show.py b/buildtest/cli/show.py index bede669ee..0a12d49d6 100644 --- a/buildtest/cli/show.py +++ b/buildtest/cli/show.py @@ -301,7 +301,7 @@ def print_config_show(): "Validate configuration file /tmp/config.yml", ) table.add_row( - "buildtest config compilers", + "buildtest config compilers list", "List all compilers from configuration file in flat listing", ) table.add_row( From 625d2fc5f97a2f3a4ba404de95d21352ebf8e163 Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Fri, 11 Aug 2023 11:44:34 -0400 Subject: [PATCH 4/5] update documentation for compilers page to reflect the new command --- docs/configuring_buildtest/compilers.rst | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/configuring_buildtest/compilers.rst b/docs/configuring_buildtest/compilers.rst index 14761026e..99ca4f27d 100644 --- a/docs/configuring_buildtest/compilers.rst +++ b/docs/configuring_buildtest/compilers.rst @@ -32,27 +32,27 @@ which includes the name of the compiler in this example we call ``builtin_gcc`` system compiler that defines C, C++ and Fortran compilers using ``cc``, ``cxx`` and ``fc``. -One can retrieve all compilers using ``buildtest config compilers``, there are few +One can retrieve all compilers using ``buildtest config compilers list``, there are few options for this command. -.. dropdown:: ``buildtest config compilers --help`` +.. dropdown:: ``buildtest config compilers list --help`` - .. command-output:: buildtest config compilers --help + .. command-output:: buildtest config compilers list --help buildtest can represent compiler output in JSON, YAML using the ``--json`` and ``--yaml``. Shown below is an example output with these options -.. dropdown:: ``buildtest config compilers --json`` +.. dropdown:: ``buildtest config compilers list --json`` - .. command-output:: buildtest config compilers --json + .. command-output:: buildtest config compilers list --json -.. dropdown:: ``buildtest config compilers --yaml`` +.. dropdown:: ``buildtest config compilers list --yaml`` - .. command-output:: buildtest config compilers --yaml + .. command-output:: buildtest config compilers list --yaml -If you want to see a flat listing of the compilers as names you can simply run ``buildtest config compilers`` as shown below +If you want to see a flat listing of the compilers as names you can simply run ``buildtest config compilers list`` as shown below -.. command-output:: buildtest config compilers +.. command-output:: buildtest config compilers list .. _detect_compilers: @@ -117,7 +117,7 @@ the module configuration to be used to access the compiler, the ``load`` propert The ``purge`` property is a boolean that determines whether to run **module purge** prior to loading modules when using the compiler. If ``purge: true`` is set then we will do **module purge**. -.. dropdown:: ``buildtest config compilers`` +.. dropdown:: ``buildtest config compilers find`` .. code-block:: console :emphasize-lines: 9-24 @@ -154,7 +154,7 @@ by searching the modules in MODULEPATH and testing each one with a regular expre We can see in the output buildtest is applying a regular expression with each modulefile and if there is a match, we add the compiler instance into the appropriate compiler group. -.. dropdown:: ``buildtest config compilers --detailed`` +.. dropdown:: ``buildtest config compilers find --detailed`` .. code-block:: console :linenos: @@ -279,7 +279,7 @@ Now take a look at generated compilers upon running ``buildtest config compiler :linenos: :emphasize-lines: 16,24 - (buildtest)  ~/Documents/github/ buildtest config compilers find +  buildtest config compilers find MODULEPATH: /Users/siddiq90/projects/spack/share/spack/lmod/darwin-catalina-x86_64/Core:/usr/local/Cellar/lmod/8.6.14/modulefiles/Darwin:/usr/local/Cellar/lmod/8.6.14/modulefiles/Core ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Detect Compilers ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── gcc: @@ -328,7 +328,7 @@ instead of the compiler wrappers when defining a compiler instance that uses a P .. code-block:: console - (buildtest)  ~/gitrepos/buildtest/tests/settings/ [prgenv_support] buildtest config compilers find --detailed +  buildtest config compilers find --detailed MODULEPATH: /opt/cray/pe/perftools/21.12.0/modulefiles:/opt/cray/pe/craype-targets/default/modulefiles:/opt/cray/ari/modulefiles:/opt/cray/pe/modulefiles:/opt/cray/modulefiles:/opt/modulefiles:/global/common/software/nersc/cle7up03/modulefiles:/global/common/software/nersc/cle7up03/extra_modulefiles:/global/common/cori_cle7up03/ftg/modulefiles Searching modules by parsing content of command: module av -t Discovered Modules From 2471a815fff2665f74c52f1b4a855f2149486898 Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Fri, 11 Aug 2023 12:04:04 -0400 Subject: [PATCH 5/5] applying black --- buildtest/cli/__init__.py | 7 ++----- buildtest/cli/compilers.py | 8 ++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/buildtest/cli/__init__.py b/buildtest/cli/__init__.py index 4c4da281e..a1ad3f499 100644 --- a/buildtest/cli/__init__.py +++ b/buildtest/cli/__init__.py @@ -1050,7 +1050,6 @@ def config_menu(subparsers, parent_parser): "-i", "--invalid", action="store_true", help="Show invalid executors" ) - subparsers_compiler = compilers.add_subparsers( description="Find new compilers and add them to detected compiler section", dest="compilers", @@ -1059,12 +1058,10 @@ def config_menu(subparsers, parent_parser): compiler_list = subparsers_compiler.add_parser("list", help="List compilers") # buildtest config compilers compiler_list.add_argument( - "-j", "--json", action="store_true", - help="List compiler details in JSON format" + "-j", "--json", action="store_true", help="List compiler details in JSON format" ) compiler_list.add_argument( - "-y", "--yaml", action="store_true", - help="List compiler details in YAML format" + "-y", "--yaml", action="store_true", help="List compiler details in YAML format" ) compiler_find = subparsers_compiler.add_parser( diff --git a/buildtest/cli/compilers.py b/buildtest/cli/compilers.py index ed1c3e0ac..93fd32643 100644 --- a/buildtest/cli/compilers.py +++ b/buildtest/cli/compilers.py @@ -32,11 +32,13 @@ def compiler_cmd(args, configuration): compiler_test(configuration, args.compiler_names) if args.compilers == "list": - list_compilers(configuration=configuration, print_yaml=args.yaml, print_json=args.json) + list_compilers( + configuration=configuration, print_yaml=args.yaml, print_json=args.json + ) def list_compilers(configuration, print_yaml=None, print_json=None): - """ This method will print available compilers found in configuration file which + """This method will print available compilers found in configuration file which can be retrieved by running ``buildtest config compilers list`` Args: @@ -55,6 +57,8 @@ def list_compilers(configuration, print_yaml=None, print_json=None): return bc.print_compilers() + + def compiler_test(configuration, compiler_names=None): """This method implements ``buildtest config compilers test`` which tests the compilers with the corresponding modules if set. This command iterates