Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ _buildtest ()
local opts="--help --json --yaml -h -j -y find test"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
if [[ "${prev}" == "find" ]]; then
local opts="--detailed --help --modulepath --update -d -h -m -u"
local opts="--detailed --file --help --modulepath --update -d -h -m -u"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
if [[ "${prev}" == "test" ]]; then
Expand Down
68 changes: 48 additions & 20 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,24 @@ def get_parser():
)
parser.add_argument("-r", "--report", help="Specify path to test report file")

parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument(
"--pager", action="store_true", help="Enable PAGING when viewing result"
)
subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")

def get_parent_parser():

parent_parser = {}

parent_parser["pager"] = argparse.ArgumentParser(add_help=False)
parent_parser["pager"].add_argument(
"--pager", help="Enable PAGING when viewing result"
)

parent_parser["file"] = argparse.ArgumentParser(add_help=False)
parent_parser["file"].add_argument(
"--file", help="Wrtie configuration file to a new file"
)
return parent_parser

parent_parser = get_parent_parser()
build_menu(subparsers)
buildspec_menu(subparsers, parent_parser)
config_menu(subparsers, parent_parser)
Expand Down Expand Up @@ -413,12 +425,12 @@ def path_menu(subparsers):
path.add_argument("name", help="Name of test")


def history_menu(subparsers, pager_option):
def history_menu(subparsers, parent_parser):
"""This method builds the command line menu for ``buildtest history`` command

Args:
subparsers (argparse._SubParsersAction): Subparser object to add subparser
pager_option (argparse.ArgumentParser): Parent parser object to add to subparser
parent_parser (argparse.ArgumentParser): Parent parser object
"""

history_subcmd = subparsers.add_parser(
Expand All @@ -430,7 +442,7 @@ def history_menu(subparsers, pager_option):
)

list_parser = history_subparser.add_parser(
"list", help="List a summary of all builds", parents=[pager_option]
"list", help="List a summary of all builds", parents=[parent_parser["pager"]]
)
list_parser.add_argument(
"-n",
Expand All @@ -446,7 +458,9 @@ def history_menu(subparsers, pager_option):
)

query = history_subparser.add_parser(
"query", help="Query information for a particular build", parents=[pager_option]
"query",
help="Query information for a particular build",
parents=[parent_parser["pager"]],
)
query.add_argument("id", type=int, help="Select a build ID")
query.add_argument(
Expand Down Expand Up @@ -668,7 +682,7 @@ def buildspec_menu(subparsers, parent_parser):
"find",
aliases=["f"],
help="Query information from buildspecs cache",
parents=[parent_parser],
parents=[parent_parser["pager"]],
)

# buildtest buildspec maintainers
Expand Down Expand Up @@ -864,7 +878,7 @@ def buildspec_menu(subparsers, parent_parser):
"summary",
aliases=["sm"],
help="Print summary of buildspec cache",
parents=[parent_parser],
parents=[parent_parser["pager"]],
)
# buildtest buildspec validate
buildspec_validate = subparsers_buildspec.add_parser(
Expand Down Expand Up @@ -945,7 +959,10 @@ def config_menu(subparsers, parent_parser):
"validate", help="Validate buildtest settings file with schema."
)
view_parser = subparsers_config.add_parser(
"view", aliases=["v"], help="View configuration file", parents=[parent_parser]
"view",
aliases=["v"],
help="View configuration file",
parents=[parent_parser["pager"]],
)
view_parser.add_argument(
"-t",
Expand Down Expand Up @@ -991,8 +1008,7 @@ def config_menu(subparsers, parent_parser):
)

compiler_find = subparsers_compiler.add_parser(
"find",
help="Find compilers",
"find", help="Find compilers", parents=[parent_parser["file"]]
)
compiler_find.add_argument(
"-d",
Expand Down Expand Up @@ -1032,7 +1048,10 @@ def report_menu(subparsers, parent_parser):
"""

parser_report = subparsers.add_parser(
"report", aliases=["rt"], help="Query test report", parents=[parent_parser]
"report",
aliases=["rt"],
help="Query test report",
parents=[parent_parser["pager"]],
)
subparsers = parser_report.add_subparsers(
description="Fetch test results from report file and print them in table format",
Expand All @@ -1045,7 +1064,10 @@ def report_menu(subparsers, parent_parser):
"path", aliases=["p"], help="Print full path to the report file being used"
)
parser_report_summary = subparsers.add_parser(
"summary", aliases=["sm"], help="Summarize test report", parents=[parent_parser]
"summary",
aliases=["sm"],
help="Summarize test report",
parents=[parent_parser["pager"]],
)

# buildtest report
Expand Down Expand Up @@ -1143,7 +1165,7 @@ def report_menu(subparsers, parent_parser):
)


def inspect_menu(subparsers, pager_option):
def inspect_menu(subparsers, parent_parser):
"""This method builds argument for ``buildtest inspect`` command

Args:
Expand All @@ -1164,13 +1186,19 @@ def inspect_menu(subparsers, pager_option):
"buildspec",
aliases=["b"],
help="Inspect a test based on buildspec",
parents=[pager_option],
parents=[parent_parser["pager"]],
)
name = subparser.add_parser(
"name", aliases=["n"], help="Specify name of test", parents=[pager_option]
"name",
aliases=["n"],
help="Specify name of test",
parents=[parent_parser["pager"]],
)
query_list = subparser.add_parser(
"query", aliases=["q"], help="Query fields from record", parents=[pager_option]
"query",
aliases=["q"],
help="Query fields from record",
parents=[parent_parser["pager"]],
)

