Esempio n. 1
0
def func_compiler_find(args=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``.
    """

    settings_file = resolve_settings_file()
    configuration = load_settings(settings_file)

    bc = BuildtestCompilers(debug=args.debug)
    bc.find_compilers()
    configuration["compilers"]["compiler"] = bc.compilers

    custom_validator(configuration,
                     schema_table["settings.schema.json"]["recipe"])

    print(f"Configuration File: {settings_file}")
    print("{:_<80}".format(""))
    print(
        yaml.safe_dump(configuration,
                       default_flow_style=False,
                       sort_keys=False))
    print("{:_<80}".format(""))
    print(f"Updating settings file:  {settings_file}")

    with open(settings_file, "w") as fd:
        yaml.safe_dump(configuration,
                       fd,
                       default_flow_style=False,
                       sort_keys=False)
Esempio n. 2
0
def test_build_by_stages():

    buildtest_configuration = load_settings()

    class args:
        buildspec = None
        debug = False
        stage = "parse"
        testdir = None
        exclude = None
        tags = ["python"]
        executor = None
        filter_tags = None
        rebuild = None

    # testing buildtest build --tags python --stage=parse
    func_build_subcmd(args, buildtest_configuration)

    class args:
        buildspec = None
        debug = False
        stage = "build"
        testdir = None
        exclude = None
        tags = ["python"]
        executor = None
        filter_tags = None
        rebuild = None

    # testing buildtest build --tags tutorials --stage=build
    func_build_subcmd(args, buildtest_configuration)
Esempio n. 3
0
def test_build_buildspecs():
    buildspec_paths = os.path.join(test_root, "buildsystem", "valid_buildspecs")
    buildtest_configuration = load_settings()

    class args:
        buildspec = [buildspec_paths]
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = None
        executor = None
        filter_tags = None
        rebuild = None

    #  testing buildtest build --buildspec tests/examples/buildspecs
    func_build_subcmd(args, buildtest_configuration)

    class args:
        buildspec = [buildspec_paths]
        debug = False
        stage = None
        testdir = None
        exclude = [buildspec_paths]
        tags = None
        executor = None
        filter_tags = None
        rebuild = None

    #  testing buildtest build --buildspec tests/examples/buildspecs --exclude tests/examples/buildspecs
    # this results in no buildspecs built
    with pytest.raises(SystemExit):
        func_build_subcmd(args, buildtest_configuration)
Esempio n. 4
0
    def load_paths(self):
        """Add all paths to search for buildspecs. We must read configuration file
        and check property ``buildspec_roots`` for list of directories to search.
        We check all directories exist, if any fail we don't add them to path.
        In addition, we add the default buildspec path where we find tutorials
        and general tests.
        """

        config_opts = load_settings()
        buildspec_paths = config_opts.get("buildspec_roots") or []

        if buildspec_paths:
            self.roots += buildspec_paths

        # only load default buildspecs if 'load_default_buildspecs' set to True
        if config_opts.get("load_default_buildspecs"):
            self.paths += BUILDSPEC_DEFAULT_PATH

        # for every root buildspec defined in configuration or via --root option,
        # we resolve path and if path exist add to self.paths. The path must be a
        # directory. If its file, we ignore it
        if self.roots:

            for root in self.roots:
                path = resolve_path(root, exist=False)
                if not os.path.exists(path):
                    print(f"Path: {path} does not exist!")

                if is_file(path):
                    print(f"Path: {path} must be a directory not a file")

                if is_dir(path):
                    self.paths.append(path)
Esempio n. 5
0
    def __init__(self, name, recipe, buildspec, compiler=None, testdir=None):
        super().__init__(name, recipe, buildspec, testdir)
        self.compiler = compiler

        self.compiler_section = self.recipe["compilers"]
        self.settings = load_settings()

        self.sourcefile = self.recipe["source"]
Esempio n. 6
0
def func_config_compiler(args=None):
    """This method implements ``buildtest config compilers`` which shows compiler
    section from buildtest configuration.
    """

    settings_file = resolve_settings_file()
    configuration = load_settings(settings_file)

    bc = BuildtestCompilers(configuration)

    if args.json:
        bc.print_json()
    if args.yaml:
        bc.print_yaml()
    if args.list:
        bc.print_compilers()
Esempio n. 7
0
def test_build_multi_executors():
    buildtest_configuration = load_settings()

    class args:
        executor = ["local.sh", "local.python"]
        buildspec = None
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = None
        filter_tags = None
        rebuild = None

    # testing buildtest build --executor local.sh --executor local.python
    func_build_subcmd(args, buildtest_configuration)
Esempio n. 8
0
def test_buildspec_tag_executor():
    buildtest_configuration = load_settings()

    class args:
        executor = ["local.sh"]
        tags = ["fail"]
        buildspec = None
        debug = False
        stage = None
        testdir = None
        exclude = None
        filter_tags = None
        rebuild = None

    # testing buildtest build --tags fail --executor local.sh
    func_build_subcmd(args, buildtest_configuration)
Esempio n. 9
0
def test_build_rebuild():

    buildtest_configuration = load_settings()
    buildspec_file = os.path.join(BUILDTEST_ROOT, "tutorials", "python-shell.yml")

    class args:
        buildspec = [buildspec_file]
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = None
        executor = None
        filter_tags = None
        rebuild = 5

    # rebuild 5 times (buildtest build -b tutorials/python-shell.yml --rebuild=5
    func_build_subcmd(args, buildtest_configuration)
Esempio n. 10
0
def func_config_summary(args=None):
    """This method implements ``buildtest config summary`` option. In this method
    we will display a summary of System Details, Buildtest settings, Schemas,
    Repository details, Buildspecs files and test names.
    """

    print("buildtest version: ", BUILDTEST_VERSION)
    print("buildtest Path:", shutil.which("buildtest"))

    print("\n")
    print("Machine Details")
    print("{:_<30}".format(""))
    print("Operating System: ", system.system["os"])
    print("Hostname: ", system.system["host"])
    print("Machine: ", system.system["machine"])
    print("Processor: ", system.system["processor"])
    print("Python Path", system.system["python"])
    print("Python Version:", system.system["pyver"])
    print("User:"******"\n")

    print("Buildtest Settings")
    print("{:_<80}".format(""))
    print(f"Buildtest Settings: {BUILDTEST_SETTINGS_FILE}")

    settings_file = resolve_settings_file()
    settings = load_settings(settings_file)

    executors = []
    for executor_type in settings.get("executors").keys():
        for name in settings["executors"][executor_type].keys():
            executors.append(f"{executor_type}.{name}")

    print("Executors: ", executors)

    print("Buildspec Cache File:", BUILDSPEC_CACHE_FILE)
    print("\n")

    print("Buildtest Schemas")
    print("{:_<80}".format(""))
    print("Available Schemas:", supported_schemas)
Esempio n. 11
0
    def __init__(self, debug=False, settings_file=None):
        """
        :param compilers: compiler section from buildtest configuration.
        :type compilers: dict
        """

        self.configuration = load_settings(settings_file)
        self.debug = debug

        if not deep_get(self.configuration, "compilers", "compiler"):
            raise BuildTestError("compiler section not defined")

        self.compilers = self.configuration["compilers"]["compiler"]

        self.names = []
        self.compiler_name_to_group = {}
        for name in self.compilers:
            if isinstance(self.compilers[name], dict):
                self.names += self.compilers[name].keys()
                for compiler in self.compilers[name].keys():
                    self.compiler_name_to_group[compiler] = name
Esempio n. 12
0
def test_build_by_tags():

    # ensure we rebuild cache file before running by tags
    # rerunning buildtest buildspec find without --rebuild option this will read from cache file
    class args:
        find = True
        rebuild = True
        root = None
        buildspec_files = False
        executors = False
        tags = False
        paths = False
        group_by_tags = False
        group_by_executor = False
        maintainers = False
        maintainers_by_buildspecs = False
        filter = None
        format = None
        helpfilter = False
        helpformat = False

    func_buildspec_find(args)

    buildtest_configuration = load_settings()

    class args:
        buildspec = None
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = ["pass"]
        executor = None
        filter_tags = None
        rebuild = None

    #  testing buildtest build --tags pass
    func_build_subcmd(args, buildtest_configuration)

    class args:
        buildspec = [os.path.join(test_root, "tutorials")]
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = ["fail", "python"]
        executor = None
        filter_tags = None
        rebuild = None

    #  testing buildtest build --tags fail --tags python
    func_build_subcmd(args, buildtest_configuration)

    class args:
        buildspec = None
        debug = False
        stage = None
        testdir = None
        exclude = None
        tags = ["pass"]
        executor = None
        filter_tags = ["pass"]
        rebuild = None

    #  testing buildtest build --tags pass --tags pass
    func_build_subcmd(args, buildtest_configuration)
Esempio n. 13
0
from buildtest.executors.setup import BuildExecutor
from buildtest.menu.build import (
    build_phase,
    discover_buildspecs,
    parse_buildspecs,
    resolve_testdirectory,
    run_phase,
)

input_buildspecs = [
    os.path.join(BUILDTEST_ROOT, "tutorials", "pass_returncode.yml")
]
included_bp, excluded_bp = discover_buildspecs(buildspec=input_buildspecs,
                                               debug=True)

configuration = load_settings()
testdir = resolve_testdirectory(configuration)
executor = BuildExecutor(configuration)

print("List of executors: ", executor.executors)
bp_filters = {"tags": None}
builders = parse_buildspecs(included_bp,
                            test_directory=testdir,
                            executor=executor,
                            filters=bp_filters,
                            rebuild=1,
                            printTable=True)

build_phase(builders, printTable=True)
run_phase(builders, executor, configuration, printTable=True)