"""
buildtest cli: include functions to build, get test configurations, and
interact with a global configuration for buildtest.
"""
import argparse
from buildtest import BUILDTEST_COPYRIGHT, BUILDTEST_VERSION
from buildtest.defaults import BUILD_REPORT, console
from buildtest.schemas.defaults import schema_table
[docs]def handle_kv_string(val):
"""This method is used as type field in --filter argument in ``buildtest buildspec find``.
This method returns a dict of key,value pair where input is in format
key1=val1,key2=val2,key3=val3
Args:
val (str): Input string in ``key1=value1,key2=value2`` format that is processed into a dictionary type
Returns:
dict: A dict mapping of key=value pairs
"""
kv_dict = {}
if "," in val:
args = val.split(",")
for kv in args:
if "=" not in kv:
raise argparse.ArgumentTypeError("Must specify k=v")
key, value = kv.split("=")[0], kv.split("=")[1]
kv_dict[key] = value
return kv_dict
if "=" not in val:
raise argparse.ArgumentTypeError("Must specify in key=value format")
key, value = val.split("=")[0], val.split("=")[1]
kv_dict[key] = value
return kv_dict
[docs]def positive_number(value):
"""Checks if input is positive number and returns value as an int type.
Args:
value (str or int): Specify an input number
Returns:
int: Return value as int type
Raises:
argparse.ArgumentTypeError will be raised if input is not positive number or input is not str or int type
>>> positive_number("1")
1
>>> positive_number(2)
2
"""
if not isinstance(value, (str, int)):
raise argparse.ArgumentTypeError(
f"Input must be an integer or string type, you have specified '{value}' which is of type {type(value)}"
)
try:
int_val = int(value)
except ValueError:
console.print(f"[red]Unable to convert {value} to int ")
console.print_exception()
raise ValueError
if int_val <= 0:
raise argparse.ArgumentTypeError(
f"Input: {value} converted to int: {int_val} must be a positive number"
)
return int_val
[docs]def get_parser():
epilog_str = f"""
References
GitHub: https://github.com/buildtesters/buildtest
Documentation: https://buildtest.readthedocs.io/en/latest/index.html
Schema Documentation: https://buildtesters.github.io/buildtest/
Slack: http://hpcbuildtest.slack.com/
Please report issues at https://github.com/buildtesters/buildtest/issues
{BUILDTEST_COPYRIGHT}
"""
parser = argparse.ArgumentParser(
prog="buildtest",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="buildtest is a HPC testing framework for building and running tests.",
usage="%(prog)s [options] [COMMANDS]",
epilog=epilog_str,
)
parser.add_argument(
"-V",
"--version",
action="version",
version=f"%(prog)s version {BUILDTEST_VERSION}",
)
parser.add_argument(
"-c", "--config", dest="configfile", help="Specify Path to Configuration File"
)
parser.add_argument(
"-d", "--debug", action="store_true", help="Print debug messages to screen"
)
parser.add_argument(
"--no-color", help="Disable colored output", action="store_true"
)
subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")
build_menu(subparsers)
buildspec_menu(subparsers)
config_menu(subparsers)
report_menu(subparsers)
inspect_menu(subparsers)
history_menu(subparsers)
edit_menu(subparsers)
schema_menu(subparsers)
cdash_menu(subparsers)
cd_parser = subparsers.add_parser(
"cd", help="change directory to root of test given a test name"
)
cd_parser.add_argument(
"test", help="Change directory to root of test for last run of test."
)
clean = subparsers.add_parser(
"clean",
help="Remove all generate files from buildtest including test directory, log files, report file, buildspec cache, history files.",
)
path = subparsers.add_parser("path", help="Show path attributes for a given test")
path_group = path.add_mutually_exclusive_group()
path_group.add_argument(
"-t", "--testpath", action="store_true", help="Show path to test script"
)
path_group.add_argument(
"-o", "--outfile", action="store_true", help="Show path to output file"
)
path_group.add_argument(
"-e", "--errfile", action="store_true", help="Show path to error file"
)
path_group.add_argument(
"-b", "--buildscript", action="store_true", help="Show path to build script"
)
path_group.add_argument(
"-s", "--stagedir", action="store_true", help="Show path to stage directory"
)
path.add_argument("name", help="Name of test")
subparsers.add_parser("docs", help="Open buildtest docs in browser")
subparsers.add_parser("schemadocs", help="Open buildtest schema docs in browser")
clean.add_argument(
"-y", "--yes", action="store_true", help="Confirm yes for all prompts"
)
subparsers.add_parser(
"debugreport",
help="Display system information and additional information for debugging purposes.",
)
help_subparser = subparsers.add_parser(
"help",
aliases=["h"],
help="buildtest command guide",
)
help_subparser.add_argument(
"command",
choices=[
"build",
"buildspec",
"cdash",
"config",
"edit",
"history",
"inspect",
"path",
"report",
"schema",
],
help="Show help message for command",
)
unittests_parser = subparsers.add_parser(
"unittests",
help="Run buildtest unit tests",
)
unittests_parser.add_argument(
"-c",
"--coverage",
action="store_true",
help="Enable coverage when running regression test",
)
unittests_parser.add_argument(
"-p", "--pytestopts", type=str, help="Specify option to pytest"
)
unittests_parser.add_argument(
"-s",
"--sourcefiles",
type=str,
help="Specify path to file or directory when running regression test",
action="append",
)
stylecheck_parser = subparsers.add_parser(
"stylecheck", aliases=["style"], help="Run buildtest style checks"
)
stylecheck_parser.add_argument(
"--no-black", action="store_true", help="Don't run black style check"
)
stylecheck_parser.add_argument(
"--no-isort", action="store_true", help="Don't run isort style check"
)
stylecheck_parser.add_argument(
"--no-pyflakes", action="store_true", help="Dont' run pyflakes check"
)
stylecheck_parser.add_argument(
"-a", "--apply", action="store_true", help="Apply style checks to codebase."
)
return parser