# buildtest inspect buildspec
Expand All @@ -1188,7 +1216,7 @@ def inspect_menu(subparsers, pager_option):
"list",
aliases=["l"],
help="List all test names, ids, and corresponding buildspecs",
parents=[pager_option],
parents=[parent_parser["pager"]],
)
inspect_list.add_argument(
"-n",
Expand Down
27 changes: 22 additions & 5 deletions buildtest/cli/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from buildtest.defaults import console
from buildtest.exceptions import BuildTestError, ConfigurationError
from buildtest.schemas.defaults import custom_validator, schema_table
from buildtest.utils.file import is_dir, resolve_path
from buildtest.utils.tools import deep_get
from lmod.module import Module
from lmod.spider import Spider
Expand All @@ -23,6 +24,7 @@ def compiler_cmd(args, configuration):
modulepath=args.modulepath,
detailed=args.detailed,
update=args.update,
filepath=args.file,
)
return

Expand Down Expand Up @@ -116,17 +118,20 @@ def compiler_test(configuration, compiler_names=None):
console.print(compiler_fail)


def compiler_find(configuration, modulepath=None, detailed=None, update=None):
def compiler_find(
configuration, modulepath=None, detailed=None, update=None, filepath=None
):
"""This method implements ``buildtest config compilers find`` which detects
new compilers based on module names defined in configuration. If system has
Lmod we use Lmodule API to detect the compilers. For environment-modules we
search for all modules in current ``$MODULEPATH``.

Args:
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
modulepath (List, optional): An instance of List, a list of directories to search for modules via MODULEPATH to detect compilers
detailed (bool, optional): An instance of bool, flag for printing a detailed report.
update (bool, optional): An instance of bool, flag for updating configuration file with new compilers
modulepath (List, optional): A list of directories to search for modules via MODULEPATH to detect compilers
detailed (bool, optional): Flag for printing a detailed report.
update (bool, optional): Flag for updating configuration file with new compilers
filepath (str, optional): An option to specify an alternative filepath where configuration file will be written
"""

bc = BuildtestCompilers(
Expand All @@ -151,14 +156,26 @@ def compiler_find(configuration, modulepath=None, detailed=None, update=None):
# print out all compilers from existing configuration file
# run buildtest config compilers find --update to update existing configuration file

# check for edge case and raise exception when --file specifies a directory path
resolved_filepath = None
if filepath:
resolved_filepath = resolve_path(filepath, exist=False)

if is_dir(resolved_filepath):
raise BuildTestError(
f"The file: {resolved_filepath} is a directory, please specify a file path"
)

# if --update is specified we update existing configuration file and write backup in same directory
if update:
fname = (
"buildtest_"
+ datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
+ ".yml"
)
backup_file = os.path.join(os.path.dirname(configuration.file), fname)
backup_file = resolved_filepath or os.path.join(
os.path.dirname(configuration.file), fname
)
copyfile(configuration.file, backup_file)
print("Writing backup configuration file to: ", backup_file)
print(f"Updating configuration file: {configuration.file}")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_nersc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import socket
import tempfile

import pytest
from buildtest.cli.build import BuildTest
Expand Down Expand Up @@ -170,3 +171,21 @@ def test_compiler_test_perlmutter():

# testing buildtest config compilers test
compiler_test(configuration=bc)


def test_compiler_find_alternative_filepath():
if not hostname.startswith("login"):
pytest.skip("This test runs on Perlmutter Login nodes ('login*')")

bc = SiteConfiguration(settings_file)
bc.detect_system()
bc.validate(moduletool="lmod")

# testing buildtest config compilers find
compilers = BuildtestCompilers(configuration=bc)
compilers.find_compilers()

# test entry point for 'buildtest config compilers find --file'
temp_path = tempfile.NamedTemporaryFile(dir=os.path.expanduser("~"))
compiler_find(configuration=bc, filepath=temp_path.name)
temp_path.close()